![](/img/trans.png)
[英]How to run script when page loads content dynamically for Chrome Extension
[英]javascript - run chrome extension as soon as page loads
用戶訪問的網頁加載完成后,我將不再運行chrome擴展程序。
如果單擊該擴展程序,效果很好,但是我希望它在頁面加載時自動運行。
有什么辦法嗎?
這是我的清單
{
"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
,這意味着您的腳本將在頁面加載后立即注入。
在DOM完成之后,但在加載子資源(例如圖像和框架)之前,將立即注入文件。
chrome.tabs.executeScript
只能在擴展上下文中調用,而在內容腳本中則不允許。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.