Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(chrome): enrich CDP failure details [C7]
Corey Olson0c6de410435e
diff --git a/test/chrome-fixture.js b/test/chrome-fixture.jsindex 466f4cb7..a0dedeca 100644--- a/test/chrome-fixture.js+++ b/test/chrome-fixture.js@@ -300,11 +300,23 @@ export function createSender(socket, pending, nextId, timeoutMs, loopDelay, relaconst now = timers.now ?? Date.now;const schedule = timers.setTimeout ?? setTimeout;const cancel = timers.clearTimeout ?? clearTimeout;+ let mainFrameNavigation = 0;+ let mainFrameId;+ let mainFrameNavigationEvent = 'none';/** Resolve or reject the request matching one CDP response without logging its payload. */function onMessage(event) {let message;try { message = JSON.parse(String(event.data)); } catch { return; }- if (message.method === 'Page.frameNavigated' && !message.params?.frame?.parentId) relayRequests.clear();+ if (message.method === 'Page.frameNavigated' && !message.params?.frame?.parentId) {+ mainFrameId = message.params.frame.id;+ mainFrameNavigation += 1;+ mainFrameNavigationEvent = 'Page.frameNavigated';+ relayRequests.clear();+ }+ if (message.method === 'Page.frameStartedNavigating' && message.params?.frameId === mainFrameId) {+ mainFrameNavigation += 1;+ mainFrameNavigationEvent = 'Page.frameStartedNavigating';+ }if (message.method === 'Network.requestWillBeSent') {const request = message.params?.request;const url = request?.url ?? '';@@ -319,8 +331,14 @@ export function createSender(socket, pending, nextId, timeoutMs, loopDelay, relaif (!waiter) return;pending.delete(message.id);cancel(waiter.timer);- if (message.error) waiter.reject(new Error(`DevTools command failed: ${waiter.method}.`));- else waiter.resolve(message.result);+ if (message.error) {+ const cdpError = message.error;+ const navigated = mainFrameNavigation !== waiter.mainFrameNavigationAtSend;+ const navigation = navigated ? `yes (${mainFrameNavigationEvent})` : 'no';+ const error = new Error(`DevTools command failed: ${waiter.method} "${waiter.label}"; CDP error ${cdpError.code}: ${cdpError.message}; page navigated since command was sent: ${navigation}.`);+ error.code = cdpError.code;+ waiter.reject(error);+ } else waiter.resolve(message.result);}socket.addEventListener('message', onMessage);return (method, params = {}, label = method, remainingMs = timeoutMs) => new Promise((resolveResult, rejectResult) => {@@ -352,7 +370,7 @@ export function createSender(socket, pending, nextId, timeoutMs, loopDelay, relarejectResult(error);};timer = schedule(expire, durationMs);- pending.set(requestId, { resolve: resolveResult, reject: rejectResult, timer, method, label });+ pending.set(requestId, { resolve: resolveResult, reject: rejectResult, timer, method, label, mainFrameNavigationAtSend: mainFrameNavigation });try { socket.send(JSON.stringify({ id: requestId, method, params })); }catch {cancel(timer);diff --git a/test/chrome-fixture.test.js b/test/chrome-fixture.test.jsindex 15c24efb..ec0a119a 100644--- a/test/chrome-fixture.test.js+++ b/test/chrome-fixture.test.js@@ -235,6 +235,53 @@ test('a failed browser evaluation names what the page threw [C7]', async () => {}});+/** Prove real CDP failures retain their causes and whether a top-level page navigation occurred [C7]. */+test('a failed DevTools command names its CDP error [C7]', {+ skip: !findChromeExecutable() && 'Chrome is not installed',+}, async () => {+ let afterRequests = 0;+ const server = createServer((request, response) => {+ if (request.url === '/after') afterRequests += 1;+ response.writeHead(200, { 'content-type': 'text/html' });+ response.end(`<!doctype html><body>${request.url === '/after' ? 'after' : 'before'}</body>`);+ });+ server.listen(0, '127.0.0.1');+ await once(server, 'listening');+ const origin = `http://127.0.0.1:${server.address().port}`;+ let chrome;+ try {+ chrome = await startChrome({ url: `${origin}/before` });+ await chrome.waitFor("location.pathname === '/before' && document.body.textContent === 'before'", 5_000, 'initial document ready'); // budget: bounds a missing local fixture document++ const navigationUrl = `${origin}/after`;+ const navigation = chrome.evaluate(`(() => {+ setTimeout(() => location.assign(${JSON.stringify(navigationUrl)}), 0);+ return new Promise(() => {});+ })()`, 'evaluate during page navigation').then(() => null, (error) => error);+ const navigationError = await navigation;+ assert.ok(navigationError instanceof Error, 'the actual page navigation rejects the pending Runtime.evaluate');+ assert.match(navigationError.message, /Runtime\.evaluate/u);+ assert.match(navigationError.message, /evaluate during page navigation/u);+ assert.match(navigationError.message, /CDP error -\d+: .+/u);+ assert.match(navigationError.message, /Inspected target navigated or closed/u);+ assert.match(navigationError.message, /page navigated since command was sent: yes \(Page\.(?:frameStartedNavigating|frameNavigated)\)/u);+ await chrome.waitFor("location.pathname === '/after' && document.body.textContent === 'after'", 5_000, 'replacement document ready'); // budget: bounds a missing local fixture document+ assert.equal(afterRequests, 1, 'the pending evaluation lost a race with one real HTTP navigation');++ const rejected = await chrome.send('Runtime.noSuchCommand', {}, 'unsupported CDP method').then(() => null, (error) => error);+ assert.ok(rejected instanceof Error, 'Chrome rejects the unsupported protocol method');+ assert.match(rejected.message, /Runtime\.noSuchCommand/u);+ assert.match(rejected.message, /unsupported CDP method/u);+ assert.match(rejected.message, /CDP error -32601: .+/u);+ assert.match(rejected.message, /wasn't found|not found/u);+ assert.match(rejected.message, /page navigated since command was sent: no/u);+ } finally {+ if (chrome) await chrome.close();+ server.closeAllConnections();+ if (server.listening) await new Promise((resolve) => server.close(resolve));+ }+});+/** Prove a page condition cannot spend the much longer general command allowance. */test('a stalled condition uses its remaining operation budget [C7]', {skip: !findChromeExecutable() && 'Chrome is not installed',