javascript – Bookmarklet works fine in Opera, but when running in Firefox I get extremely weird results

I wrote this bookmarklet:

javascript:var b = document.createElement("button");b.innerHTML = "Scroll to current video";b.addEventListener("click",() => doItYesly());  = "fixed"; = 0; = 0; = "99999999";document.body.prepend(b);var s = document.createElement("button");  = "fixed"; = 0; = "50px"; = "99999999";s.innerHTML = "Set";s.addEventListener("click",() => localStorage.setItem("scrolldistanceforosautoscroller",window.scrollY));document.body.prepend(s);function doItYesly(){let inter = setInterval(() => {scrollTo(0,parseInt(localStorage.getItem("scrolldistanceforosautoscroller")));if(window.scrollY === parseInt(localStorage.getItem("scrolldistanceforosautoscroller"))){clearInterval(inter);}},100);}window

Basically it’s a tiny bookmarklet to allow a user to auto-scroll to a specific point in a long list of videos on YouTube. I wrote it for a friend of mine who repeatedly navigates to the same page over and over, and wanted to try and save some time and prevent from having to manually scroll through all the videos every time he wanted to return to the exact same spot.

When I click this bookmark in my browser (I use Opera) it works just fine. When I open the same bookmark in Firefox (he uses Firefox) it redirects me to a page that says “this page is hosted on your computer” and it simply says (object Window). This is because, in Opera when I would run my code it would print out “input scroll distance”, because the last expression evaluated to that. To fix that, I simply pointed to the window object, causing the final expression to evaluate to the page itself. This fixed the problem for Opera, but for Firefox it doesn’t fix the issue… Instead of just rendering the page like usual, it simply outputs a textual representation of the window object…

Is there any way around this? I assume this is for security, and if so then there probably isn’t a workaround… But perhaps there’s something I could do to make Firefox stop behaving this way?

When I run this same exact code from the dev console it works perfectly as expected, the problem only occurs when I save it as a bookmarklet and click on it. Any ideas?