Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Globally Disable Nag modals "Leave Site" "Changes may not be saved" Chrome

How can I globally and PERMANENTLY disable chromes ability to open

"Leave Site?" "Changes may not be saved" popups.

I want to close every tab of every chrome window and I know what I'm doing I don't need the nanny app to prevent my shutdown or get in my way when I'm trying to close out.

I tried tampermonkey scripts for disabling "onbeforeunload" events but they're not stopping this obnoxious behavior from chrome.

like image 456
rrz Avatar asked Sep 11 '25 17:09

rrz


1 Answers

  1. Install a beforeunload listener before the page does by declaring @run-at document-start in the metadata block.
  2. Call stopImmediatePropagation to prevent the subsequently added page listeners from seeing the event.
  3. Also clear window.onbeforeunload.
// ==UserScript==
// @name        ignore beforeunload 
// @match       *://*/*
// @grant       none
// @run-at      document-start
// ==/UserScript==

window.addEventListener('beforeunload', e => {
  window.onbeforeunload = null;
  e.stopImmediatePropagation();
});
like image 82
wOxxOm Avatar answered Sep 14 '25 14:09

wOxxOm