For some reason, jQuery doesn't work in my background.js in my Google Chrome extension.
Suppose my plugin tells me all the images on the page. I verified that it gets to the below method OK, but it stops at the jQuery loop.
First, manifest.json: note I'm including jQuery, the file exists:
{
"name": "Gallery",
"version": "0.0.1",
"manifest_version": 2,
"description": "Gallery",
"browser_action": {
"default_icon": "G.png"
},
"background": {
"persistent": true,
"scripts": ["jquery-1.11.2.min.js", "background.js"]
},
"permissions": [
"tabs", "contextMenus", "http://*/*", "https://*/*"
],
"content_scripts": [
{
"matches": [
"http://*/*",
"https://*/*"
],
"css": ["contentstyle.css"],
"js": ["jquery-1.11.2.min.js", "contentscript.js"]
}
],
"icons": {
"32": "G.png"
}
}
background.js uses the jQuery syntax:
chrome.browserAction.onClicked.addListener(scanImages);
function scanImages()
{
// IT GETS HERE - THIS IS OK
alert('Clicked plugin button, about to start looping thru IMG...');
// BUT STOPS HERE: JQUERY DOESN'T EXECUTE
$("img").each(function() {
alert($(this).prop("src"));
});
// ANOTHER JQUERY THAT DOESN'T WORK
alert('Page title = ' + $(document).find("title").text());
}