Skip to content

Commit 204328e

Browse files
authored
Conditionally add unload event listener (enable bfcache) (#88)
1 parent 41ef3d7 commit 204328e

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ jobs:
3030
if: github.ref_name == 'main'
3131
run: npm run release
3232
env:
33-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
33+
NODE_AUTH_TOKEN: ${{ secrets.KRAKENJS_PAYPAL_SDK_NPM_AUTH_TOKEN }}
3434

3535
- name: Publish alpha to npm (non-main branch)
3636
if: github.ref_name != 'main'
3737
run: npm run release:alpha
3838
env:
39-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
39+
NODE_AUTH_TOKEN: ${{ secrets.KRAKENJS_PAYPAL_SDK_NPM_AUTH_TOKEN }}

src/logger.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -385,13 +385,16 @@ export function Logger({
385385
immediateFlush();
386386
});
387387

388-
window.addEventListener("unload", () => {
389-
immediateFlush();
390-
});
391-
392-
window.addEventListener("pagehide", () => {
393-
immediateFlush();
394-
});
388+
// Use pagehide if available, fallback to unload
389+
if ("onpagehide" in window) {
390+
window.addEventListener("pagehide", () => {
391+
immediateFlush();
392+
});
393+
} else {
394+
window.addEventListener("unload", () => {
395+
immediateFlush();
396+
});
397+
}
395398
}
396399

397400
const logger = {

0 commit comments

Comments
 (0)