I am trying to inject javascript into my chrome extension, however, I can't seem to get it to work.
My manifest.json file:
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"js": ["src/inject/inject.js"],
"all_frames": true
}]
my inject.js file:
chrome.extension.sendMessage({}, function(response) {
var readyStateCheckInterval = setInterval(function() {
if (document.readyState === "complete") {
clearInterval(readyStateCheckInterval);
//my code to inject here.
}
}, 10);
});
Am I missing something? When I go to a website I expect to see it at the top of the page, but I don't see it at all. Thanks.
Unless you have a need for message passing, I would recommend adding jQuery to your list of javascript files and using $(document).ready(function() { });
to run your code after the page has loaded.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.