mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
docs(auth.md): JavaScript writeFileSync/readFileSync usage not async (#22649)
This commit is contained in:
parent
9ad9b6b316
commit
60afcc9c6c
@ -584,14 +584,13 @@ Reusing authenticated state covers [cookies](https://developer.mozilla.org/en-US
|
|||||||
```js
|
```js
|
||||||
// Get session storage and store as env variable
|
// Get session storage and store as env variable
|
||||||
const sessionStorage = await page.evaluate(() => JSON.stringify(sessionStorage));
|
const sessionStorage = await page.evaluate(() => JSON.stringify(sessionStorage));
|
||||||
await fs.writeFileSync('playwright/.auth/session.json', JSON.stringify(sessionStorage), 'utf-8');
|
fs.writeFileSync('playwright/.auth/session.json', JSON.stringify(sessionStorage), 'utf-8');
|
||||||
|
|
||||||
// Set session storage in a new context
|
// Set session storage in a new context
|
||||||
const sessionStorage = JSON.parse(await fs.readFileSync('playwright/.auth/session.json', 'utf-8'));
|
const sessionStorage = JSON.parse(fs.readFileSync('playwright/.auth/session.json', 'utf-8'));
|
||||||
await context.addInitScript(storage => {
|
await context.addInitScript(storage => {
|
||||||
if (window.location.hostname === 'example.com') {
|
if (window.location.hostname === 'example.com') {
|
||||||
const entries = JSON.parse(storage);
|
for (const [key, value] of Object.entries(storage)) {
|
||||||
for (const [key, value] of Object.entries(entries)) {
|
|
||||||
window.sessionStorage.setItem(key, value);
|
window.sessionStorage.setItem(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user