mirror of
https://github.com/microsoft/playwright-mcp.git
synced 2025-07-27 00:52:27 +08:00
browser://console should be single resource (#34)
Returning one resource per log line is flooding the Claude UI: <img width="1061" alt="Screenshot 2025-03-19 at 16 01 45" src="https://github.com/user-attachments/assets/1779374e-6b9d-44d7-b916-c521933e1085" /> Returning one big resource with all lines feels better. original PR: https://github.com/microsoft/playwright/pull/35276
This commit is contained in:
parent
cd214cb58d
commit
bd9c8729ff
@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { Resource, ResourceResult } from './resource';
|
import type { Resource } from './resource';
|
||||||
|
|
||||||
export const console: Resource = {
|
export const console: Resource = {
|
||||||
schema: {
|
schema: {
|
||||||
@ -24,14 +24,12 @@ export const console: Resource = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
read: async (context, uri) => {
|
read: async (context, uri) => {
|
||||||
const result: ResourceResult[] = [];
|
const messages = await context.ensureConsole();
|
||||||
for (const message of await context.ensureConsole()) {
|
const log = messages.map(message => `[${message.type().toUpperCase()}] ${message.text()}`).join('\n');
|
||||||
result.push({
|
return [{
|
||||||
uri,
|
uri,
|
||||||
mimeType: 'text/plain',
|
mimeType: 'text/plain',
|
||||||
text: `[${message.type().toUpperCase()}] ${message.text()}`,
|
text: log
|
||||||
});
|
}];
|
||||||
}
|
|
||||||
return result;
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -331,3 +331,35 @@ test.describe('test browser_select_option', () => {
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('browser://console', async ({ server }) => {
|
||||||
|
await server.send({
|
||||||
|
jsonrpc: '2.0',
|
||||||
|
id: 2,
|
||||||
|
method: 'tools/call',
|
||||||
|
params: {
|
||||||
|
name: 'browser_navigate',
|
||||||
|
arguments: {
|
||||||
|
url: 'data:text/html,<html><script>console.log("Hello, world!");console.error("Error"); </script></html>',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await server.send({
|
||||||
|
jsonrpc: '2.0',
|
||||||
|
id: 3,
|
||||||
|
method: 'resources/read',
|
||||||
|
params: {
|
||||||
|
uri: 'browser://console',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(response).toEqual(expect.objectContaining({
|
||||||
|
result: expect.objectContaining({
|
||||||
|
contents: [{
|
||||||
|
uri: 'browser://console',
|
||||||
|
mimeType: 'text/plain',
|
||||||
|
text: '[LOG] Hello, world!\n[ERROR] Error',
|
||||||
|
}],
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user