0

Although there are a lot of similar questions here, I couldn't solve my problem with any of the accepted solutions, so I'm creating a new question.

I have a content script that adds some functionality to a Jira Issue. However, when navigating to the Jira Issue from a Filter Results Page, the content script doesn't run until I manually reload the page.

What I've tried so far:

  1. Adding webNavigation Listeners (with the manifest permission), but none of them seem to trigger when the Jira Issue link is clicked from the Filter Page.
// background.js

const myLog = () => console.log('webNavigation event triggered');

browser.webNavigation.onDOMContentLoaded.addListener(myLog);
browser.webNavigation.onHistoryStateUpdated.addListener(myLog);
browser.webNavigation.onReferenceFragmentUpdated.addListener(myLog);
  1. Adding "all_frames": true to the manifest.json, but that didn't make it work either:
// manifest.json

...

"background": {
    "scripts": ["background.js"],
    "persistent": false
  },
"content_scripts": [
    {
      "matches": ["*://jira.atlassian.com/*"],
      "js": ["content.js"],
      "all_frames": true
    }
  ],
"permissions": ["tabs", "webNavigation", "<all_urls>"]
  1. Listening to window.onpopstate event inside the content script. Although it detects when I click the "Back" and "Forward" arrows in the browser, it doesn't fire when I click the links inside the Filter Results Page.
// content.js

window.onpopstate = () => {
 browser.runtime.sendMessage('webNavigation event triggered');
}

How can I run this content script without having to manually reload the page?

Lucas Mendonca
  • 387
  • 3
  • 13
  • webNavigation listeners should be triggered so you probably look in the [wrong console](/q/38913799). It's easier to use chrome.tabs.onUpdated though. See also [this answer](/a/39508954) for more info. – wOxxOm Feb 13 '22 at 01:42
  • @wOxxOm mmm it doesn't seem to be the wrong console. Maybe the problem has to do with the fact that the URL itself doesn't change, the page is just re-rendered but the URL is the same. I've tried the pjax:end and the hashchange options but it didn't work either. MutationObservers work, but they seem a bit hacky... – Lucas Mendonca Feb 13 '22 at 18:14
  • 1
    MutationObserver is the right tool, conceptually and practically, if the URL doesn't change. – wOxxOm Feb 13 '22 at 20:46
  • @wOxxOm Thank you! Then [this answer of yours](https://stackoverflow.com/questions/2844565/is-there-a-javascript-jquery-dom-change-listener/39508954#39508954) is more than enough to deal with this problem. – Lucas Mendonca Feb 14 '22 at 11:17

0 Answers0