chrome.webNavigation undefined
chrome.webNavigation
, as most chrome.* APIs, can only be accessed from the background script of an extension, not from content scripts. Although your file is named background.js
, your manifest shows that you are using it as a content script.
It is right to use a content script in this case because you need to interact with the DOM. From the fragment of code you posted, it seems that you don't need to use the webNavigation API. You can simply set your content script in your manifest to run_at: document_end
, and it will run as soon as the DOM is complete. Check http://developer.chrome.com/extensions/content_scripts.html
On top of @rsanchez answer, if you call a chrome.webNavigation
in the background script of your extension, but still have this error, you may also need to add the webNavigation
permission in your manifest.json
.
"permissions": [
"webNavigation"
]
Mozilla documentation | Chrome Documentation
you need to make sure in your manifest.json
the extension is registered with persistent: false
"background": {
"scripts": [
"./scripts/saving/extension/background.js"
],
"persistent": false // <---- HERE!!!!!
}
per what is said in here: https://developer.chrome.com/extensions/background_pages
The only occasion to keep a background script persistently active is if the extension uses chrome.webRequest API to block or modify network requests. The webRequest API is incompatible with non-persistent background pages.
!!! AND ALSO !!!
(if it was persistent: true
)
you need to UNLOAD the extension and load it again
UPDATE:
turned out it's all irrelevant
in Chrome 72 what happens is that the extension needs to be always unloaded and loaded back anew
simple refresh/reload throws this problem