我需要在更新的标签上做一些事情,比如检查页面加载是否正确,并替换页面内的内容。这是我的代码
// 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 错误页面,我不能这样做,但我无法捕捉到错误。