Playwright: [Feature] Browser context serialization to support local storage

Created on 26 Feb 2020  路  4Comments  路  Source: microsoft/playwright

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.

v1.7

Most helpful comment

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

All 4 comments

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

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

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 :)

This is now implemented via https://playwright.dev/#version=master&path=docs%2Fapi.md&q=browsernewpageoptions--options-storagestate

Was this page helpful?
0 / 5 - 0 ratings