-
Notifications
You must be signed in to change notification settings - Fork 244
Open
Description
Description
When using playwright-cli open --extension, the run-code command fails with page is undefined error.
Reproduction Steps
- Run:
playwright-cli open --extension - Select a tab in the browser (with existing logged-in session)
- Run:
playwright-cli run-code "async page => { await page.waitForLoadState('networkidle'); return await page.evaluate(() => document.body.innerText); }"
Expected Behavior
The page parameter should be available in the callback function, allowing Playwright API calls like page.waitForLoadState(), page.evaluate(), etc.
Actual Behavior
Error: page is undefined
Root Cause Analysis
Looking at the source code:
- In
lib/mcp/browser/tools/runCode.js:56-58:
const context = {
page: tab.page,
__end__
};-
tab.pagecomes fromTabclass initialization inlib/mcp/browser/tab.js:49 -
In
--extensionmode, the browser context is created viaExtensionContextFactory(seelib/mcp/program.js:64-70) -
The
Tabobject may not be properly initialized via_onPageCreatedcallback when connecting to an existing browser tab through the extension.
Impact
This prevents users from:
- Using
run-codeto execute Playwright API calls in extension mode - Waiting for page states (e.g.,
waitForLoadState('networkidle')) - Executing complex page evaluations
Workaround
- Use normal mode without
--extensionflag - Use
state-save/state-loadto transfer authentication state between sessions
Environment
- playwright-cli version: 0.1.1
- playwright version: 1.59.0-alpha
- Node.js: v22.20.0
- OS: macOS (darwin)
Related Issues
- Feature Request: extension mode support #211 - Feature Request: extension mode support
- Extension seems broken again #254 - Extension seems broken again
- 'playwright-cli --extension open' does not play well with PLAYWRIGHT_MCP_EXTENSION_TOKEN #267 - --extension does not play well with PLAYWRIGHT_MCP_EXTENSION_TOKEN
evalwith arrow function produces "TypeError: result is not a function" #296 - eval with arrow function produces error (similar workaround suggested)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels