简体   繁体   English

Chrome扩展程序-注入Javascript不起作用

[英]Chrome Extension - Inject Javascript not working

I am trying to inject javascript into my chrome extension, however, I can't seem to get it to work. 我正在尝试将javascript插入chrome扩展程序中,但是似乎无法正常工作。

My manifest.json file: 我的manifest.json文件:

"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"js": ["src/inject/inject.js"],
"all_frames": true
}]

my inject.js file: 我的inject.js文件:

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() { }); 除非您需要传递消息,否则我建议将jQuery添加到您的javascript文件列表中,并使用$(document).ready(function() { }); to run your code after the page has loaded. 在页面加载后运行代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM