【发布时间】:2012-04-30 13:42:19
【问题描述】:
我需要在更新的标签上做一些事情,比如检查页面加载是否正确,并替换页面内的内容。这是我的代码
// background.js
chrome.tabs.onUpdate.addListener(function(tabId, changeInfo, tab){
try{
chrome.tabs.executeScript(tabId, filename);
} catch(e) {
// 1. when I open a new tab
// 1. Error during tabs.executeScript: Unknown error.
// 2. when I request a url not arrive-able.
// 2. Error during tabs.executeScript: Cannot access contents of url
// "data:text/html,chromewebdata". Extension manifest must request
// permission to access this host.
// but I can't catch these errors, they just appers in background console.
}
});
我在上传的时候尝试执行脚本,但是如果当前标签是chrome://newtab或者chrome错误页面,我不能这样做,但是我无法捕捉到错误。
【问题讨论】:
标签: javascript google-chrome google-chrome-extension browser-tab