Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set keepAlive false to parse webview pages correctly Node.js >=19 #902

Merged
Merged
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
26 changes: 15 additions & 11 deletions lib/helpers/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import _ from 'lodash';
import {LRUCache} from 'lru-cache';
import os from 'node:os';
import path from 'node:path';
import http from 'node:http';
import {findAPortNotInUse} from 'portscanner';
import type {WebviewsMapping} from '../commands/types';
import type {AndroidDriverCaps} from '../driver';
Expand Down Expand Up @@ -323,8 +324,8 @@ async function collectWebviewsDetails(
for (const item of webviewsMapping) {
detailCollectors.push(
(async () => {
let port: number|undefined;
let host: string|undefined;
let port: number | undefined;
let host: string | undefined;
try {
[host, port] = await allocateDevtoolsChannel(adb, item.proc, webviewDevtoolsPort);
if (enableWebviewDetailsCollection) {
Expand Down Expand Up @@ -352,23 +353,26 @@ 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,
// 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;
}

// 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,
})
).data;
return cdpGetRequest(host, port, '/json/version');
}

const WebviewHelpers: WebviewHelpers = {
Expand Down
Loading