From 3e1ea66eee409e56519e5d1f885ec048dc66c1fe Mon Sep 17 00:00:00 2001 From: yaumu3 Date: Mon, 22 Jan 2024 09:52:34 +0900 Subject: [PATCH] refactor: extract cdp GET --- lib/helpers/webview.ts | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/lib/helpers/webview.ts b/lib/helpers/webview.ts index e8f1692a..d87de9a6 100644 --- a/lib/helpers/webview.ts +++ b/lib/helpers/webview.ts @@ -353,10 +353,10 @@ async function collectWebviewsDetails( } // https://chromedevtools.github.io/devtools-protocol/ -async function cdpList(host: string, port: number): Promise { +async function cdpGetRequest(host: string, port: number, endpoint: string): Promise { 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, @@ -367,19 +367,12 @@ async function cdpList(host: string, port: number): Promise { ).data; } -// https://chromedevtools.github.io/devtools-protocol/ +async function cdpList(host: string, port: number): Promise { + return cdpGetRequest(host, port, '/json/list'); +} + async function cdpInfo(host: string, port: number): Promise { - 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 = {