firefox-scripts icon indicating copy to clipboard operation
firefox-scripts copied to clipboard

User scripts @startup and @shutdown broken with 142

Open AlexVallat opened this issue 5 months ago • 6 comments

If a user script has @startup or @shutdown attributes, these no longer work. Most scripts don't have a @startup, so still work, just can't be successfully unloaded. In userChrome.js, these are called using eval which is no longer allowed.

Perhaps a workaround might be to change the userScript definition so the startup and shutdown methods are hard-coded known names, rather than defined by attributes? Or open to other ideas...

AlexVallat avatar Jul 23 '25 08:07 AlexVallat

Replace eval with Cu.evalInSandbox Demo: https://github.com/alice0775/userChrome.js/blob/master/141/restore_warnOnClose66.uc.js

benzBrake avatar Jul 23 '25 12:07 benzBrake

https://github.com/xiaoxiaoflood/firefox-scripts/issues/363#issuecomment-3110211567

117649 avatar Jul 23 '25 21:07 117649

That seems to work, thanks. I think a similar change will need to be made to rebuild_userChrome.uc.js too?

AlexVallat avatar Jul 24 '25 07:07 AlexVallat

That seems to work, thanks. I think a similar change will need to be made to rebuild_userChrome.uc.js too?

If so mine was changed long ago.

117649 avatar Jul 24 '25 09:07 117649

I couldn't find your changed rebuild_userChrome.uc.js on any other issue, but I've made the change myself as rebuild_userChrome.uc.js if anyone else needs it.

AlexVallat avatar Jul 24 '25 17:07 AlexVallat

I couldn't find your changed rebuild_userChrome.uc.js on any other issue, but I've made the change myself as rebuild_userChrome.uc.js if anyone else needs it.

I wasn't understand what you mean before now I see.

I didn't need change rebuild_userChrome.uc.js because none of the script I'm using use @shutdown.

And I just slapped

Cu.evalInSandbox(`(function(script, doc, win, loc){${script.shutdown}})`, _uc.getSandbox(win))(script, doc, win, loc);

there. I give it more argument in case I'd every encounter a wild script which in no case meaning you did anything wrong.

117649 avatar Jul 25 '25 10:07 117649