0

My plugin is working great. I just get an error in the plugin error log if it runs on Chrome Urls like 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'
    });
});

Generates "Unchecked runtime.lastError while running tabs.executeScript: Cannot access a chrome:// URL Context _generated_background_page.html"

I tried having it only run if windows.location.hostname does not equal extensions, which makes it not run when it is on the page but I still get the error message.

I read here that it can be ignored and that there is a missing check but no example of said check. https://groups.google.com/a/chromium.org/d/msg/chromium-extensions/qC1o39YkN28/WEOAFv6xNWYJ

Brockenstein
  • 86
  • 1
  • 3
  • Simply read chrome.runtime.lastError in the callback: [example](https://stackoverflow.com/a/45603880). BTW no need for chrome.extension.getBackgroundPage() – wOxxOm Dec 10 '18 at 16:10

1 Answers1

1

I'm not aware on scenario when you need to inject script on background page through this way. Anyway you could add a callback and handle the error

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