-
Notifications
You must be signed in to change notification settings - Fork 20
Description
Describe the bug
I use --host-resolver-rules to forward a baseURL to localhost.
This is useful in many testing scenarios (e.g. whitelisting).
This works when I run my tests on a local browser but doesn't work on remote browsers.
I assume it is related to the proxy server that playwright uses in the latter case.
I order to try to workaround this issue, I have tried to specify host mapping on my machine in the /etc/hosts file.
The same happens. It works on local browsers and doesn't work on remote browsers.
However, chrome says it respects the mapping when I query chrome://net-internals/#dns.
A Simple Reproduction
test.use({
baseURL: "https://www.wikipedia.org/",
launchOptions: {
/** Map wikipedia to github */
args: [`--host-resolver-rules=MAP www.wikipedia.org github.com`],
},
});
test("Host Mapping", async ({ page, baseURL }, testInfo) => {
// Should hit github.com
await page.goto(baseURL, { waitUntil: "load" });
await expect(page).toHaveScreenshot();
});Expected behavior
Screenshot should show the github main page
Actual behavior
Screenshot shows the wikipedia main page
To Reproduce
Steps to reproduce the behavior:
- Add the following the
playwright.config.ts
const baseURL = 'my.domain.com';
export default defineConfig({
...
use: {
baseURL,
ignoreHTTPSErrors: true,
launchOptions: {
/** Map {@link baseURL} to {@link localhost} */
args: [`--host-resolver-rules=MAP ${new URL(baseURL).host} 127.0.0.1:3000`]
},
});- Start a dev server on port 3000
- Run a test in HEADED mode (in order to open chrome diagnostics)
test("Host Mapping", async ({ page, baseURL }, testInfo) => {
await page.goto("chrome://version", { waitUntil: "load" });
await testInfo.attach("chrome-version", {
body: (await page.textContent("body")) || "",
contentType: "text/plain",
});
await page.goto("chrome://net-internals/#dns");
await page.getByRole("button", { name: "Clear host cache" }).click();
await page.getByRole("link", { name: "Sockets" }).click();
await page.getByRole("button", { name: "Flush socket pools" }).click();
await page.getByRole("link", { name: "DNS" }).click();
await page.getByRole("textbox", { name: "example.com" }).click();
await page
.getByRole("textbox", { name: "example.com" })
.fill(new URL(baseURL).hostname);
await page.getByRole("button", { name: "Lookup" }).click();
await expect(page.locator("#dns-view-dns-lookup-output")).toHaveText(
/127\.0\.0\.1/
);
await page.goto("chrome://version", { waitUntil: "load" });
await testInfo.attach("chrome-version", {
body: await page.content(),
contentType: "plain/html",
});
// Should hit localhost
await page.goto(baseURL, { waitUntil: "networkidle" });
});Expected behavior
Host mapping should be respected by the remote browser
Screenshots
If applicable, add screenshots to help explain your problem.
repro.mov
**chrome://version** output
<!DOCTYPE html><html id="t" dir="ltr" lang="en"><head>
<meta charset="utf-8">
<meta name="color-scheme" content="light dark">
<title>About Version</title>
<link rel="icon" type="image/png" sizes="32x32" href="chrome://theme/current-channel-logo">
<link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
<link rel="stylesheet" href="chrome://version/about_version.css">
<script type="module" src="about_version.js"></script>
</head>
<body>
<div id="outer">
<div id="logo">
<!-- Version for themes. -->
<picture>
<source srcset="chrome://theme/IDR_PRODUCT_LOGO_WHITE,
chrome://theme/IDR_PRODUCT_LOGO_WHITE@2x 2x" media="(prefers-color-scheme: dark)">
<source srcset="chrome://theme/IDR_PRODUCT_LOGO,
chrome://theme/IDR_PRODUCT_LOGO@2x 2x" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)">
<img alt="Chromium logo" src="chrome://theme/IDR_PRODUCT_LOGO">
</picture>
<div id="company">The Chromium Authors</div>
<div id="copyright">Copyright 2025 The Chromium Authors. All rights reserved.</div>
</div>
<table id="inner" cellpadding="0" cellspacing="0" border="0">
<tbody><tr><td class="label">Chromium</td>
<td class="version" id="version">
<span id="copy-content">
<span>134.0.6998.35</span>
(<span>Official Build</span>)
<span></span>
<span>(64-bit)</span>
</span>
<button id="copy-to-clipboard" aria-label="Copy version string">
<div id="copy-to-clipboard-icon"></div>
</button>
</td>
</tr>
<tr>
<td class="label">Revision</td>
<td class="version">
<span>ea6ef4c2ac15ae95d2cfd65682da62c093415099-refs/branch-heads/6998@{#1472}</span>
</td>
</tr>
<tr>
<td class="label">OS</td>
<td class="version" id="os_type">
<span id="copy-os-content">
<span>Linux</span>
</span>
</td>
</tr>
<tr><td class="label">JavaScript</td>
<td class="version" id="js_engine">
<span>V8</span>
<span>13.4.114.14</span>
</td>
</tr>
<tr><td class="label">User Agent</td>
<td class="version" id="useragent">Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36</td>
</tr>
<tr><td class="label">Command Line</td>
<td class="version" id="command_line"> /root/.cache/ms-playwright/chromium-1161/chrome-linux/chrome --disable-field-trial-config --disable-background-networking --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AcceptCHFrame,AutoExpandDetailsElement,AvoidUnnecessaryBeforeUnloadCheckSync,CertificateTransparencyComponentUpdater,DeferRendererTasksAfterInput,DestroyProfileOnBrowserClose,DialMediaRouteProvider,ExtensionManifestV2Disabled,GlobalMediaControls,HttpsUpgrades,ImprovedCookieControls,LazyFrameLoading,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Translate --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --unsafely-disable-devtools-self-xss-warnings --no-sandbox --proxy-server=socks5://127.0.0.1:42687 --proxy-bypass-list=<-loopback> --host-resolver-rules=MAP dev-web.collaboard.app 127.0.0.1:3000 --user-data-dir=/tmp/playwright_chromiumdev_profile-JOg6J6 --remote-debugging-pipe --no-startup-window --flag-switches-begin --flag-switches-end</td>
</tr>
<tr><td class="label">Executable Path</td>
<td class="version" id="executable_path">/root/.cache/ms-playwright/chromium-1161/chrome-linux/chrome</td>
</tr>
<tr><td class="label">Profile Path</td>
<td class="version" id="profile_path">/tmp/playwright_chromiumdev_profile-JOg6J6/Default</td>
</tr>
<tr id="variations-seed-section" hidden="">
<td class="label">Variations Seed Type</td>
<td class="version" id="variations-seed"></td>
</tr>
<tr id="variations-cmd-section">
<td class="label">Command-line Variations</td>
<td class="version-wide" id="variations-cmd" data-value="eyJkaXNhYmxlLWZlYXR1cmVzIjoiQWNjZXB0Q0hGcmFtZSxBdXRvRXhwYW5kRGV0YWlsc0VsZW1lbnQsQXZvaWRVbm5lY2Vzc2FyeUJlZm9yZVVubG9hZENoZWNrU3luYyxDZXJ0aWZpY2F0ZVRyYW5zcGFyZW5jeUNvbXBvbmVudFVwZGF0ZXIsRGVmZXJSZW5kZXJlclRhc2tzQWZ0ZXJJbnB1dCxEZXN0cm95UHJvZmlsZU9uQnJvd3NlckNsb3NlLERpYWxNZWRpYVJvdXRlUHJvdmlkZXIsRXh0ZW5zaW9uTWFuaWZlc3RWMkRpc2FibGVkLEdsb2JhbE1lZGlhQ29udHJvbHMsSHR0cHNVcGdyYWRlcyxJbXByb3ZlZENvb2tpZUNvbnRyb2xzLExhenlGcmFtZUxvYWRpbmcsTGVuc092ZXJsYXksTWVkaWFSb3V0ZXIsUGFpbnRIb2xkaW5nLFRoaXJkUGFydHlTdG9yYWdlUGFydGl0aW9uaW5nLFRyYW5zbGF0ZSIsImVuYWJsZS1mZWF0dXJlcyI6IlVrbVNhbXBsaW5nUmF0ZVx1MDAzQ1VrbVNhbXBsaW5nUmF0ZSIsImZvcmNlLWZpZWxkdHJpYWwtcGFyYW1zIjoiVWttU2FtcGxpbmdSYXRlLlNhbXBsZWRfTm9TZWVkX090aGVyOl9kZWZhdWx0X3NhbXBsaW5nLzEiLCJmb3JjZS1maWVsZHRyaWFscyI6IlVrbVNhbXBsaW5nUmF0ZS9TYW1wbGVkX05vU2VlZF9PdGhlciJ9">eyJkaXNhYmxlLWZlYXR1cmVzIjoiQWNjZXB0Q0hGcmFtZSxBdXRvRXhwYW5k...</td>
<td>
<button id="copy-variations-to-clipboard" aria-label="Copy variations string">
<div id="copy-to-clipboard-icon"></div>
</button>
</td>
</tr>
<tr id="variations-section">
<td class="label">Active Variations</td>
<td class="version" id="variations-list">f4f00e05-ca7d8d80<br>9481ce98-3d47f4f4<br>2a426c03-3d47f4f4<br>70678518-dee66fa8<br>be338734-dee66fa8<br>5f9907a9-dee66fa8<br>8eeccb9a-dee66fa8<br>2b465683-dee66fa8<br>52fc7926-dee66fa8<br>bc9b361d-dee66fa8<br>a41a7188-dee66fa8<br>ff71bfdc-dee66fa8<br>e7cc79d5-dee66fa8<br>4b935545-3d47f4f4<br>9a38bae3-6046c8a7<br>2d1e43a3-3d47f4f4<br>386dc267-3d47f4f4<br>d69d967d-3695c92e<br></td>
</tr>
<tr id="sanitizer-section" hidden="">
<td class="label">Sanitizer</td>
<td class="version" id="sanitizer"></td>
</tr>
</tbody></table>
</div>
<div id="messages" role="alert" aria-live="polite" aria-relevant="additions">
</div>
</body></html>Setup information (please complete the following information):
- Azure Subscription Id: 9fe9ffb9-c762-4e25-983b-3cc6a635a4c3
- Workspace Name: CollaboardPlaywright
- Service trace Id (if available):
- Log snippet (if available):
- Browser on which tests are executed (if applicable): chromium
- Time range (in PST) when the issue was experienced: 5:00 4/4
- Playwright Version: 1.51
- Client machine OS: macOS
- OS requested on Service: linux
Additional context
Add any other context about the problem here.