Skip to content
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] Browser context serialization to support local storage #1129

Closed
arjunattam opened this issue Feb 26, 2020 · 6 comments
Closed

[Feature] Browser context serialization to support local storage #1129

arjunattam opened this issue Feb 26, 2020 · 6 comments
Assignees

Comments

@arjunattam
Copy link
Contributor

The browserContext.cookies and browserContext.setCookies methods make it possible for users to serialize cookies and load them into a new context. This enables loading a new context with authentication state before running tests.

Some apps use local storage to maintain their authentication state, and we should have similar methods for local storage.

Additionally, it might be worth evaluating whether we want to create a higher-level abstraction ("browser context state" maybe?) that covers all such storage (cookies, local storage, indexed db, etc). That way, users will not need to know which storage type they want to serialize and load over. In many cases, users are building applications where authentication is third-party (SSO etc) and therefore knowing which state type is used by auth is not possible.

@jperl
Copy link
Contributor

jperl commented Mar 6, 2020

We built a saveState and setState in playwright-utils for cookies, localStorage, sessionStorage, not indexed db yet

@vrknetha
Copy link

vrknetha commented Jul 9, 2020

I would use this to save the state so that I don't need to redo the steps for login and some other authentication

@arjunattam
Copy link
Contributor Author

We now have a guide for sharing authentication state across browser contexts (using APIs for cookies and local storage). We could evolve this into a unified API for all "browser context state" based on user feedback. Please share your user scenarios and help us identify what's missing :)

@pavelfeldman
Copy link
Member

@joshpzero
Copy link

joshpzero commented Mar 19, 2021

@pavelfeldman Can we please get sessionStorage included in this? It seems odd that it wouldn't be considered part of the storage state, even if it is less frequently used. I understand we can write it quite easily, as in the documentation but I feel like it belongs.

@yury-s
Copy link
Member

yury-s commented Mar 19, 2021

@joshpzero can you file a separate feature request for this? There are some questions like what to do if there are two pages from the same origin in the same context that have different sessionStorage states and whether sessionStorage for the current origin in the page is sufficient or you may need previous states too, otherwise it's doable. Having Page.sessionStorage()/setSessionStorage() could be more straightforward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants