From 53ed2f601b877ea79b9244f53b6c0410a9db55e4 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Fri, 21 Mar 2025 10:24:28 +0100 Subject: [PATCH] fix(library): indexedDB shouldn't stumble over `null` in Firefox (#35308) --- packages/playwright-core/src/server/storageScript.ts | 4 ++-- tests/library/browsercontext-storage-state.spec.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/playwright-core/src/server/storageScript.ts b/packages/playwright-core/src/server/storageScript.ts index 6ed162587b..c306b11ed5 100644 --- a/packages/playwright-core/src/server/storageScript.ts +++ b/packages/playwright-core/src/server/storageScript.ts @@ -36,8 +36,8 @@ export async function collect(serializers: ReturnType, isFirefox: function isPlainObject(v: any) { const ctor = v?.constructor; if (isFirefox) { - const constructorImpl = ctor?.toString(); - if (constructorImpl.startsWith('function Object() {') && constructorImpl.includes('[native code]')) + const constructorImpl = ctor?.toString() as string | undefined; + if (constructorImpl?.startsWith('function Object() {') && constructorImpl?.includes('[native code]')) return true; } diff --git a/tests/library/browsercontext-storage-state.spec.ts b/tests/library/browsercontext-storage-state.spec.ts index abb8b368da..ec8afa8e91 100644 --- a/tests/library/browsercontext-storage-state.spec.ts +++ b/tests/library/browsercontext-storage-state.spec.ts @@ -95,7 +95,7 @@ it('should round-trip through the file', async ({ contextFactory }, testInfo) => const transaction = openRequest.result.transaction(['store', 'store2'], 'readwrite'); transaction .objectStore('store') - .put({ name: 'foo', date: new Date(0) }); + .put({ name: 'foo', date: new Date(0), null: null }); transaction .objectStore('store2') .put('bar', 'foo'); @@ -138,7 +138,7 @@ it('should round-trip through the file', async ({ contextFactory }, testInfo) => openRequest.addEventListener('error', () => reject(openRequest.error)); })); expect(idbValues).toEqual([ - { name: 'foo', date: new Date(0) }, + { name: 'foo', date: new Date(0), null: null }, 'bar' ]); await context2.close();