diff --git a/playwright.config.ts b/playwright.config.ts index e588d7d..faf774c 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -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'], + }, + }, }, ], }) diff --git a/src/extensions/persist.ts b/src/extensions/persist.ts index 3380c31..70ade94 100644 --- a/src/extensions/persist.ts +++ b/src/extensions/persist.ts @@ -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, /**