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?

  • Moderator

    @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 to undefined 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
    // @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,

Log in to reply

Looks like your connection to Vivaldi Forum was lost, please wait while we try to reconnect.