How can I prevent a webpage from displaying a bookmarklet’s javascript text in the URL bar after running it?

I have a bookmarklet written in the form javascript:(function(){ [do some stuff to current page]; })(); that I run from Firefox. It acts on the webpage as intended, but running it replaces the website’s URL in the URL bar with the text of the bookmarklet.

Searching around for solutions it seemed as though pushState() or replaceState() should do the trick(?), but I can’t figure out how to implement them correctly.

I’ve tried adding history.replaceState({},'',window.location.protocol + '//' + window.location.hostname + window.location.pathname); as the last line inside the bookmarklet’s function(){}, but still the javascript text shows up in the URL bar instead of the URL specified by replaceState() after running. Duplicating or refreshing the window afterwards confirms that search queries in the original URL have been removed, so replaceState() is apparently working, but the text of the URL bar still isn’t being updated to match it.