-
Notifications
You must be signed in to change notification settings - Fork 218
Document Playwright MCP usage to prevent module loading errors #15848
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -162,6 +162,53 @@ tools: | |||||
| allowed_domains: ["github.com", "*.github.io"] | ||||||
| ``` | ||||||
|
|
||||||
| ### Cannot Find Module 'playwright' | ||||||
|
|
||||||
| **Error Message:** | ||||||
|
|
||||||
| ```text | ||||||
| Error: Cannot find module 'playwright' | ||||||
| Require stack: | ||||||
| - /tmp/gh-aw/agent/script.js | ||||||
| ``` | ||||||
|
|
||||||
| **Cause:** The AI agent tried to use `require('playwright')` or created a standalone Node.js script expecting the playwright npm package to be installed. In gh-aw workflows, Playwright is provided through an MCP server interface, not as an npm package. | ||||||
|
|
||||||
| **Solution:** Use Playwright through MCP tools instead of trying to require the module: | ||||||
|
|
||||||
| ```javascript | ||||||
| // ❌ INCORRECT - This won't work | ||||||
| const playwright = require('playwright'); | ||||||
| const browser = await playwright.chromium.launch(); | ||||||
|
|
||||||
| // ✅ CORRECT - Use MCP Playwright tools | ||||||
| // Example: Navigate and take screenshot | ||||||
| await mcp__playwright__browser_navigate({ | ||||||
| url: "https://example.com" | ||||||
| }); | ||||||
|
|
||||||
| await mcp__playwright__browser_snapshot(); | ||||||
|
|
||||||
| // Example: Execute custom Playwright code | ||||||
| await mcp__playwright__browser_run_code({ | ||||||
| code: `async (page) => { | ||||||
| await page.setViewportSize({ width: 390, height: 844 }); | ||||||
| const title = await page.title(); | ||||||
| return { title, url: page.url() }; | ||||||
| }` | ||||||
| }); | ||||||
| ``` | ||||||
|
|
||||||
| **Available MCP Playwright Tools:** | ||||||
| - `mcp__playwright__browser_navigate` - Navigate to URL | ||||||
| - `mcp__playwright__browser_snapshot` - Take screenshot | ||||||
| - `mcp__playwright__browser_run_code` - Execute custom Playwright code | ||||||
| - `mcp__playwright__browser_click` - Click elements | ||||||
| - `mcp__playwright__browser_type` - Type text | ||||||
| - `mcp__playwright__browser_close` - Close browser | ||||||
|
|
||||||
| See the [Playwright Tool documentation](/gh-aw/reference/tools/#playwright-tool-playwright) for complete details. | ||||||
|
||||||
| See the [Playwright Tool documentation](/gh-aw/reference/tools/#playwright-tool-playwright) for complete details. | |
| See the [Playwright tool configuration documentation](/gh-aw/reference/tools/#playwright-tool-playwright) for configuration details. For the runtime MCP tool list and signatures, run `gh aw mcp inspect`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Playwright MCP call in this example isn’t awaited. Since these MCP tool calls are async, leaving off
awaitcan cause agents to proceed before navigation/testing completes. Update the snippet to explicitlyawaitthemcp__playwright__browser_run_code(...)call (and close it consistently).