Skip to content
Merged
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 types/chrome-remote-interface/chrome-remote-interface-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,26 @@ CDP.Activate({ id: "CC46FBFA-3BDA-493B-B2E4-2BE6EB0D97EC" }, (err) => {
CDP.Version((err, info) => {
if (!err) {}
});

(async () => {
const client = await CDP();
try {
await client.send("Page.navigate", { url: "https://github.com" });
} catch (err) {
if (err instanceof CDP.ProtocolError) {
// $ExpectType ProtocolErrorRequest
err.request;
// $ExpectType string
err.request.method;
// $ExpectType SendError
err.response;
// $ExpectType number
err.response.code;
// $ExpectType string
err.response.message;
}
}

// @ts-expect-error
new CDP.ProtocolError({} as any, {} as any);
})();
14 changes: 14 additions & 0 deletions types/chrome-remote-interface/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import type ProtocolMappingApi from "devtools-protocol/types/protocol-mapping";
import type ProtocolProxyApi from "devtools-protocol/types/protocol-proxy-api";

declare class ProtocolError extends Error {
private constructor();
readonly request: CDP.ProtocolErrorRequest;
readonly response: CDP.SendError;
}

declare namespace CDP {
interface BaseOptions {
host?: string | undefined;
Expand Down Expand Up @@ -44,6 +50,12 @@ declare namespace CDP {
data?: string | undefined;
}

interface ProtocolErrorRequest {
method: string;
params?: object | undefined;
sessionId?: string | undefined;
}

interface SendCallback<T extends keyof ProtocolMappingApi.Commands> {
(error: true, response: SendError): void;
(error: false, response: ProtocolMappingApi.Commands[T]["returnType"]): void;
Expand Down Expand Up @@ -430,6 +442,8 @@ declare const CDP: {
Version(options: CDP.BaseOptions, callback: (err: Error | null, info: CDP.VersionResult) => void): void;
Version(callback: (err: Error | null, info: CDP.VersionResult) => void): void;
Version(options?: CDP.BaseOptions): Promise<CDP.VersionResult>;

readonly ProtocolError: typeof ProtocolError;
};

export = CDP;
2 changes: 1 addition & 1 deletion types/chrome-remote-interface/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@types/chrome-remote-interface",
"version": "0.33.9999",
"version": "0.34.9999",
"projects": [
"https://github.com/cyrus-and/chrome-remote-interface"
],
Expand Down