Преглед изворни кода

feat: beforeunload toggling works after attaching

Sven пре 1 година
родитељ
комит
acad0e5807
1 измењених фајлова са 8 додато и 4 уклоњено
  1. 8 4
      src/features/input.ts

+ 8 - 4
src/features/input.ts

@@ -162,10 +162,14 @@ export function initBeforeUnloadHook() {
   (function(original: typeof window.addEventListener) {
     // @ts-ignore
     window.__proto__.addEventListener = function(...args: Parameters<typeof window.addEventListener>) {
-      if(!beforeUnloadEnabled && args[0] === "beforeunload")
-        return info("Prevented beforeunload event listener from being called");
-      else
-        return original.apply(this, args);
+      const origListener = typeof args[1] === "function" ? args[1] : args[1].handleEvent;
+      args[1] = function(...a) {
+        if(!beforeUnloadEnabled && args[0] === "beforeunload")
+          return info("Prevented beforeunload event listener from being called");
+        else
+          return origListener.apply(this, a);
+      };
+      original.apply(this, args);
     };
     // @ts-ignore
   })(window.__proto__.addEventListener);