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
Description
PowerSyncDatabaseregisters awindow.addEventListener('unload', ...)listener whenenableMultiTabsis true (the default):powersync-js/packages/web/src/db/PowerSyncDatabase.ts
Lines 144 to 147 in f720d62
Starting with Chrome 146 (March 2026), Chrome is rolling out
unloaddeprecation to all origins — currently 1% of page loads, reaching 100% by Chrome 153 (September 2026). When the deprecation is active, this triggers:Reference: https://developer.chrome.com/docs/web-platform/deprecating-unload
Suggested Fix
Replace
unloadwithpagehide, which is the recommended alternative and does not block bfcache:And in
close():Current Workaround
Users can set
externallyUnload: trueand handle cleanup themselves:Environment
@powersync/web: 1.37.0enableMultiTabs: trueflag