Skip to content

feat(codegen): add user-data-dir option #35814

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

agg23
Copy link
Contributor

@agg23 agg23 commented Apr 30, 2025

Introduces codegen --user-data-dir option to allow specification of an existing browser profile directory to use during codegen.

Resolves #35617.

@@ -414,6 +414,26 @@ pwsh bin/Debug/netX/playwright.ps1 codegen --load-storage=auth.json github.com/m

<img width="1394" alt="github signed in showing use of load storage scharp" src="https://user-images.githubusercontent.com/13063165/220928354-caa0e958-fe09-4125-9b54-67483064da51.png" />

#### Use existing userDataDir

Run `codegen` with `--user-data-dir` to set a fixed [user data directory](https://playwright.dev/docs/api/class-browsertype#browser-type-launch-persistent-context-option-user-data-dir) for the browser session. If you point this at your existing browser's user data directory, codegen will use your existing browser profile and have access to your authentication state. Remember that any authentication that codegen receives from using your browser configuration must be replicated at test time using [fixtures](./test-fixtures.md) or `before*` hooks, otherwise the UI you're trying to evaluate might not be available when executing the test.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure what our practice is for pages like test-fixtures.md as it only exists in JS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up removing the link.

This comment has been minimized.

This comment has been minimized.

Run `codegen` with `--user-data-dir` to set a fixed [user data directory](https://playwright.dev/docs/api/class-browsertype#browser-type-launch-persistent-context-option-user-data-dir) for the browser session. If you point this at your existing browser's user data directory, codegen will use your existing browser profile and have access to your authentication state. Remember that any authentication that codegen receives from using your browser configuration must be replicated at test time using fixtures or `before*` hooks, otherwise the UI you're trying to evaluate might not be available when executing the test.

```bash js
npx playwright codegen --user-data-dir=/path/to/your/browser/data/ github.com/microsoft/playwright
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work for a user who has a different profile than 'Default'. The story is a bit more complicated there that we should teach them how to get this path, what is 'Default' etc. I wonder if we want to enter this territory or if we should rely on third-party blog posts like this one. The main customers of this are Chromium anyways and doing this with page.pause() seems to have worked fine in the past.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

github-actions bot commented May 2, 2025

Test results for "tests 1"

1 failed
❌ [firefox-page] › page/page-evaluate.spec.ts:424:3 › should throw for too deep reference chain @firefox-ubuntu-22.04-node18

3 flaky ⚠️ [firefox-library] › library/inspector/cli-codegen-1.spec.ts:986:7 › cli codegen › should not throw csp directive violation errors @firefox-ubuntu-22.04-node18
⚠️ [webkit-library] › library/ignorehttpserrors.spec.ts:30:3 › should isolate contexts @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/elementhandle-bounding-box.spec.ts:22:3 › should work @webkit-ubuntu-22.04-node18

39126 passed, 803 skipped
✔️✔️✔️

Merge workflow run.

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