How to overload a specific JS function?
-
Hi.
I am encountering a problem with alerts from a specific site, which asks for confirmation when I close a tab ("You may have unsaved changes bla bla").
Can I overload alert() function to disable those alerts at all for this site? Maybe with vivaldi flags or maybe there are some extenisons? -
@kyshtynbai The things that pop up when you try to close a tab are known as
beforeUnload
handlers, rather than alerts. Maybe you could try setting them toundefined
to avoid them? -
I was looking for the same a while back, and came across Luminous: JavaScript events blocker. I tried it, but found the interface weird and complex and I couldn't make it work to stop beforeunload events. Maybe you have more luck.
Let us know how it goes
-
You can use userscript for that. I tried this in tampermonkey extension and it seems to work.
// ==UserScript== // @name remove onbeforeunload // @namespace http://tampermonkey.net/ // @version 0.1 // @description remove onbeforeunload // @author You // @match https://*/* // @grant none // ==/UserScript== (function() { 'use strict'; setTimeout(() => { onbeforeunload = ''; }, 1000); })();
Change
https://*/*
if you want it on a specific website, -
@greenenemy This is a bit starnge: the alert window still pop-ups with this script enabled, but the browser now crashes less often. Thanks anyway.
UPD it is a well-known problem AFAIC https://forum.vivaldi.net/topic/41909/vivaldi-crashes-when-closing-specific-tabs-with-leave-site-message/3?_=1593091436686 -