Skip to content

Commit

Permalink
chore: Add workaround for CDP host security validation (#968)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Nov 27, 2024
1 parent e27aa61 commit 07142ba
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/commands/context/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import path from 'node:path';
import http from 'node:http';
import Chromedriver from 'appium-chromedriver';
import {toDetailsCacheKey, getWebviewDetails, WEBVIEWS_DETAILS_CACHE} from './cache';
import dns from 'node:dns/promises';

// https://cs.chromium.org/chromium/src/chrome/browser/devtools/device/android_device_info_query.cc
export const CHROME_BROWSER_PACKAGE_ACTIVITY = /** @type {const} */ ({
Expand Down Expand Up @@ -96,9 +97,11 @@ async function getFreePort() {
* @returns {Promise<object[]>}
*/
async function cdpGetRequest(host, port, endpoint) {
// Workaround for https://github.com/puppeteer/puppeteer/issues/2242, https://github.com/appium/appium/issues/20782
const compatibleHost = isCompatibleCdpHost(host) ? host : (await dns.lookup(host)).address;
return (
await axios({
url: `http://${host}:${port}${endpoint}`,
url: `http://${compatibleHost}:${port}${endpoint}`,
timeout: CDP_REQ_TIMEOUT,
// We need to set this from Node.js v19 onwards.
// Otherwise, in situation with multiple webviews,
Expand Down Expand Up @@ -810,6 +813,18 @@ export async function dismissChromeWelcome() {
}
}

/**
* https://github.com/puppeteer/puppeteer/issues/2242#issuecomment-544219536
*
* @param {string} host
* @returns {boolean}
*/
function isCompatibleCdpHost (host) {
return ['localhost', 'localhost.localdomain'].includes(host)
|| host.endsWith('.localhost')
|| Boolean(net.isIP(host));
}

/**
* @typedef {import('appium-adb').ADB} ADB
*/

0 comments on commit 07142ba

Please sign in to comment.