Skip to content

Commit

Permalink
refactor: extract cdp GET
Browse files Browse the repository at this point in the history
  • Loading branch information
yaumu3 committed Jan 22, 2024
1 parent ecc38b8 commit 3e1ea66
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions lib/helpers/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,10 @@ async function collectWebviewsDetails(
}

// https://chromedevtools.github.io/devtools-protocol/
async function cdpList(host: string, port: number): Promise<object[]> {
async function cdpGetRequest(host: string, port: number, endpoint: string): Promise<object[]> {
return (
await axios({
url: `http://${host}:${port}/json/list`,
url: `http://${host}:${port}${endpoint}`,
timeout: CDP_REQ_TIMEOUT,
// We need to set this from Node.js v19 onwards.
// Otherwise, in situation with multiple webviews,
Expand All @@ -367,19 +367,12 @@ async function cdpList(host: string, port: number): Promise<object[]> {
).data;
}

// https://chromedevtools.github.io/devtools-protocol/
async function cdpList(host: string, port: number): Promise<object[]> {
return cdpGetRequest(host, port, '/json/list');
}

async function cdpInfo(host: string, port: number): Promise<object[]> {
return (
await axios({
url: `http://${host}:${port}/json/version`,
timeout: CDP_REQ_TIMEOUT,
// We need to set this from Node.js v19 onwards.
// Otherwise, in situation with multiple webviews,
// the preceding webview pages will be incorrectly retrieved as the current ones.
// https://nodejs.org/en/blog/announcements/v19-release-announce#https11-keepalive-by-default
httpAgent: new http.Agent({keepAlive: false}),
})
).data;
return cdpGetRequest(host, port, '/json/version');
}

const WebviewHelpers: WebviewHelpers = {
Expand Down

0 comments on commit 3e1ea66

Please sign in to comment.