Skip to content

Commit

Permalink
fix: set keepAlive false to parse webview pages correctly on Node.js …
Browse files Browse the repository at this point in the history
…v19 onwards
  • Loading branch information
yaumu3 committed Jan 19, 2024
1 parent 7a9f654 commit ecc38b8
Showing 1 changed file with 13 additions and 2 deletions.
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

0 comments on commit ecc38b8

Please sign in to comment.