types
This commit is contained in:
parent
82076392f7
commit
037fe39c30
|
|
@ -520,8 +520,8 @@ export abstract class BrowserContext extends SdkObject {
|
||||||
if (!origin || !originsToSave.has(origin))
|
if (!origin || !originsToSave.has(origin))
|
||||||
continue;
|
continue;
|
||||||
try {
|
try {
|
||||||
const storage: Awaited<ReturnType<typeof storageScript.collect>> = await page.mainFrame().nonStallingEvaluateInExistingContext(`(${storageScript.collect})()`, 'utility');
|
const storage: storageScript.Storage = await page.mainFrame().nonStallingEvaluateInExistingContext(`(${storageScript.collect})()`, 'utility');
|
||||||
if (storage.localStorage.length || storage.indexedDB?.length)
|
if (storage.localStorage.length || storage.indexedDB.length)
|
||||||
result.origins.push({ origin, localStorage: storage.localStorage, indexedDB: storage.indexedDB });
|
result.origins.push({ origin, localStorage: storage.localStorage, indexedDB: storage.indexedDB });
|
||||||
originsToSave.delete(origin);
|
originsToSave.delete(origin);
|
||||||
} catch {
|
} catch {
|
||||||
|
|
@ -605,8 +605,7 @@ export abstract class BrowserContext extends SdkObject {
|
||||||
for (const originState of state.origins) {
|
for (const originState of state.origins) {
|
||||||
const frame = page.mainFrame();
|
const frame = page.mainFrame();
|
||||||
await frame.goto(metadata, originState.origin);
|
await frame.goto(metadata, originState.origin);
|
||||||
const args: Parameters<typeof storageScript.restore> = [originState];
|
await frame.evaluateExpression(storageScript.restore.toString(), { isFunction: true, world: 'utility' }, originState);
|
||||||
await frame.evaluateExpression(storageScript.restore.toString(), { isFunction: true, world: 'utility' }, args);
|
|
||||||
}
|
}
|
||||||
await page.close(internalMetadata);
|
await page.close(internalMetadata);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,9 @@
|
||||||
|
|
||||||
import type * as channels from '@protocol/channels';
|
import type * as channels from '@protocol/channels';
|
||||||
|
|
||||||
export async function collect(): Promise<Omit<channels.OriginStorage, 'origin'>> {
|
export type Storage = Omit<channels.OriginStorage, 'origin'>;
|
||||||
|
|
||||||
|
export async function collect(): Promise<Storage> {
|
||||||
const idbResult = await Promise.all((await indexedDB.databases()).map(async dbInfo => {
|
const idbResult = await Promise.all((await indexedDB.databases()).map(async dbInfo => {
|
||||||
if (!dbInfo.name)
|
if (!dbInfo.name)
|
||||||
throw new Error('Database name is empty');
|
throw new Error('Database name is empty');
|
||||||
|
|
@ -109,7 +111,7 @@ export async function restore(originState: channels.SetOriginStorage) {
|
||||||
await Promise.all(store.records.map(async record => {
|
await Promise.all(store.records.map(async record => {
|
||||||
await idbRequestToPromise(
|
await idbRequestToPromise(
|
||||||
objectStore.add(
|
objectStore.add(
|
||||||
record.value as any, // protocol says string, but this got deserialized above
|
record.value,
|
||||||
objectStore.keyPath === null ? record.key : undefined
|
objectStore.keyPath === null ? record.key : undefined
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue