chore: only reset network log upon explicit navigation (#377)

Fixes https://github.com/microsoft/playwright-mcp/issues/376
This commit is contained in:
Pavel Feldman
2025-05-08 17:02:09 -07:00
committed by GitHub
parent 85c85bd2fb
commit 57b3c14276
14 changed files with 228 additions and 179 deletions

View File

@@ -18,12 +18,15 @@ import { test, expect } from './fixtures.js';
import fs from 'fs/promises';
import path from 'path';
test('browser_file_upload', async ({ client, localOutputPath }) => {
test('browser_file_upload', async ({ client, localOutputPath, server }) => {
server.setContent('/', `
<input type="file" />
<button>Button</button>
`, 'text/html');
expect(await client.callTool({
name: 'browser_navigate',
arguments: {
url: 'data:text/html,<html><title>Title</title><input type="file" /><button>Button</button></html>',
},
arguments: { url: server.PREFIX },
})).toContainTextContent(`
\`\`\`yaml
- button "Choose File" [ref=s1e3]
@@ -96,17 +99,18 @@ The tool "browser_file_upload" can only be used when there is related modal stat
}
});
test('clicking on download link emits download', async ({ startClient, localOutputPath }) => {
test('clicking on download link emits download', async ({ startClient, localOutputPath, server }) => {
const outputDir = localOutputPath('output');
const client = await startClient({
config: { outputDir },
});
server.setContent('/', `<a href="/download" download="test.txt">Download</a>`, 'text/html');
server.setContent('/download', 'Data', 'text/plain');
expect(await client.callTool({
name: 'browser_navigate',
arguments: {
url: 'data:text/html,<a href="data:text/plain,Hello world!" download="test.txt">Download</a>',
},
arguments: { url: server.PREFIX },
})).toContainTextContent('- link "Download" [ref=s1e3]');
await client.callTool({
name: 'browser_click',
@@ -133,7 +137,7 @@ test('navigating to download link emits download', async ({ client, server, mcpB
expect(await client.callTool({
name: 'browser_navigate',
arguments: {
url: server.PREFIX + '/download',
url: server.PREFIX + 'download',
},
})).toContainTextContent('### Downloads');
});