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 1 commit
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
15 changes: 13 additions & 2 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 @@ -357,6 +358,11 @@ async function cdpList(host: string, port: number): Promise<object[]> {
await axios({
url: `http://${host}:${port}/json/list`,
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;
}
Expand All @@ -367,6 +373,11 @@ async function cdpInfo(host: string, port: number): Promise<object[]> {
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;
}
Expand Down
Loading