Skip to content

fix: 🐛 use pagehide for lifecycle cleanup#57

Open
aermin wants to merge 1 commit into
mainfrom
agent/fix-pagehide-lifecycle
Open

fix: 🐛 use pagehide for lifecycle cleanup#57
aermin wants to merge 1 commit into
mainfrom
agent/fix-pagehide-lifecycle

Conversation

@aermin

@aermin aermin commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #56 by replacing lifecycle cleanup that relied on the deprecated unload event with pagehide.

Why

Registering unload handlers can trigger Chrome permissions policy warnings. Unlike unload, pagehide also reports whether a page is entering the back-forward cache through event.persisted.

Changes

  • Stop registering unload handlers for heartbeat and lock cleanup.
  • Clean up heartbeat timers and this client's locks on non-BFCache pagehide.
  • Preserve the current lifecycle state when pagehide.persisted === true.
  • Add Jest regression coverage in test/bfcache.test.ts for both lifecycle branches.

The tests exercise this polyfill's lifecycle handling; existing cross-context heartbeat behavior is unchanged.

Validation

  • npm test -- --runInBand (13 suites, 68 tests)
  • npm run lint
  • npm run build

@aermin
aermin force-pushed the agent/fix-pagehide-lifecycle branch 3 times, most recently from 0a1c109 to 6abe81d Compare July 22, 2026 14:55
@aermin aermin changed the title Use pagehide for lifecycle cleanup fix: use pagehide for lifecycle cleanup Jul 22, 2026
@aermin
aermin force-pushed the agent/fix-pagehide-lifecycle branch from 6abe81d to 27bc1bb Compare July 22, 2026 15:17
@aermin aermin changed the title fix: use pagehide for lifecycle cleanup fix: 🐛 use pagehide for lifecycle cleanup Jul 22, 2026
@aermin
aermin marked this pull request as ready for review July 22, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Violation] Permissions policy violation: unload is not allowed in this document

1 participant