Skip to content

Commit ca06abb

Browse files
🤖 Merge PR DefinitelyTyped#74992 [chrome-remote-interface] expose CDP.ProtocolError for v0.34.0 by @madisonrickert
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 2266eb2 commit ca06abb

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

‎types/chrome-remote-interface/chrome-remote-interface-tests.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,26 @@ CDP.Activate({ id: "CC46FBFA-3BDA-493B-B2E4-2BE6EB0D97EC" }, (err) => {
408408
CDP.Version((err, info) => {
409409
if (!err) {}
410410
});
411+
412+
(async () => {
413+
const client = await CDP();
414+
try {
415+
await client.send("Page.navigate", { url: "https://github.com" });
416+
} catch (err) {
417+
if (err instanceof CDP.ProtocolError) {
418+
// $ExpectType ProtocolErrorRequest
419+
err.request;
420+
// $ExpectType string
421+
err.request.method;
422+
// $ExpectType SendError
423+
err.response;
424+
// $ExpectType number
425+
err.response.code;
426+
// $ExpectType string
427+
err.response.message;
428+
}
429+
}
430+
431+
// @ts-expect-error
432+
new CDP.ProtocolError({} as any, {} as any);
433+
})();

‎types/chrome-remote-interface/index.d.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import type ProtocolMappingApi from "devtools-protocol/types/protocol-mapping";
22
import type ProtocolProxyApi from "devtools-protocol/types/protocol-proxy-api";
33

4+
declare class ProtocolError extends Error {
5+
private constructor();
6+
readonly request: CDP.ProtocolErrorRequest;
7+
readonly response: CDP.SendError;
8+
}
9+
410
declare namespace CDP {
511
interface BaseOptions {
612
host?: string | undefined;
@@ -44,6 +50,12 @@ declare namespace CDP {
4450
data?: string | undefined;
4551
}
4652

53+
interface ProtocolErrorRequest {
54+
method: string;
55+
params?: object | undefined;
56+
sessionId?: string | undefined;
57+
}
58+
4759
interface SendCallback<T extends keyof ProtocolMappingApi.Commands> {
4860
(error: true, response: SendError): void;
4961
(error: false, response: ProtocolMappingApi.Commands[T]["returnType"]): void;
@@ -430,6 +442,8 @@ declare const CDP: {
430442
Version(options: CDP.BaseOptions, callback: (err: Error | null, info: CDP.VersionResult) => void): void;
431443
Version(callback: (err: Error | null, info: CDP.VersionResult) => void): void;
432444
Version(options?: CDP.BaseOptions): Promise<CDP.VersionResult>;
445+
446+
readonly ProtocolError: typeof ProtocolError;
433447
};
434448

435449
export = CDP;

‎types/chrome-remote-interface/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/chrome-remote-interface",
4-
"version": "0.33.9999",
4+
"version": "0.34.9999",
55
"projects": [
66
"https://github.com/cyrus-and/chrome-remote-interface"
77
],

0 commit comments

Comments
 (0)