From 9e65dda258c9b8169a4a6486b5c018f42f6c512a Mon Sep 17 00:00:00 2001 From: huangkairan <56213366+huangkairan@users.noreply.github.com> Date: Sat, 4 Nov 2023 06:10:00 +0800 Subject: [PATCH] fix(web-extension): beforeunload logic (#1330) --- .changeset/witty-kids-talk.md | 5 +++++ packages/web-extension/src/content/index.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/witty-kids-talk.md diff --git a/.changeset/witty-kids-talk.md b/.changeset/witty-kids-talk.md new file mode 100644 index 0000000000..4a9d4f000a --- /dev/null +++ b/.changeset/witty-kids-talk.md @@ -0,0 +1,5 @@ +--- +'@rrweb/web-extension': patch +--- + +🐞 fix(web-extension): beforeunload logic diff --git a/packages/web-extension/src/content/index.ts b/packages/web-extension/src/content/index.ts index 5f99e974aa..fce329e711 100644 --- a/packages/web-extension/src/content/index.ts +++ b/packages/web-extension/src/content/index.ts @@ -155,8 +155,8 @@ async function initMainPage() { // Before unload pages, cache the new events in the local storage. window.addEventListener('beforeunload', (event) => { + if (!newEvents.length) return; event.preventDefault(); - if (newEvents.length === 0) return; void Browser.storage.local.set({ [LocalDataKey.bufferedEvents]: bufferedEvents.concat(newEvents), });