Chrome extension: "Uncaught Error: "getBackgroundPage" can only be used in extension processes...." - google-chrome-extension

I published a chrome extension to testers only. The app seems to work very well. I don't see any errors when inspecting the console for the popup or the background page. However, I get the following error when inspecting the console for any web page: "Uncaught Error: "getBackgroundPage" can only be used in extension processes. See the content scripts documentation for more extensions/schema_generated_bindings.js:418"
This app contains several JavaScript files, but each one includes the code within a self executing function. The "getBackgroundPage" calls are in the JavaScript files.
Could you please help? Isn't the app I built an isolated module independent from any web page? How can I prevent this error from happening?

I had the same error when I was trying to communicate with the background page from my content script. The correct way of doing it is via Message Passing. It is very well documented here : https://developer.chrome.com/extensions/messaging.html

Related

Kiip web sdk integration showing bad request error in console

I just integrated KIIP SDK for web in my node js application and it works correctly . But the problem is it showing error on browser console on each page refresh, But this error does not affect working of this sdk, it works perfectly.
the errror message showing is,
'POST https://api.kiip.me/2.0/web/moment/?r=1426508956613 400 (Bad Request)'.
My kiip code integration is as follows,
1) Included the script file on head tag
2)Declared the app key as global variable,
kiip_app_key='app-key from kiip site';
3) And intialized the kiip instance and invoked the method.
var kiipInstance = new Kiip(kiip_app_key);
kiipInstance.setTestMode();
kiipInstance.postMoment('received offer');
Andrew from Kiip here.A few things could be causing this:
The page is running from a local file or host. Solution: run the test page on a server.
The app is not submitted for live rewards. Solution: Submit for live rewards in the Kiip dashboard.
You're passing an incorrect app key. Solution: copy the app_key for the corresponding app from the Kiip dashboard and paste it as you're global variable.
Hope this helps,
Andrew

Chrome Extension: How to solve "Not allowed to load local resource" error upon content script injection

I tried to inject jQuery to content page to make easy access to DOM elements.
The code was something like below
chrome.tabs.executeScript(tabId, { file: "jquery.min.js"} ,function(){
chrome.tabs.executeScript(tabId, { file: myOwnScript.js});}
);
It was all fine on Windows, but on Ubuntu, in content page window, I always get console error message saying
"Not allowed to load local resource: file:///****/jquery.min.map"
I noted it was talking about *.map but not *.js
There are some more mysteies:
1. There is no error message on myOwnScript.js
2. My extension works well even though this message keeps showing at each page load.
I made plenty searches on Google but didn't find similar case.
My questions is,
1. What is the reason of such error?
2. Should I take it as a serious error?
My enviroment is as below
OS : Ubuntu 14.04, with LXDE desktop
Chrome : 34.0.1847.132
(Didn't try other configurations because I am not that good at customizing Linux :)
Previous versions of Jquery have a comment pointing to the map file (so that a bug in jquery.min.js can be translated to a bug in the readable jquery.js). You can safely delete this comment, or upgrade to a more recent version of Jquery, which has removed this comment (for exactly this reason). See also this answer.

get a browser rendered html+javascript

I need a comandline tool (or Javascript/PHP, but i think commandline is the one way) for render and get the rendered content of URL, but the important its I need to renderer the Javascript not only the CSS/Html/images.
For example command like: "renderengine http://www.google.es outputfile.html" and the content of the web (parsed html and javascript executed) isa saved in outputfile.html.
I need this because i need to take the result of a full javascript website like grooveshark, the site load all using javascript/ajax and the crawlers dont find nothing, only basic HTML empty template (because is loaded after using ajax/javscript)
Exists any browser engine for linux with support to Javascript (for example V8) that output the result for save in files?
Selenium : very complete solution with bindings in many languages
puppeteer : headless Chrome API, usable in NodeJS or as a command-line tool
HTtrack : command-line tool
Apache Notch & webmagic : open source Java web crawlers
pholcus : "distributed & high concurrency" web crawler written in Go
Xvfb a display server implementing the X11 display server protocol, without showing any screen output. I have used it successfully with Travis CI and Protractor as an example. Alternative: XDummy
PhantomJS (first suggested by nvuono) : can export the rendered page as non-HTML (pdf, png...). PhantomJS development is suspended until further notice (more details).
Closely related: SlimerJS, CasperJS
And there are many Python web scraping libraries:
Scrapy
pyspider
ghost.py
splinter
Try phantomjs from www.phantomjs.org and you can easily modify the included rasterize.js to export the rendered HTML. It's based on webkit and does full evaluation of your target site's javascript, allowing you to adjust timeouts or execute your own code first if you wish. I personally use it to save hardcopy HTML file version of fully-rendered knockout.js templates.
It executes javascript so I just did something like this and saved the console output to a file:
var markup = page.evaluate(function(){return document.documentElement.innerHTML;});
console.log(markup);
phantom.exit();

How do you use Javascript when creating a Chrome extension options page?

I tried following Google's example: https://developer.chrome.com/extensions/options.html
I immediately encountered the problem of the button and body trying to execute functions, so I attached listeners instead. Then, it's telling me that the options page isn't allowed to execute JS.
Either I didn't properly understand how to do that, or Chrome's documentation is entirely wrong.
How do you use JS in there? Or: can you point me in the direction of a proper tutorial.
Check out this answer: Chrome tutorials - options page
"manifest_version": 2 forbids embedded scripts. Move all of the JavaScript to options.js and load it that way."
You can't use inline JS with manifest v2.0 that is required for new extensions. That was possible with manifest v1 but not now. You have to reference script file to page. This issue if present on all extension pages.
<script type="text/javascript">JS CODE</script>
Is not allowed anymore. Use this instead.
<script type="text/javascript" src="FILENAME.js"></script>
Take a look at google code docs - manifest

icon error in createNotification in Chrome extension

In my Chrome Extension, I am using webkitNotifications.createNotification to alert users. It's a great tool!! In the sample code given, the first parameter is optional and specifies an an icon and the Google instructions claim that it can be a local reference. When I use a local file, I get a broken image link. This even occurs when I use the sample for Notification Demo located here - http://code.google.com/chrome/extensions/samples.html#f799e26ceef2367cf836f24bcb47df4398b0df58
Does anyone else have this issue?
The icon is listed in my manifest file.
I can get around this by using a complete web reference, but I like to use this tool for error notifications and sometimes the error is caused by an interruption of internet access.
I am using chrome version 18.0.1025.151 m.
Thanks!
The problem with their sample is they have included "manifest_version": 2 in their manifest but not added a "web_accessible_resources" listing what resources should be available to pages.
You can read more about manifest_version 2 and what changes it introduces here....
http://code.google.com/chrome/extensions/manifestVersion.html
...and about web_accessible_resources here....
http://code.google.com/chrome/extensions/manifest.html#web_accessible_resources
To fix the problem in the sample, you can either remove the manifest version 2 bit (even the docs say this wont be required for a while yet). Or you can add the following to the manifest....
"web_accessible_resources": [
"48.png"
]
"Web Accessible" means the resources is being accessed from your server so you must make sure to include the path to the resources in your javascript and in the manifest,json.

Resources