Skip to content

Commit

Permalink
chore: make indexeddb opt-in (#34942)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt authored Feb 27, 2025
1 parent 58db3f7 commit 10fc0ef
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/src/api/class-apirequestcontext.md
Original file line number Diff line number Diff line change
Expand Up @@ -914,4 +914,4 @@ Returns storage state for this request context, contains current cookies and loc
* since: v1.51
- `indexedDB` ?<boolean>

Defaults to `true`. Set to `false` to omit IndexedDB from snapshot.
Set to `true` to include IndexedDB in the storage state snapshot.
11 changes: 6 additions & 5 deletions docs/src/api/class-browsercontext.md
Original file line number Diff line number Diff line change
Expand Up @@ -1533,10 +1533,6 @@ Whether to emulate network being offline for the browser context.

Returns storage state for this browser context, contains current cookies, local storage snapshot and IndexedDB snapshot.

:::note
IndexedDBs with typed arrays are currently not supported.
:::

## async method: BrowserContext.storageState
* since: v1.8
* langs: csharp, java
Expand All @@ -1549,7 +1545,12 @@ IndexedDBs with typed arrays are currently not supported.
* since: v1.51
- `indexedDB` ?<boolean>

Defaults to `true`. Set to `false` to omit IndexedDB from snapshot.
Set to `true` to include IndexedDB in the storage state snapshot.
If your application uses IndexedDB to store authentication tokens, like Firebase Authentication, enable this.

:::note
IndexedDBs with typed arrays are currently not supported.
:::

## property: BrowserContext.tracing
* since: v1.12
Expand Down
11 changes: 6 additions & 5 deletions packages/playwright-client/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9267,14 +9267,15 @@ export interface BrowserContext {
/**
* Returns storage state for this browser context, contains current cookies, local storage snapshot and IndexedDB
* snapshot.
*
* **NOTE** IndexedDBs with typed arrays are currently not supported.
*
* @param options
*/
storageState(options?: {
/**
* Defaults to `true`. Set to `false` to omit IndexedDB from snapshot.
* Set to `true` to include IndexedDB in the storage state snapshot. If your application uses IndexedDB to store
* authentication tokens, like Firebase Authentication, enable this.
*
* **NOTE** IndexedDBs with typed arrays are currently not supported.
*
*/
indexedDB?: boolean;

Expand Down Expand Up @@ -18558,7 +18559,7 @@ export interface APIRequestContext {
*/
storageState(options?: {
/**
* Defaults to `true`. Set to `false` to omit IndexedDB from snapshot.
* Set to `true` to include IndexedDB in the storage state snapshot.
*/
indexedDB?: boolean;

Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/browserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ export abstract class BrowserContext extends SdkObject {
this._origins.add(origin);
}

async storageState(indexedDB = true): Promise<channels.BrowserContextStorageStateResult> {
async storageState(indexedDB = false): Promise<channels.BrowserContextStorageStateResult> {
const result: channels.BrowserContextStorageStateResult = {
cookies: await this.cookies(),
origins: []
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ export class GlobalAPIRequestContext extends APIRequestContext {
return this._cookieStore.cookies(url);
}

override async storageState(indexedDB = true): Promise<channels.APIRequestContextStorageStateResult> {
override async storageState(indexedDB = false): Promise<channels.APIRequestContextStorageStateResult> {
return {
cookies: this._cookieStore.allCookies(),
origins: (this._origins || []).map(origin => ({ ...origin, indexedDB: indexedDB ? origin.indexedDB : [] })),
Expand Down
11 changes: 6 additions & 5 deletions packages/playwright-core/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9267,14 +9267,15 @@ export interface BrowserContext {
/**
* Returns storage state for this browser context, contains current cookies, local storage snapshot and IndexedDB
* snapshot.
*
* **NOTE** IndexedDBs with typed arrays are currently not supported.
*
* @param options
*/
storageState(options?: {
/**
* Defaults to `true`. Set to `false` to omit IndexedDB from snapshot.
* Set to `true` to include IndexedDB in the storage state snapshot. If your application uses IndexedDB to store
* authentication tokens, like Firebase Authentication, enable this.
*
* **NOTE** IndexedDBs with typed arrays are currently not supported.
*
*/
indexedDB?: boolean;

Expand Down Expand Up @@ -18558,7 +18559,7 @@ export interface APIRequestContext {
*/
storageState(options?: {
/**
* Defaults to `true`. Set to `false` to omit IndexedDB from snapshot.
* Set to `true` to include IndexedDB in the storage state snapshot.
*/
indexedDB?: boolean;

Expand Down
8 changes: 4 additions & 4 deletions tests/library/browsercontext-storage-state.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ it('should round-trip through the file', async ({ contextFactory }, testInfo) =>
});

const path = testInfo.outputPath('storage-state.json');
const state = await context.storageState({ path });
const state = await context.storageState({ path, indexedDB: true });
const written = await fs.promises.readFile(path, 'utf8');
expect(JSON.stringify(state, undefined, 2)).toBe(written);

Expand Down Expand Up @@ -365,7 +365,7 @@ it('should support IndexedDB', async ({ page, server, contextFactory }) => {
await page.getByLabel('Mins').fill('1');
await page.getByText('Add Task').click();

const storageState = await page.context().storageState();
const storageState = await page.context().storageState({ indexedDB: true });
expect(storageState.origins).toEqual([
{
origin: server.PREFIX,
Expand Down Expand Up @@ -438,7 +438,7 @@ it('should support IndexedDB', async ({ page, server, contextFactory }) => {
]);

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

const recreatedPage = await context.newPage();
await recreatedPage.goto(server.PREFIX + '/to-do-notifications/index.html');
Expand All @@ -448,5 +448,5 @@ it('should support IndexedDB', async ({ page, server, contextFactory }) => {
- text: /Pet the cat/
`);

expect(await context.storageState({ indexedDB: false })).toEqual({ cookies: [], origins: [] });
expect(await context.storageState()).toEqual({ cookies: [], origins: [] });
});
2 changes: 1 addition & 1 deletion tests/library/global-fetch-cookie.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ it('should preserve local storage on import/export of storage state', async ({ p
};
const request = await playwright.request.newContext({ storageState });
await request.get(server.EMPTY_PAGE);
const exportedState = await request.storageState();
const exportedState = await request.storageState({ indexedDB: true });
expect(exportedState).toEqual(storageState);
await request.dispose();
});
Expand Down

0 comments on commit 10fc0ef

Please sign in to comment.