How do I build Playwright from source and enable the playwright codegen feature with multiple selectors?

I’m trying to build Playwright from source to use the enhanced playwright codegen feature that generates multiple selectors (as discussed here). I followed the commit trail to #29154, which is merged into the main branch.

I cloned the repo from

https://github.com/microsoft/playwright/tree/main, ran:

npm run build  
npm install -g .

I expected to run playwright codegen and see multiple selectors generated, but it’s not happening, even with the latest or alpha versions.

What am I missing to get this working with the source-built version? Do I need to configure something extra to enable the enhanced codegen behavior?

Any help would be greatly appreciated!

I’ve been down this rabbit hole myself recently. After pulling the latest main branch and building it with npm run build.

I realized that just installing globally with npm install -g . doesn’t always ensure the CLI is correctly wired to your custom build, especially if you’ve got Playwright installed globally or locally elsewhere.

What worked for me was running codegen directly from the repo, like this:

node ./packages/cli/cli.js codegen https://example.com

This makes sure you’re using the version you just built, not another one from your system PATH.

Once I did that, I started seeing the multiple selector suggestions show up as expected. Give that a try and let me know if it works for you too.

I actually ran into this exact issue last week when testing out the merged PR for multiple selectors.

The key insight I found was that the multiple-selector output in codegen is behind a feature flag, and it’s not enabled by default, even if you build from source.

I had to set this environment variable before running codegen:

PW_CODEGEN_ALL_SELECTORS=1 playwright codegen https://example.com

Once I did that, boom, codegen started suggesting multiple locator strategies per element.

I don’t think they’ve fully documented this yet since it’s still considered experimental, but it worked like a charm once I toggled the flag.

Just chiming in with something that tripped me up when I built Playwright from source: codegen enhancements like multiple selector support are sometimes version-locked to browser builds too.

So even if you build the CLI from source, if you’re still pointing to a previously downloaded browser bundle, you won’t see all the new features. After building, I forced a fresh browser install with:

npx playwright install

And made sure to delete the .playwright cache folder. After that, the codegen started acting as expected with all the selector options. It’s one of those subtle things that isn’t obvious unless you’ve run into it before. Hope this helps!