I am building a chrome extension with a userinterface build in a Shadow DOM (using Vanilla Javascript).
I have disabled the "normal" pop-up window and inject the User Interface when the User is clicking the Chrome Extension icon.
However, I would like the User Interface to be disabled when Chrome is Offline, and reenable when the network connection is back online. I simply made a "offline message" behind the UI - and plan to just "hide" the UI placed in the variable "Canvas"...
I really have a hard time understanding Google's documentation regarding webRequest - it would have been great if they could provide some examples!
I have looked at this question: How to detect network state changes in a Chrome extension
This documentation: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/onErrorOccurred
But seem to be stuck! I get this error in the console: "TypeError: Cannot read property 'onErrorOccurred' of undefined"
- from this (non-working) code(placed in the content script):
let target = "https://www.google.com/searchdomaincheck?format=domain&type=chrome"
console.log(target);
console.log({url:`${target}`})
//chrome.webNavigation.onErrorOccurred.addListener(
chrome.webRequest.onErrorOccurred.addListener(
showOffline(), {url:`${target}`}
);
webRequest.onCompleted.addListener(
RemoveshowOffline(), {url:`${target}`}
);
function showOffline() {
Canvas.style.display = "none";
}
function RemoveshowOffline() {
Canvas.style.display = "inline-grid";
}