Restore scratch setup bootstrap and live frontdoor sweep
This commit is contained in:
@@ -211,6 +211,37 @@ export async function authenticateFrontdoor(options = {}) {
|
||||
return report;
|
||||
}
|
||||
|
||||
export function getSessionStorageEntries(authReport) {
|
||||
return Array.isArray(authReport?.storage?.sessionStorageEntries)
|
||||
? authReport.storage.sessionStorageEntries.filter(
|
||||
(entry) => Array.isArray(entry) && typeof entry[0] === 'string' && typeof entry[1] === 'string',
|
||||
)
|
||||
: [];
|
||||
}
|
||||
|
||||
export async function addSessionStorageInitScript(context, authReport) {
|
||||
const sessionEntries = getSessionStorageEntries(authReport);
|
||||
await context.addInitScript((entries) => {
|
||||
sessionStorage.clear();
|
||||
for (const [key, value] of entries) {
|
||||
if (typeof key === 'string' && typeof value === 'string') {
|
||||
sessionStorage.setItem(key, value);
|
||||
}
|
||||
}
|
||||
}, sessionEntries);
|
||||
}
|
||||
|
||||
export async function createAuthenticatedContext(browser, authReport, options = {}) {
|
||||
const context = await browser.newContext({
|
||||
ignoreHTTPSErrors: true,
|
||||
storageState: options.statePath || DEFAULT_STATE_PATH,
|
||||
...options.contextOptions,
|
||||
});
|
||||
|
||||
await addSessionStorageInitScript(context, authReport);
|
||||
return context;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const report = await authenticateFrontdoor();
|
||||
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
||||
|
||||
Reference in New Issue
Block a user