我有这段代码:
chrome.tabs.onUpdated.addListener(function(id, changes, tab)
{
if (changes.status != "complete") return false;
chrome.tabs.executeScript(id, {code: "alert('Page loaded.');"});
});
它在调试器中执行,但不起作用。为什么呢?
答案 0 :(得分:0)
请完全按照此处的定义进行尝试。
<强>的manifest.json 强>
{
"manifest_version": 2,
"name": "Execute script app",
"version": "1.0",
"background": {
"persistent":true,
"page":"background.html"
},
"content_scripts": [{
"matches": ["http://*/*"],
"js": ["app.js"]
}
],
"permissions": [
"tabs",
"http://*/*"
]
}
<强> background.html 强>
<script src="background.js"></script>
<强> background.js 强>
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab){
if(changeInfo && changeInfo.status == "complete"){
chrome.tabs.executeScript(tabId, {code: "alert('Page loaded.');"});
}
});
<强> app.js 强>
//well this is just empty since ur not doing anything here