From 0f6a5c5fc24e8dc9125c5c536c8547a86ca87b15 Mon Sep 17 00:00:00 2001 From: Colin Ihrig Date: Tue, 28 Jun 2022 10:49:30 -0400 Subject: feat(web): add beforeunload event (#14830) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds the 'beforeunload' event. Co-authored-by: Bartek IwaƄczuk --- cli/tests/testdata/before_unload.js | 21 +++++++++++++++++++++ cli/tests/testdata/before_unload.js.out | 8 ++++++++ 2 files changed, 29 insertions(+) create mode 100644 cli/tests/testdata/before_unload.js create mode 100644 cli/tests/testdata/before_unload.js.out (limited to 'cli/tests/testdata') diff --git a/cli/tests/testdata/before_unload.js b/cli/tests/testdata/before_unload.js new file mode 100644 index 000000000..2572e512b --- /dev/null +++ b/cli/tests/testdata/before_unload.js @@ -0,0 +1,21 @@ +let count = 0; + +console.log("0"); + +globalThis.addEventListener("beforeunload", (e) => { + console.log("GOT EVENT"); + if (count === 0 || count === 1) { + e.preventDefault(); + setTimeout(() => { + console.log("3"); + }, 100); + } + + count++; +}); + +console.log("1"); + +setTimeout(() => { + console.log("2"); +}, 100); diff --git a/cli/tests/testdata/before_unload.js.out b/cli/tests/testdata/before_unload.js.out new file mode 100644 index 000000000..f1f2ab49a --- /dev/null +++ b/cli/tests/testdata/before_unload.js.out @@ -0,0 +1,8 @@ +0 +1 +2 +GOT EVENT +3 +GOT EVENT +3 +GOT EVENT -- cgit v1.2.3