Browser Plugin - when a user navigates to another page


John Clarke
I am creating a browser plugin that highlights items on a page when it finds keywords. However, when the user clicks a hyperlink the code seems to stop working. How can I get the code to continue working when the user has navigated to another URL ?

DecSoft

Hello John,

The Javascript code placed at the "WebExtContent" app's event is the "content" of the WebExtension, that is, the Javascript code which is executed on every loaded page. So, I think you must use this app's event to do the job. When the user changes to another page, by clicking in a link, for example, the "content" Javascript code is executed, so, you can do whatever you need at that point.



John Clarke
I have a variable in the browsers localstorage called "automationcoderecord". How can I access this from the WebExtContext ?

DecSoft

Hello John,

Remember that the app and the web extension content run in different contexts. I am not sure if you can set a local storage option from the app to be accessed from the web extension content and viceversa. You can try it, however, because I am not completely sure in this specific case. Anyway, if that is not possible, you always can communicate from the content to the app, so the app read the local storage and send you back the option's value.



John Clarke
Sorry to be a nuisance but how can communicate from the content to the app, so the app read the local storage and send you back the option's value ?

John Clarke
Solved! Thanks again for all of your support!

DecSoft

Hello John,

How did you do it? Because I try to apply my proposed solution... without lucky... (maybe because more information is needed, for example, where you set the local storage option) and I am here struggling with my mind in order to find another possible workaround... :-(



John Clarke
Here is my code

On WebExtBackground

and in WebExtContent


DecSoft

Hello John,

Glad to know that you got it, sir, and, thanks for sharing your code here!


Everybody can read the DecSoft support forum for learning purposes, however only DecSoft customers can post new threads. Purchase one or more licenses of some DecSoft products in order to give this and other benefits.

This website uses some useful cookies to store your preferences.

I agree. Hide this note. Give me more information.