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