mirror of
https://github.com/chenasraf/DefinitelyTyped.git
synced 2026-05-18 01:49:01 +00:00
🤖 Merge PR #53913 [chrome-remote-interface] add initial definition by @kazarmy
* Add initial definition * Add callback versions of `CDP()` * Import types directly from `devtools-protocol` * Update `devtools-protocol` to 0.0.894172
This commit is contained in:
committed by
GitHub
parent
9d5bb0390b
commit
134a6bd4ca
@@ -0,0 +1,56 @@
|
||||
import CDP = require('chrome-remote-interface');
|
||||
|
||||
(async () => {
|
||||
let client: CDP.Client | undefined;
|
||||
try {
|
||||
const cdpPort = { port: 9223 };
|
||||
client = await CDP(cdpPort);
|
||||
const { Page, Runtime } = client;
|
||||
await Page.enable();
|
||||
await Page.navigate({ url: 'https://github.com' });
|
||||
// await Page.loadEventFired();
|
||||
await Runtime.enable();
|
||||
const loc = await Runtime.evaluate({ expression: 'window.location.toString()' });
|
||||
const targets = await CDP.List(cdpPort);
|
||||
for (const target of targets) {
|
||||
if (target.url.startsWith('https://github.com')) {
|
||||
await CDP.Close({ ...cdpPort, id: target.id });
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (client) {
|
||||
await client.close();
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
(() => {
|
||||
const cdpPort = { port: 9223 };
|
||||
CDP(cdpPort, client => {
|
||||
CDP.List(cdpPort, (err, targets) => {
|
||||
if (!err) {
|
||||
for (const target of targets) {
|
||||
if (target.url.startsWith('https://github.com')) {
|
||||
CDP.Close({ id: target.id }, err => {});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
client.close();
|
||||
});
|
||||
})();
|
||||
|
||||
(() => {
|
||||
CDP(client => {
|
||||
CDP.List((err, targets) => {
|
||||
if (!err) {
|
||||
for (const target of targets) {
|
||||
if (target.url.startsWith('https://github.com')) {
|
||||
CDP.Close({ id: target.id }, err => {});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
client.close();
|
||||
});
|
||||
})();
|
||||
44
types/chrome-remote-interface/index.d.ts
vendored
Normal file
44
types/chrome-remote-interface/index.d.ts
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
// Type definitions for chrome-remote-interface 0.30
|
||||
// Project: https://github.com/cyrus-and/chrome-remote-interface
|
||||
// Definitions by: Khairul Azhar Kasmiran <https://github.com/kazarmy>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// Minimum TypeScript Version: 3.8
|
||||
|
||||
import type ProtocolProxyApi from 'devtools-protocol/types/protocol-proxy-api';
|
||||
|
||||
declare namespace CDP {
|
||||
interface BaseOptions {
|
||||
host?: string;
|
||||
port?: number;
|
||||
}
|
||||
|
||||
interface ListJson {
|
||||
description: string;
|
||||
devtoolsFrontendUrl: string;
|
||||
id: string;
|
||||
title: string;
|
||||
type: string;
|
||||
url: string;
|
||||
webSocketDebuggerUrl: string;
|
||||
}
|
||||
|
||||
interface Client {
|
||||
close: () => Promise<void>;
|
||||
Page: ProtocolProxyApi.PageApi;
|
||||
Runtime: ProtocolProxyApi.RuntimeApi;
|
||||
}
|
||||
}
|
||||
|
||||
declare const CDP: {
|
||||
(options: CDP.BaseOptions, callback: (client: CDP.Client) => void): void;
|
||||
(callback: (client: CDP.Client) => void): void;
|
||||
(options?: CDP.BaseOptions): Promise<CDP.Client>;
|
||||
|
||||
Close(options: CDP.BaseOptions & { id: string }, callback: (err: Error | null) => void): void;
|
||||
Close(options: CDP.BaseOptions & { id: string }): Promise<void>;
|
||||
|
||||
List(options: CDP.BaseOptions, callback: (err: Error | null, targets: CDP.ListJson[]) => void): void;
|
||||
List(callback: (err: Error | null, targets: CDP.ListJson[]) => void): void;
|
||||
List(options?: CDP.BaseOptions): Promise<CDP.ListJson[]>;
|
||||
};
|
||||
export = CDP;
|
||||
6
types/chrome-remote-interface/package.json
Normal file
6
types/chrome-remote-interface/package.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"devtools-protocol": "0.0.894172"
|
||||
}
|
||||
}
|
||||
23
types/chrome-remote-interface/tsconfig.json
Normal file
23
types/chrome-remote-interface/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"chrome-remote-interface-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/chrome-remote-interface/tslint.json
Normal file
1
types/chrome-remote-interface/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user