I want to inject jQuery into a web page (with a content script) in a Chrome extension.
I try, but something confuses me.
here is my manifest.json
The situation is very similar to this question.
Content scripts live in their own, isolated JavaScript context. This is done so that scripts added by extensions don't coflict with the page or each other.
When you open the Dev Tools console, it shows console messages from all contexts of the webpage: page's context, contexts of the iframes (which are also isolated) and content script contexts. That's why you see the log message.
However, while it can show all messages at once, if you try to execute something, it must go to one context. By default, it's the page's context: <top frame>
just above the console.
To execute something in the extension's context, you need to switch to it:
And if you want to make some JavaScript available to the page context, you need to inject it into the page itself as a <script>
tag. See this question.
I used this and it's working fine. maybe the path of your jquery is not correct.
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"js": ["js/jquery.min.js", "js/socket/socket.io.js","js/socket/client.js"],
"run_at": "document_idle"
}]