Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To execute a function when there is a change in the URL, you can use the browser.webNavigation.onHistoryStateUpdated API. Here's how you can use it in your add-on:

  1. First, you need to declare the necessary permissions in your manifest.json file:
"permissions": [
  "webNavigation"
]
  1. In your background.js file, you can use the browser.webNavigation.onHistoryStateUpdated event listener to execute your function when there is a change in the URL:
browser.webNavigation.onHistoryStateUpdated.addListener(function(details) {
  // execute your function here
});

The details parameter contains information about the navigation event, including the new URL. You can use this information to determine if your function should be executed.

Note that this event fires when the user navigates forward or backward, as well as when navigating between pages using links or the address bar.