💬 Commit message: Update 2026-02-11 04:16:38, 12 files, 588 lines

📁 Files changed: 12
📝 Lines changed: 588

  • TODO.md
  • browser.d.ts
  • browser.d.ts.map
  • browser.js
  • browser.js.map
  • mcp.js
  • mcp.js.map
  • types.d.ts
  • types.d.ts.map
  • browser.ts
  • mcp.ts
  • types.ts
This commit is contained in:
Adam Ladachowski
2026-02-11 04:16:38 +01:00
parent 5a7466b67d
commit f7df5d8f54
12 changed files with 577 additions and 11 deletions
+120
View File
@@ -202,6 +202,63 @@ server.tool(
})
);
// Network monitoring
server.tool(
'network',
'Get captured network requests and responses',
{
filter: z
.enum(['all', 'failed', 'xhr', 'fetch', 'document', 'script', 'stylesheet', 'image'])
.optional()
.default('all')
.describe('Filter by request type or status'),
clear: z.boolean().optional().default(false).describe('Clear entries after retrieving'),
},
withLogging('network', async ({ filter, clear }) => {
await ensureLaunched();
const requests = browser.getNetwork(filter, clear);
return textResult(JSON.stringify({ ok: true, count: requests.length, requests }));
})
);
server.tool(
'intercept',
'Block or mock network requests matching a pattern',
{
action: z.enum(['block', 'mock', 'list', 'clear']).describe('Action to perform'),
pattern: z
.string()
.optional()
.describe('URL pattern to match (glob syntax, e.g., "**/api/*" or "**/*.png")'),
status: z.number().optional().describe('HTTP status code for mock response'),
body: z.string().optional().describe('Response body for mock'),
contentType: z
.string()
.optional()
.default('application/json')
.describe('Content-Type for mock response'),
},
withLogging('intercept', async ({ action, pattern, status, body, contentType }) => {
await ensureLaunched();
if (action === 'list') {
const patterns = browser.getInterceptPatterns();
return textResult(JSON.stringify({ ok: true, count: patterns.length, patterns }));
}
if (action === 'clear') {
await browser.clearIntercepts();
return textResult(JSON.stringify({ ok: true, message: 'All intercepts cleared' }));
}
if (!pattern) {
return textResult(JSON.stringify({ ok: false, error: 'Pattern required for block/mock' }));
}
const response = action === 'mock' ? { status, body, contentType } : undefined;
await browser.addIntercept(pattern, action, response);
return textResult(
JSON.stringify({ ok: true, action, pattern, patterns: browser.getInterceptPatterns() })
);
})
);
// Utility
server.tool(
'wait',
@@ -561,6 +618,69 @@ server.resource(
}
);
// Resource: browser://network - All captured network requests
server.resource(
'Network Requests',
'browser://network',
{ description: 'All network requests captured from the browser', mimeType: 'application/json' },
async () => {
if (!launched) {
return {
contents: [
{
uri: 'browser://network',
mimeType: 'application/json',
text: JSON.stringify({ launched: false, requests: [] }),
},
],
};
}
const requests = browser.getNetwork('all', false);
return {
contents: [
{
uri: 'browser://network',
mimeType: 'application/json',
text: JSON.stringify({ launched: true, count: requests.length, requests }),
},
],
};
}
);
// Resource: browser://network/failed - Failed network requests only
server.resource(
'Failed Requests',
'browser://network/failed',
{
description: 'Failed network requests (errors and 4xx/5xx status codes)',
mimeType: 'application/json',
},
async () => {
if (!launched) {
return {
contents: [
{
uri: 'browser://network/failed',
mimeType: 'application/json',
text: JSON.stringify({ launched: false, requests: [] }),
},
],
};
}
const requests = browser.getNetwork('failed', false);
return {
contents: [
{
uri: 'browser://network/failed',
mimeType: 'application/json',
text: JSON.stringify({ launched: true, count: requests.length, requests }),
},
],
};
}
);
// Resource: browser://screenshot - Current page screenshot (base64)
server.resource(
'Page Screenshot',