How to stop any event whatsoever from occuring in vanilla JavaScript?

I would like to prevent any event whatsoever from occuring in vanilla JavaScript.

  • I don’t want to turn off JavaScript.
  • I don’t want only to prevent all DOM mutation events but to prevent any event whatsoever; even non-DOM events like alert().

So basically I would like to just freeze a webpage as-is, so not even sliders will keep working.

Is it possible to do that and if so how would you recommend to do that?


An endless loop like while(1) will not help because it will present a “page unresponsive” dialog box and will also prevent the possibility to close the window without going to a task manager and close it from there as with CTRL + ALT + Delete in Windows 11.

Probably not.

You could try binding a listener to all known events (afaik, you’d just have to hard-code a list) that just calls event.preventDefault(); and does nothing. Not all events are preventable though I think.

I’m curious why you’d event want to do this.

I want to do this because I don’t want news websites to load any kind of moving contents like sliders, gifs and moving text, esepcially not in surprise.

And instead you’ll break them from loading actual news content.
Congratulations.

We’ve had this discussion enough times that you are sure you want to see the world burn. So here. Burn on, bright spark.

for(const prop in document) {
   if(/^on/.test(prop)) {
      document.addEventListener(prop.substr(2), function(event) { event.stopPropagation(); }, true);
   }
}
1 Like

And instead you’ll break them from loading actual news content.
Congratulations.

I actually want to run it once in some time as with setInterval(), so that original news content would be parsed and rendered, just won’t change and no surprises would come as well.

We’ve had this discussion enough times that you are sure you want to see the world burn. So here. Burn on, bright spark.

I never said anywhere in my life that I want to see the world burn, even as a joke; I greatly avoid metaphors.


About the code example; first, much thanks ! :slight_smile:

I ran the code on any website with a user script manager with this configuration:

// ==UserScript==
// @name         stop all events
// @match        *://*/*
// @run-at     document-start

Much propogated content, including ads, didn’t appear; for example I saw some empty sidebars with empty blocks instead with image and text and some other content blocks appeared empty as well, but:

  • Moving repetitive text kept moving repetitively.
  • All sliders anywhere ran normally

So, I figure from this that I might have an XY problem or I am not defining the problem I am having correctly.

Maybe my problem is not with events but with moving content “hardcodedly” (for lack of a better term).

My main problem is actually sliders and moving texts.
Things like movement on mouse hover is rare and of minor importance for me and gif animations can easily be targeted and removed.

So I probably I have to freeze “movement” not “events”. But for that I need to read a good book on JavaScript graphics maybe, not asking a question in a forum. Will you agree?..

Without a specific example, I can’t offer a response.

1 Like

I avoid these for legal reasons, I totally understand.

1 Like

Have you checked if css animations is causing the undesired effects.

No, that’s a topic I don’t know anything about. Thank you for mentioning it.