I am working on an add-on that will inject some javascript into certain web pages. Which works nicely but has one problem: when I navigate to a different page the code is not always injected unless I refresh the loaded page with the F5 key.
The same behaviour also appears on certain pages with the Borderify example (which draws a border around the document body) where I have changed the manifest.json code to match these pages:
"matches": ["<all_urls>"],
or
“matches”: ["://github.com/mdn/"],
(See https://github.com/mdn/webextensions-examples/tree/main/borderify)
This is an example of the problematic behaviour:
I navigate to ‘https://github.com/mdn/webextensions-examples/’ with firefox, the colored border appears.
In this page, I click the ‘annotate-page’ link, which navigates me to ‘https://github.com/mdn/webextensions-examples/tree/main/annotate-page’, but the colored border does NOT appear.
When I refresh the page with F5, the colored border is drawn.
Clicking the browsers ‘back’ button, the previous page is shown, but WITHOUT the border. Refreshing with F5 makes the border appear again.
So my question:
Why doesn’t the code in the content_scripts work whenever the document
changes? How can I fix this?
Thanks, Thomas