diff --git a/lib/mcp/ccs-browser-server.cjs b/lib/mcp/ccs-browser-server.cjs index bfb0d2f2..a69c413f 100755 --- a/lib/mcp/ccs-browser-server.cjs +++ b/lib/mcp/ccs-browser-server.cjs @@ -5097,16 +5097,18 @@ async function ensureInterceptSession(page) { }) ); } - pushRecentRequest({ - requestId: String(paused.requestId || ''), - pageId: page.id, - url: String(paused.request?.url || ''), - method: String(paused.request?.method || ''), - resourceType: String(paused.resourceType || ''), - matchedRuleId: matchedRule ? matchedRule.ruleId : '', - action, - statusCode: action === 'fulfill' ? matchedRule.statusCode : 0, - }); + if (matchedRule) { + pushRecentRequest({ + requestId: String(paused.requestId || ''), + pageId: page.id, + url: String(paused.request?.url || ''), + method: String(paused.request?.method || ''), + resourceType: String(paused.resourceType || ''), + matchedRuleId: matchedRule.ruleId, + action, + statusCode: action === 'fulfill' ? matchedRule.statusCode : 0, + }); + } })(); activityChain = activityChain .catch(() => {}) diff --git a/tests/unit/hooks/browser-mcp-session-and-intercepts.test.ts b/tests/unit/hooks/browser-mcp-session-and-intercepts.test.ts index 5d324aa7..7f160f9e 100644 --- a/tests/unit/hooks/browser-mcp-session-and-intercepts.test.ts +++ b/tests/unit/hooks/browser-mcp-session-and-intercepts.test.ts @@ -780,8 +780,7 @@ describe('ccs-browser MCP server - session and interception', () => { expect(listText).toContain('requestId: req-1'); expect(listText).toContain('matchedRuleId: rule-1'); expect(listText).toContain('action: fail'); - expect(listText).toContain('requestId: req-2'); - expect(listText).toContain('action: continue'); + expect(listText).not.toContain('requestId: req-2'); }); it('removes rules and recent requests bound to a page after that page is closed', async () => {