gpt4 book ai didi

javascript - 页面加载后立即运行 chrome 扩展

转载 作者:行者123 更新时间:2023-12-03 06:43:57 25 4
gpt4 key购买 nike

我不想在用户访问的网页完成加载后立即运行我的 Chrome 扩展程序。

如果我单击该扩展程序,它就可以正常工作,但我希望它在页面加载时自动运行。

有什么办法可以做到这一点吗?

这是我的 list

{
"manifest_version": 2,

"name": "Simple Text Highlighter",
"description": "This plugin notify of the word 'Simple' in the current page",
"version": "1.0",

"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},

"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"js": ["jquery.min.js", "highlightSimple.js"],
"css": ["highlight.css"],
"run_at": "document_end"
}],

"permissions": [
"tabs",
"activeTab",
"notifications",
"http://*/",
"https://*/"
]

}

这是 JavaScript

(function () {
chrome.tabs.executeScript(null, {
file: 'highlight.css'
}, function () {
chrome.tabs.executeScript(null, {
file: 'jquery.min.js'
}, function () {
chrome.tabs.executeScript(null, {
file: 'replace.js'
});
});
})
})();

提前致谢。

最佳答案

您已设置run_at字段document_end,这意味着您的脚本将在页面加载后立即注入(inject)。

the files are injected immediately after the DOM is complete, but before subresources like images and frames have loaded.

并且 chrome.tabs.executeScript 只能在扩展上下文中调用,在内容脚本中不允许。

关于javascript - 页面加载后立即运行 chrome 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37829802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com