Google chrome extension 如何防止chrome扩展在chrome URL上执行

Google chrome extension 如何防止chrome扩展在chrome URL上执行,google-chrome-extension,Google Chrome Extension,我的插件工作得很好。我只是在插件错误日志中得到一个错误,如果它运行在Chrome URL上,比如chrome://extensions/ // // Inject the payload.js script into the current tab after the popout has loaded // window.addEventListener('load', function (evt) { chrome.extension.getBackgroundPage().chr

我的插件工作得很好。我只是在插件错误日志中得到一个错误,如果它运行在Chrome URL上,比如chrome://extensions/

//
// Inject the payload.js script into the current tab after the popout has loaded
//

window.addEventListener('load', function (evt) {
    chrome.extension.getBackgroundPage().chrome.tabs.executeScript(null, {
        file: 'payload.js'
    });
});
运行tabs时生成“Unchecked runtime.lastError.executeScript:无法访问chrome://URL 上下文 _生成的\u background\u page.html“

我试图让它只在windows.location.hostname不等于扩展名时运行,这使得它在页面上时不会运行,但我仍然收到错误消息


我在这里读到,它可以被忽略,并且有一张遗失的支票,但没有上述支票的例子

我不知道什么时候需要通过这种方式在后台页面上注入脚本。无论如何,您可以添加回调并处理错误

window.addEventListener('load', function (evt) {
chrome.extension.getBackgroundPage().chrome.tabs.executeScript(null, {
    file: 'payload.js'
}, ()=>{
    if(chrome.runtime.lastError) {
        //handle error here
    }
});});

只需读取回调中的chrome.runtime.lastError:。顺便说一句,不需要chrome.extension.getBackgroundPage()