Update: This was an oversight on my behalf - Tabs.onUpdated.addListener does indeed fire on all mentioned events, I just had a hidden guard clause that was blocking it from firing on pushstate/pageload
I'm creating my first chrome extension (manifest v3) that injects scripts on certain URLs via a background service worker.
I started with chrome.tabs.onUpdated.addListener
, before realizing tabs.onUpdated doesn't listen for pushState events. So if i arrived from a link that used pushState, the listener wouldn't trigger.
So I added a second listener on chrome.webNavigation.onHistoryUpdated
with the same logic. ...Clumsy, but it works.
Then I realised that if I hit reload on a page, neither of the above two trigger and the script isn't injected.
Given how common this need must be, I assume(d) there'd be a simple solution to listening for a URL (& triggering JS/CSS insertion), irrespective of whether the browser arrives at the URL by initial load, conventional link, pushState, or refresh...but having scoured the docs (and stack overflow), I'm not finding anything simple.
Anyone have any thoughts? Is best practice really to do up a suite of different listeners, or am I missing something obvious?
Update: tabs.onUpdated does indeed run on all needed events. The issue I was facing is that I had a guard clause against changeInfo.url, instead of tab.url. Because changeInfo.url only updates when the url actually changes (as opposed to pageload or push state), the rest of my logic was being discarded.