I'm working on a Firefox add-on which needs to observe tab url updates made through history.pushState
. I'm currently learning this whole WebExtension API for Firefox - it's my first add-on after Greasemonkey userscripts era.
I've tried using this slightly edited code (removed optional filter parameter) presented in the API documentation on MDN:
function logOnHistoryStateUpdated(details) {
console.log("onHistoryStateUpdated: " + details.url);
console.log("Transition type: " + details.transitionType);
console.log("Transition qualifiers: " + details.transitionQualifiers);
}
browser.webNavigation.onHistoryStateUpdated.addListener( logOnHistoryStateUpdated );
This code works for me, when used in background script, with log messages displayed in browser console. What I want is have this code working in content script, but it does not. Simply, no log messages are printed in either console.
To be sure of what is going on, I've added this code:
console.log( typeof browser );
console.log( typeof browser.webNavigation );
console.log( typeof browser.webNavigation.onHistoryStateUpdated );
console.log( typeof browser.webNavigation.onHistoryStateUpdated.addListener );
printed values are as follow:
object
undefined
so, it seems, that webNavigation API is not available in content scripts, am I right or doing something wrong? I did add the webNavigation permission in the manifest (it's the same manifest file I used with working background script). I don't see anything on MDN saying that this API can be used only in bg scripts or can't in content ones.