javascript - Injecting jQuery into Google.com using a Chrome Extension -
i'm building chrome extension , quite inject jquery google website, reason isn't working me.
here manifest file content_scripts
:
"content_scripts": [{ "matches": ["*://www.google.com/*"], "css": ["src/inject/inject.css"], "js": ["js/jquery/jquery.min.js", "src/inject/inject.js"], "run_at" : "document_start" }]
and jquery in folder supposed be. in inject.js
file have:
$("body").append("hello world"); console.log("loaded.");
and strangely enough when go google.com, loaded.
appear in console, hello world
not appended body
, nor error in console strange. did inside of inject.js
:
if (window.jquery) { $("body").append("hello world"); console.log("loaded."); } else { console.log('not loaded.'); }
and loaded.
appeared in console again, , hello world
did not appened... don't know problem is... doesn't seem make sense.
any ideas? thank you.
content scripts run in sandboxed contexts. cannot change page-dom within them. there workaround:
in content-script, add scripts via script-tags this:
var script_tag = document.createelement("script"); script_tag.setattribute("src", chrome.extension.geturl("js/jquery/jquery.min.js")); document.head.appendchild(script_tag);
Comments
Post a Comment