-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Export credential #4269
Comments
What do you think is needed on top of the cookies and storage? A user-land code for those can be found below. const cookies = await (await page.context().cookies()).filter(c => c.value !== '');
const storage = await page.evaluate(() => ({ sessionStorage, localStorage })); await context.addCookies(loggedInState.cookies);
await context.addInitScript(loggedInState => {
if (new URL(location.href).origin.endsWith('microsoft.com')) {
for (const name of Object.keys(loggedInState.session))
sessionStorage[name] = loggedInState.sessionStorage[name];
for (const name of Object.keys(loggedInState.local))
localStorage[name] = loggedInState.localStorage[name];
}
}, loggedInState); |
I think there is other state information in the user-data-dir that some sites use to validate a session. I will attempt to produce an example. I also wonder:
|
@pavelfeldman that was fast! #4412 💯 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original Issue on puppeteer
Currently, there is no reliable way to clone a browser (all session data/cookies/user data dir structure) without persisting a user data directory on disk. This makes running tests that require persistent authentication (like MFA prompts) somewhat tricky.
Proposing adding functions to API to serve this purpose:
exportCredential()
,importCredential(str)
. Export simply returns a base64-encoded string. You then provide this string when instantiating the browser, which unpacks the session data and sets the cookies. Sort of like freezing the browser in time, and then reactivating it.I am using node-tar to gzip the userDataDir, the implementation looks something like this:
Import function looks like:
parsedCredential is composed of:
._client.send('Network.getAllCookies')
page.cookies()
Is this something that would be appropriate to add to the project itself, or is it better in a utility module? I think this is a very common use-case.
The text was updated successfully, but these errors were encountered: