Removing/Replacing a content script from web page--does unregister currently work?


Removing/Replacing a content script from web page--does unregister currently work?



Do you know if the unregister() function currently works in Firefox?



I thought it wasn't working but it does after the page is reloaded. I was expecting the change to take place in the current load.



I was able to register a content script, meaning inject via the background script at the desired point. However, I can't get unregister() to remove the content script from the page and then inject a new one.



The first obj object loads into the page and functions, but the unregister and new register don't do anything. The post message in the else block sends the message back that the code entered the else block to unregister. If the obj objects are reversed, the first loads into the page and works, but nothing happens when try to unregister and register the new content. Changing the "matches" property and manifest.json permissions to all_urls made no difference; and no errors appear in the debug console of the extension.



Am I misunderstanding what unregister() is supposed to do?



Is there another way to remove/replace the content js and css files from a web page?



Thank you.


async function register(obj) {

if ( !obj ) {

obj = {

"matches": ["file:///*extension%20test.html"],

"js": [ { 'file' : "content.js" } ],

"css" : [ { 'file' : "styles.css" } ]

};

}

else

{

portFromCS.postMessage( { 'func' : 'disp_result', 'args' : { 'msg' : "Unregistering : ", 'value' : obj.js[0].file } } );

registered.unregister();

obj = {

"matches": ["file:///*extension%20test.html"],

"js": [ { 'file' : "content2.js" } ],

"css" : [ { 'file' : "styles.css" } ]

};


};

registered = await browser.contentScripts.register( obj );


}









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to input without newline? (Python)

C++ thread error: no type named ‘type’ MINGW

Analog for TagView in flutter