Chrome: unspecified ReferenceError jQuery not defined

I am trying to build a chrome extension. It takes the URL of the background image of the username and places it on the page. But this gives an unexpected error. Error text:

The https://twitter.com/jack page launched insecure content from http://api.twitter.com/1/users/show.json?screen_name=jack&callback=jQuery18207089675806928426_1351333462593&_=1351333462594 .

Not Prepared ReferenceError: jQuery18207089675806928426_1351333462593 is not defined (anonymous function)

error message

The extension folder contains the following files:

action.js // background.html // jquery.min.js // manifest.json

folder

action.js:

var userPage = document.URL; var arr = userPage.split("/"); var username = ""; for(i=3;i<4;i++) username += arr[i]; var page = "http://api.twitter.com/1/users/show.json?screen_name="+username+"&callback=?"; background(); function background() { $.getJSON(page, function(data) { $("span.screen-name").append(" β€’ <a href='"+data.profile_background_image_url+"'>B</a> β€’ "); }); } 

background.html:

 <html> <head> <script type="text/javascript" src="/javas.js"></script> </head> <body> </body> </html> 

jquery.min.js taken from http://code.jquery.com/jquery-1.8.2.min.js

manifest.json:

 { "name": "Twitter Background", "version": "1.0", "background_page": "background.html", "description": "Puts the background image url to the profile page.", "content_scripts": [ { "matches": ["http://twitter.com/*","https://twitter.com/*"], "js": ["jquery.min.js","action.js"], "all_frames":true } ] } 
+3
source share
1 answer

The first error ("The page on the https: ... page is insecure content from http: // ...") is just a warning and non-critical.

The second error is caused by a difference in the execution context. See Chrome extension code and content scripts against embedded scripts . As you can see, looking at the first warning, a JSONP request is made. This means that a <script> element is entered on the page. This script calls a function ( jQuery182.... ) that cannot be found because jQuery was loaded in the context of the script contents.

To solve the problem, inject action.js on the page or (recommended) add https://api.twitter.com/* to the permissions section of your manifest file, and do not use ?callback=? in the url you pass $.getJSON .

+4
source

All Articles