Skip to content

Replace unload event with pagehide — Chrome 146+ deprecation causes Permissions Policy violation #912

@gutenye

Description

@gutenye

Description

PowerSyncDatabase registers a window.addEventListener('unload', ...) listener when enableMultiTabs is true (the default):

if (this.resolvedFlags.enableMultiTabs && !this.resolvedFlags.externallyUnload) {
this.unloadListener = () => this.close({ disconnect: false });
window.addEventListener('unload', this.unloadListener);
}

if (this.resolvedFlags.enableMultiTabs && !this.resolvedFlags.externallyUnload) {
  this.unloadListener = () => this.close({ disconnect: false });
  window.addEventListener('unload', this.unloadListener);
}

Starting with Chrome 146 (March 2026), Chrome is rolling out unload deprecation to all origins — currently 1% of page loads, reaching 100% by Chrome 153 (September 2026). When the deprecation is active, this triggers:

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

Reference: https://developer.chrome.com/docs/web-platform/deprecating-unload

Suggested Fix

Replace unload with pagehide, which is the recommended alternative and does not block bfcache:

if (this.resolvedFlags.enableMultiTabs && !this.resolvedFlags.externallyUnload) {
  this.unloadListener = () => this.close({ disconnect: false });
  window.addEventListener('pagehide', this.unloadListener);
}

And in close():

if (this.unloadListener) {
  window.removeEventListener('pagehide', this.unloadListener);
}

Current Workaround

Users can set externallyUnload: true and handle cleanup themselves:

const db = new PowerSyncDatabase({
  schema,
  database: { dbFilename: 'app.sqlite' },
  flags: { externallyUnload: true },
})

window.addEventListener('pagehide', () => {
  db.close({ disconnect: false })
})

Environment

  • @powersync/web: 1.37.0
  • Chrome 146+
  • Affects all users with default enableMultiTabs: true flag

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions