chore: make indexeddb opt-in (#34942)

This commit is contained in:
Simon Knott 2025-02-27 14:27:54 +01:00 committed by GitHub
parent 58db3f7e3f
commit 10fc0ef221
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 26 additions and 23 deletions

View File

@ -914,4 +914,4 @@ Returns storage state for this request context, contains current cookies and loc
* since: v1.51 * since: v1.51
- `indexedDB` ?<boolean> - `indexedDB` ?<boolean>
Defaults to `true`. Set to `false` to omit IndexedDB from snapshot. Set to `true` to include IndexedDB in the storage state snapshot.

View File

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

View File

@ -9267,14 +9267,15 @@ export interface BrowserContext {
/** /**
* Returns storage state for this browser context, contains current cookies, local storage snapshot and IndexedDB * Returns storage state for this browser context, contains current cookies, local storage snapshot and IndexedDB
* snapshot. * snapshot.
*
* **NOTE** IndexedDBs with typed arrays are currently not supported.
*
* @param options * @param options
*/ */
storageState(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; indexedDB?: boolean;
@ -18558,7 +18559,7 @@ export interface APIRequestContext {
*/ */
storageState(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.
*/ */
indexedDB?: boolean; indexedDB?: boolean;

View File

@ -511,7 +511,7 @@ export abstract class BrowserContext extends SdkObject {
this._origins.add(origin); this._origins.add(origin);
} }
async storageState(indexedDB = true): Promise<channels.BrowserContextStorageStateResult> { async storageState(indexedDB = false): Promise<channels.BrowserContextStorageStateResult> {
const result: channels.BrowserContextStorageStateResult = { const result: channels.BrowserContextStorageStateResult = {
cookies: await this.cookies(), cookies: await this.cookies(),
origins: [] origins: []

View File

@ -693,7 +693,7 @@ export class GlobalAPIRequestContext extends APIRequestContext {
return this._cookieStore.cookies(url); return this._cookieStore.cookies(url);
} }
override async storageState(indexedDB = true): Promise<channels.APIRequestContextStorageStateResult> { override async storageState(indexedDB = false): Promise<channels.APIRequestContextStorageStateResult> {
return { return {
cookies: this._cookieStore.allCookies(), cookies: this._cookieStore.allCookies(),
origins: (this._origins || []).map(origin => ({ ...origin, indexedDB: indexedDB ? origin.indexedDB : [] })), origins: (this._origins || []).map(origin => ({ ...origin, indexedDB: indexedDB ? origin.indexedDB : [] })),

View File

@ -9267,14 +9267,15 @@ export interface BrowserContext {
/** /**
* Returns storage state for this browser context, contains current cookies, local storage snapshot and IndexedDB * Returns storage state for this browser context, contains current cookies, local storage snapshot and IndexedDB
* snapshot. * snapshot.
*
* **NOTE** IndexedDBs with typed arrays are currently not supported.
*
* @param options * @param options
*/ */
storageState(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; indexedDB?: boolean;
@ -18558,7 +18559,7 @@ export interface APIRequestContext {
*/ */
storageState(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.
*/ */
indexedDB?: boolean; indexedDB?: boolean;

View File

@ -110,7 +110,7 @@ it('should round-trip through the file', async ({ contextFactory }, testInfo) =>
}); });
const path = testInfo.outputPath('storage-state.json'); 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'); const written = await fs.promises.readFile(path, 'utf8');
expect(JSON.stringify(state, undefined, 2)).toBe(written); 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.getByLabel('Mins').fill('1');
await page.getByText('Add Task').click(); await page.getByText('Add Task').click();
const storageState = await page.context().storageState(); const storageState = await page.context().storageState({ indexedDB: true });
expect(storageState.origins).toEqual([ expect(storageState.origins).toEqual([
{ {
origin: server.PREFIX, origin: server.PREFIX,
@ -438,7 +438,7 @@ it('should support IndexedDB', async ({ page, server, contextFactory }) => {
]); ]);
const context = await contextFactory({ storageState }); const context = await contextFactory({ storageState });
expect(await context.storageState()).toEqual(storageState); expect(await context.storageState({ indexedDB: true })).toEqual(storageState);
const recreatedPage = await context.newPage(); const recreatedPage = await context.newPage();
await recreatedPage.goto(server.PREFIX + '/to-do-notifications/index.html'); 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/ - text: /Pet the cat/
`); `);
expect(await context.storageState({ indexedDB: false })).toEqual({ cookies: [], origins: [] }); expect(await context.storageState()).toEqual({ cookies: [], origins: [] });
}); });

View File

@ -376,7 +376,7 @@ it('should preserve local storage on import/export of storage state', async ({ p
}; };
const request = await playwright.request.newContext({ storageState }); const request = await playwright.request.newContext({ storageState });
await request.get(server.EMPTY_PAGE); await request.get(server.EMPTY_PAGE);
const exportedState = await request.storageState(); const exportedState = await request.storageState({ indexedDB: true });
expect(exportedState).toEqual(storageState); expect(exportedState).toEqual(storageState);
await request.dispose(); await request.dispose();
}); });