better logs for maps and sets

This commit is contained in:
Tommy D. Rossi
2025-11-22 14:52:51 +01:00
parent 96b1f8a4c8
commit 5c64ecde08
2 changed files with 24 additions and 2 deletions
+16 -2
View File
@@ -53,6 +53,20 @@ function safeSerialize(arg: any): string {
if (typeof value === 'object' && value !== null) {
if (seen.has(value)) return '[Circular]';
seen.add(value);
if (value instanceof Map) {
return {
dataType: 'Map',
value: Array.from(value.entries())
};
}
if (value instanceof Set) {
return {
dataType: 'Set',
value: Array.from(value.values())
};
}
}
return value;
});
@@ -394,7 +408,7 @@ export class RelayConnection {
//
// To fix this, we intercept 'Runtime.enable' and force a reset:
// 1. We send 'Runtime.disable'. This clears Chrome's internal Runtime state for this session.
// 2. We wait a brief moment (50ms) to ensure the disable command propagates.
// 2. We wait a brief moment (100ms) to ensure the disable command propagates.
// 3. Then we allow the original 'Runtime.enable' command to proceed.
//
// This sequence forces Chrome to treat the enablement as a fresh start, causing it to
@@ -404,7 +418,7 @@ export class RelayConnection {
logger.debug('Runtime.enable called, disabling first to force context refresh for tab:', targetTab.debuggee.tabId);
try {
await chrome.debugger.sendCommand(debuggerSession, 'Runtime.disable');
await new Promise(resolve => setTimeout(resolve, 50));
await new Promise(resolve => setTimeout(resolve, 100));
} catch (e) {
logger.debug('Error disabling Runtime (ignoring):', e);
}
+8
View File
@@ -21,6 +21,14 @@ the chrome window can have more than one page. you can see other pages with `con
you can control the browser in collaboration with the user. the user can help you get unstuck from captchas or difficult to find elements or reproducing a bug
## capabilities
examples of things playwriter MCP can do:
- monitor logs for a page while the user reproduces a but to let you understand what is causing a bug
- monitor logs while also controlling the page, then read collected logs and debug an issue
- monitor xhr network requests while scrolling an infinite scroll page to extract data from a website
- get accessibility snapshot to see clickable elements on the page, then click or interact with them to automate a task like ordering pizza
## finding the page to execute code in
if you plan to control a specific page for an url you can store it in `state` so you can reuse it later on: