fix: allow opt out from storageState
This commit is contained in:
parent
7aac96d780
commit
1931f16ed9
|
|
@ -515,7 +515,7 @@ export abstract class BrowserContext extends SdkObject {
|
|||
};
|
||||
const originsToSave = new Set(this._origins);
|
||||
|
||||
const collectScript = `(${storageScript.collect})((${utilityScriptSerializers.source})(), ${this._browser.options.name === 'firefox'})`;
|
||||
const collectScript = `(${storageScript.collect})((${utilityScriptSerializers.source})(), ${this._browser.options.name === 'firefox'}, ${Boolean(process.env.PLAYWRIGHT_SKIP_INDEXEDDB)})`;
|
||||
|
||||
// First try collecting storage stage from existing pages.
|
||||
for (const page of this.pages()) {
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ import type { source } from './isomorphic/utilityScriptSerializers';
|
|||
|
||||
export type Storage = Omit<channels.OriginStorage, 'origin'>;
|
||||
|
||||
export async function collect(serializers: ReturnType<typeof source>, isFirefox: boolean): Promise<Storage> {
|
||||
const idbResult = await Promise.all((await indexedDB.databases()).map(async dbInfo => {
|
||||
export async function collect(serializers: ReturnType<typeof source>, isFirefox: boolean, skipIndexedDB: boolean): Promise<Storage> {
|
||||
async function collectDB(dbInfo: IDBDatabaseInfo) {
|
||||
if (!dbInfo.name)
|
||||
throw new Error('Database name is empty');
|
||||
if (!dbInfo.version)
|
||||
|
|
@ -119,13 +119,13 @@ export async function collect(serializers: ReturnType<typeof source>, isFirefox:
|
|||
version: dbInfo.version,
|
||||
stores,
|
||||
};
|
||||
})).catch(e => {
|
||||
throw new Error('Unable to serialize IndexedDB: ' + e.message);
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
localStorage: Object.keys(localStorage).map(name => ({ name, value: localStorage.getItem(name)! })),
|
||||
indexedDB: idbResult,
|
||||
indexedDB: skipIndexedDB ? [] : await Promise.all((await indexedDB.databases()).map(collectDB)).catch(e => {
|
||||
throw new Error('Unable to serialize IndexedDB: ' + e.message);
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue