1

I am trying to make a super tiny extension to wait 30 seconds and reload a page in case for any unspecific reason page couldn't load (timeouts, network instability...)

I am following Mozilla's Your first extension. So far, so good. I did that work.

However, when I am using their methods, specifically onErrorOccurred, I can't register that event instead of following the guide.

I tried disconnecting my own wifi network and try accessing a random site. I couldn't see any logging.

What am I doing wrong?

If my approach is not correct, How should I do it?

manifest.json

{

  "manifest_version": 2,
  "name": "ElEspia",
  "version": "0.0.1",

  "description": "Watchdog for kiosk-like systems browser based",

  "icons": {
    "48": "icons/icon.png"
  },

  "content_scripts": [
    {
      "matches": ["<all_urls>"],
      "js": ["watchdog.js"]
    }
  ]

}

watchdog.js

document.body.style.border = "5px solid red";



function logOnErrorOccurred(details) {
  console.log(`onErrorOccurred: ${details.url}`);
  console.log(details.error);
}

console.log("Registered");

browser.webNavigation.onErrorOccurred.addListener(logOnErrorOccurred);
Juanse Cora
  • 755
  • 9
  • 19
  • 1
    Content scripts can't use most of `browser` API. Content scripts run in web pages. You need a background script and also add webNavigation to permissions in manifest.json, see their demo extensions and the documentation. – wOxxOm May 27 '20 at 18:55
  • Thanks for the info. But just these 2 changes doesn't seem to be enough. Any additional idea? – Juanse Cora May 27 '20 at 19:34
  • 1
    Naturally you would need to move the listener function as well. See [this](https://stackoverflow.com/a/38920982) on how to open devtools for the background script so you can debug it properly. – wOxxOm May 27 '20 at 20:03
  • Thank you very very much. You pointed me in the right direction. I cannot empathized how much I appreciated. – Juanse Cora May 27 '20 at 21:46

0 Answers0