Here is my manifest:
{
"name": "test.",
"version": "1.0",
"permissions": [
"tabs", "http://*/*", "https://*/*"
],
"content_scripts": [
{
"js": ["jquery.js"]
}
],
"browser_action": {
"default_title": "Set this page's color.",
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"manifest_version": 2
}
and my popup.js
function click(e) {
chrome.tabs.executeScript(null,
{code:"$('img').css('display','none');
window.close();
}
document.addEventListener('DOMContentLoaded', function () {
...
}
});
But for some reason
i get the error
Uncaught ReferenceError: $ is not defined
Why?
Problem in your code
$orjQuerykeywords are undefined.Solution
Modify your manifest to include URL where jQuery is to be injected(Do not forget to declare permission(s) for the URL’s.
The above injects jQuery in a Google Page, use
<all_urls>to inject in all websites.References