Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ export default defineConfig({
workers: 1,
projects: [
{
use: devices['Desktop Chrome'],
use: {
...devices['Desktop Chrome'],
launchOptions: {
/**
* @note Emulate Chrome's `unload` deprecation so the tests
* fail if any code relies on the `unload` event.
*/
args: ['--enable-features=DeprecateUnload'],
},
},
},
],
})
12 changes: 10 additions & 2 deletions src/extensions/persist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,16 @@ export function persist() {
const logger = new Logger('extension').extend('persist')
const COLLECTION_KEY = `${STORAGE_KEY}/${collection[kCollectionId]}`

// Flush the collection's on page unload.
window.addEventListener('unload', () => {
/**
* @note Flush the collection whenever the page becomes hidden.
* This covers reloads, navigations, and closing the page.
* The `unload` event is deprecated and blocked by Chrome.
*/
document.addEventListener('visibilitychange', () => {
if (document.visibilityState !== 'hidden') {
return
}

localStorage.setItem(
COLLECTION_KEY,
/**
Expand Down
Loading