Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions apps/extension/src/browser-driver/__tests__/chromium-cdp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,29 @@ describe("ChromiumCdp", () => {
]);
});

it.each([
[{ type: "string", value: "connection token expired" }, "connection token expired"],
[{ type: "string", value: "first line\nsecond line" }, "first line"],
[{ type: "number", value: 0, description: "0" }, "0"],
[{ type: "boolean", value: false }, "false"],
[{ type: "object", subtype: "null", value: null }, "null"],
[{ type: "undefined" }, "[undefined]"],
])("records the thrown primitive %j in console entries", async (exception, text) => {
const { api, onEvent } = fakeApi();
const cdp = new ChromiumCdp(api);
try {
await cdp.ensureAttached(22);
onEvent.fire({ tabId: 22 }, "Runtime.exceptionThrown", {
exceptionDetails: { text: "Uncaught", exception },
});
expect(cdp.consoleEntriesSince(22, 0, 50, 1000, false).entries).toMatchObject([
{ kind: "exception", level: "error", text },
]);
} finally {
cdp.dispose();
}
});

it("filters console entries by cursor and caps result size", async () => {
const { api, onEvent } = fakeApi();
const cdp = new ChromiumCdp(api);
Expand Down
2 changes: 1 addition & 1 deletion apps/extension/src/browser-driver/chromium-cdp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ export function parseExceptionThrown(params: unknown): ParsedConsoleEntry | null
const details = (raw.exceptionDetails ?? {}) as Record<string, unknown>;
const exception = (details.exception ?? {}) as Record<string, unknown>;
const text =
firstLine(typeof exception.description === "string" ? exception.description : undefined) ||
firstLine(remoteObjectToText(exception)) ||
firstLine(typeof details.text === "string" ? details.text : undefined) ||
"Uncaught (unknown error)";
return makeConsoleEntry({
Expand Down
22 changes: 22 additions & 0 deletions apps/extension/src/tools/__tests__/evaluate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,28 @@ describe("handleEvaluate", () => {
expect(res.error?.column).toBe(8);
});

it.each([
[{ type: "string", value: "connection token expired" }, "Uncaught connection token expired"],
[{ type: "boolean", value: false }, "Uncaught false"],
[{ type: "object", subtype: "null", value: null }, "Uncaught null"],
[{ type: "number", value: 0, description: "0" }, "0"],
])("preserves a thrown primitive %j ahead of the generic header", async (exception, text) => {
const sm = new SessionManager({ agentWindow: fakeAgentWindow([100]) });
await sm.start("aa11");
const fake = makeFakeCdp({
evaluate: () => ({
result: exception,
exceptionDetails: { text: "Uncaught", lineNumber: 0, columnNumber: 0, exception },
}),
});
const res = await handleEvaluate(
sm,
{ session_id: "aa11", expression: "throw value" },
{ cdp: fake.cdp, tabsApi: fake.tabsApi },
);
expect(res).toMatchObject({ ok: false, error: { text, line: 1, column: 0 } });
});

it("stringifies unserializableValue (Infinity / NaN / BigInt)", async () => {
const sm = new SessionManager({ agentWindow: fakeAgentWindow([100]) });
await sm.start("aa11");
Expand Down
10 changes: 4 additions & 6 deletions apps/extension/src/tools/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,17 @@ function abortedError(signal: AbortSignal | undefined): RpcError | null {

/**
* Pull a human-readable error text out of CDP's exception payload.
* Prefers `exception.description` (the full stack) and falls back to
* `exceptionDetails.text` (the short header). Both are best-effort —
* Chrome sometimes ships an empty string when the throw value is
* `null` / `undefined` / a non-Error primitive.
* Prefers `exception.description` (the full stack), then a thrown
* primitive's value, before falling back to the generic short header.
*/
function extractErrorText(details: CdpExceptionDetails): string {
const desc = details.exception?.description?.trim();
if (desc) return desc;
const text = details.text?.trim();
if (text) return text;
if (details.exception?.value !== undefined) {
return `Uncaught ${String(details.exception.value)}`;
}
const text = details.text?.trim();
if (text) return text;
return "Uncaught (unknown error)";
}

Expand Down