-
Notifications
You must be signed in to change notification settings - Fork 5k
chore(mcp): let browser_run_code support helper scripts #38730
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,3 +166,66 @@ test('browser_run_code return value', async ({ client, server }) => { | |
| result: '{"message":"Hello, world!"}', | ||
| }); | ||
| }); | ||
|
|
||
| test('browser_run_code dynamic import', async ({ client, server }) => { | ||
| test.skip(process.platform === 'win32', 'windows only works with file:// imports'); | ||
| server.setContent('/', ` | ||
| <button onclick="console.log('Submit')">Submit</button> | ||
| `, 'text/html'); | ||
| await client.callTool({ | ||
| name: 'browser_navigate', | ||
| arguments: { url: server.PREFIX }, | ||
| }); | ||
|
|
||
| const scriptPath = test.info().outputPath('helper.mjs'); | ||
| await fs.writeFile(scriptPath, ` | ||
| export async function clickSubmit(page) { | ||
| await page.getByRole("button", { name: "Submit" }).click(); | ||
| } | ||
| `); | ||
|
|
||
| const code = `async (page) => { | ||
| const { clickSubmit } = await import(${JSON.stringify(scriptPath)}); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we want to prohibit random imports? Looks like it did work for require but not for import. I think the user should have better control over what can be imported. |
||
| await clickSubmit(page); | ||
| }`; | ||
| expect(await client.callTool({ | ||
| name: 'browser_run_code', | ||
| arguments: { | ||
| code, | ||
| }, | ||
| })).toHaveResponse({ | ||
| code: `await (${code})(page);`, | ||
| consoleMessages: expect.stringContaining('- [LOG] Submit'), | ||
| }); | ||
| }); | ||
|
|
||
| test('browser_run_code dynamic import (file: proto)', async ({ client, server }) => { | ||
| server.setContent('/', ` | ||
| <button onclick="console.log('Submit')">Submit</button> | ||
| `, 'text/html'); | ||
| await client.callTool({ | ||
| name: 'browser_navigate', | ||
| arguments: { url: server.PREFIX }, | ||
| }); | ||
|
|
||
| const scriptPath = test.info().outputPath('helper.mjs'); | ||
| await fs.writeFile(scriptPath, ` | ||
| export async function clickSubmit(page) { | ||
| await page.getByRole("button", { name: "Submit" }).click(); | ||
| } | ||
| `); | ||
|
|
||
| const code = `async (page) => { | ||
| const { clickSubmit } = await import(${JSON.stringify('file://' + scriptPath)}); | ||
| await clickSubmit(page); | ||
| }`; | ||
| expect(await client.callTool({ | ||
| name: 'browser_run_code', | ||
| arguments: { | ||
| code, | ||
| }, | ||
| })).toHaveResponse({ | ||
| code: `await (${code})(page);`, | ||
| consoleMessages: expect.stringContaining('- [LOG] Submit'), | ||
| }); | ||
| }); | ||
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.
use 20 which is our oldest supported node?