siefkenj / react-userscripts

Develop a Greasemonkey/Tampermonkey script using React
GNU General Public License v3.0
82 stars 19 forks source link

Tips: Firefox with ViolentMonkey granting api perm(s) in dev mode crashes #11

Closed bosam closed 2 years ago

bosam commented 2 years ago

Hi,

First off, thank you for creating this boilerplate project which truly helped me fast-forward on a script idea I had been brewing in my head for a while.

The issue

It is NOT related to this bundle but exists because of ViolentMonkey latest public version 2.13.0 makes the dev injection fails or if it does not fail, will fail the react code later when using a useEffect or a useState hook. It is good to notice that you also need to @grant an API method (or several) - (@grant none will not trigger the issue)

After trying to debug it for the last couple of days, I found that this was how they allow the window dom object to be accessed and how react-dom has a specific function that only applies in dev mode. The method is called: invokeGuardedCallbackDev and will try to access the faulty window object to get its event and crash.

The solution for now?

Install one of the latest ViolentMonkey beta. They have seemingly fixed the way they interact with window and unsafeWindow much better now!


It was truly driving me crazy but I am glad this is not a widespread issue, well, at least if somebody is in the same boat as I am, this post will be helpful to others!

siefkenj commented 2 years ago

Thanks for noticing this. I'm sure it will be helpful to others. Would you mind adding a line in the README about ViolentMonkey compatibility?