Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: make indexeddb opt-in (#34942)

Simon Knott10fc0ef221dd
diff --git a/docs/src/api/class-apirequestcontext.md b/docs/src/api/class-apirequestcontext.md
index 165b9f3bd6..8cced36cc8 100644
--- a/docs/src/api/class-apirequestcontext.md
+++ b/docs/src/api/class-apirequestcontext.md
@@ -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.
diff --git a/docs/src/api/class-browsercontext.md b/docs/src/api/class-browsercontext.md
index f831bd4cae..211074d438 100644
--- a/docs/src/api/class-browsercontext.md
+++ b/docs/src/api/class-browsercontext.md
@@ -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
@@ -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
diff --git a/packages/playwright-client/types/types.d.ts b/packages/playwright-client/types/types.d.ts
index a54ce42b85..5ea9ec4def 100644
--- a/packages/playwright-client/types/types.d.ts
+++ b/packages/playwright-client/types/types.d.ts
@@ -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;
@@ -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;
diff --git a/packages/playwright-core/src/server/browserContext.ts b/packages/playwright-core/src/server/browserContext.ts
index a57af3bf12..b2bf4bf202 100644
--- a/packages/playwright-core/src/server/browserContext.ts
+++ b/packages/playwright-core/src/server/browserContext.ts
@@ -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: []
diff --git a/packages/playwright-core/src/server/fetch.ts b/packages/playwright-core/src/server/fetch.ts
index 739af0218e..e7647759a2 100644
--- a/packages/playwright-core/src/server/fetch.ts
+++ b/packages/playwright-core/src/server/fetch.ts
@@ -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 : [] })),
diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts
index a54ce42b85..5ea9ec4def 100644
--- a/packages/playwright-core/types/types.d.ts
+++ b/packages/playwright-core/types/types.d.ts
@@ -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;
@@ -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;
diff --git a/tests/library/browsercontext-storage-state.spec.ts b/tests/library/browsercontext-storage-state.spec.ts
index d1431e88fd..e22c66f23c 100644
--- a/tests/library/browsercontext-storage-state.spec.ts
+++ b/tests/library/browsercontext-storage-state.spec.ts
@@ -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);
@@ -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,
@@ -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');
@@ -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: [] });
});
diff --git a/tests/library/global-fetch-cookie.spec.ts b/tests/library/global-fetch-cookie.spec.ts
index f2f522a619..e34cf1561b 100644
--- a/tests/library/global-fetch-cookie.spec.ts
+++ b/tests/library/global-fetch-cookie.spec.ts
@@ -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();
});