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

Ways to pass context from one browser instance to another #414

Closed
dbelozerovx1 opened this issue Feb 5, 2024 · 2 comments
Closed

Ways to pass context from one browser instance to another #414

dbelozerovx1 opened this issue Feb 5, 2024 · 2 comments

Comments

@dbelozerovx1
Copy link

Didn't find Questions tab in this repo so ill ask it here i guess

Is there any way to pass context from one playwright.Browser instance to another? Besides browser.NewContext(BrowserNewContextOptions{}), because state from ctx.StorageState() from browser is StorageState type, and for NewContext is OptionalStorageState and nested Cookie is also different types, its so frustrating, i think its not intended to work like this, manually build context every time doesnt seem okay for me

any suggestions, maybe im blind and cant see an easy way to solve my problem?

@canstand
Copy link
Collaborator

canstand commented Feb 5, 2024

try share storage state with file:

storageFile := "storage.json"

sharedBrowserContextOption := playwright.BrowserNewContextOptions{}

ctx1, _ := browser.NewContext(sharedBrowserContextOption)

ctx1.StorageState(storageFile)  // save storage

sharedBrowserContextOptions.StoragePath = playwright.String(storageFile)

// reuse ctx options
ctx2, _ := browser.NewContext(sharedBrowserContextOptions)

@dbelozerovx1
Copy link
Author

that is one way but not actually what im trying to do, here some context, i need to pass context with storageState from one browser that did some logins/auth to new another browser so the new browser will has same sessions and wont need to login/auth to apps again

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

2 participants