How to listen for URL changes in a web-extension that are initiated in the web-app itself?
Asked Answered
B

0

6

In a web-extension, I'm registering a content-script programmatically:

browser.contentScripts.register({
    matches: ["https://www.example.com/messages/*"],
    js: [{file: "my-callback-script"}],
    runAt: "document_idle"
});

The page I register it for changes its own URL without a page reload. No, not the bit right of the #, the bit of the URL to the left of the #, but still on the same domain/app. I don't think that web-extensions have a specific API for callbacks for URL changes, only for full page loads. The URL mask 'https://www.example.com/messages/*' is true for before and after, and I was hoping it would just work but it does not.

I'm pretty sure that window.onhashchange is not what I want, and window.addEventListener('popstate', listener); doesn't appear to be it either. How do I do this without polling every few seconds?

Backbreaking answered 21/10, 2018 at 1:15 Comment(3)
Have you tried to use browser.tabs.onUpdated? developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/…Teddman
ever figure this out? i know it is old. i have the exact same situation as you.Kutenai
no, never figured it outBackbreaking

© 2022 - 2024 — McMap. All rights reserved.