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
6 changes: 6 additions & 0 deletions packages/playwright-core/src/server/storageScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ export class StorageScript {
throw new Error('Database version is unset');

const db = await this._idbRequestToPromise(indexedDB.open(dbInfo.name));
if (db.objectStoreNames.length === 0)
return { name: dbInfo.name, version: dbInfo.version, stores: [] };

const transaction = db.transaction(db.objectStoreNames, 'readonly');
const stores = await Promise.all([...db.objectStoreNames].map(async storeName => {
const objectStore = transaction.objectStore(storeName);
Expand Down Expand Up @@ -165,6 +168,9 @@ export class StorageScript {

// after `upgradeneeded` finishes, `success` event is fired.
const db = await this._idbRequestToPromise(openRequest);

if (db.objectStoreNames.length === 0)
return;
Copy link

Copilot AI Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The early return here returns undefined, which is inconsistent with the branch at line 88 that returns an object with empty stores. To avoid potential type inconsistencies for callers, consider unifying the behavior so that both cases return a consistent storage state representation.

Suggested change
return;
return { restored: false };

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c'mon copilot! restore doesn't have a return value anyways, it's OK that it returns undefined

const transaction = db.transaction(db.objectStoreNames, 'readwrite');
await Promise.all(dbInfo.stores.map(async store => {
const objectStore = transaction.objectStore(store.name);
Expand Down
22 changes: 22 additions & 0 deletions tests/library/browsercontext-storage-state.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,25 @@ it('should support IndexedDB', async ({ page, server, contextFactory }) => {

expect(await context.storageState()).toEqual({ cookies: [], origins: [] });
});

it('should support empty indexedDB', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/35760' } }, async ({ page, server, contextFactory }) => {
await page.goto(server.EMPTY_PAGE);
await page.evaluate(() => new Promise<void>(resolve => {
const openRequest = indexedDB.open('unused-db');
openRequest.onsuccess = () => resolve();
openRequest.onerror = () => resolve();
}));
const storageState = await page.context().storageState({ indexedDB: true });
expect(storageState.origins).toEqual([{
origin: server.PREFIX,
localStorage: [],
indexedDB: [{
name: 'unused-db',
version: 1,
stores: [],
}]
}]);

const context = await contextFactory({ storageState });
expect(await context.storageState({ indexedDB: true })).toEqual(storageState);
});
Loading