Unexpected result when using setInterval in Firefox

Trying to diagnose an issue that I run into writing a bookmarklet for my personal use. Long story short is, it works perfectly fine on Chrome and Chromium based browser but behaves unexpectedly when executed in Firefox.

Using simple code to illustrate problem:

javascript:var number=0;function test(){console.log("The number is " + number);number++;};setInterval(test,1000);

Whenever executed in chromium based browser, the code works as intended, counting numbers from 0 up in the console until clearInterval is issued. In Firefox, however, it just returns the ID (which makes sense) but instead of counting in the console it writes the ID to the document.body, overwriting existing html.

It seems like the issue only arises with setInverval method because the code below works just fine

javascript:console.log("The number is whatever");

For clarification we’re talking about pure HTML + JS.

Any tips and help is appreciated. Thank you for your time.


Works:

javascript:console.log("The number is whatever");

Does not work:

javascript:var number=0;function test(){console.log("The number is " + number);number++;};setInterval(test,1000);

setInterval returns the interval ID but overwrites existing document.body with said ID.