mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
feat(proxy): support local.playwright for proxying (#8330)
This commit is contained in:
parent
44887c237d
commit
cad7fc2ef7
@ -76,6 +76,8 @@ export class Playwright extends ChannelOwner<channels.PlaywrightChannel, channel
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _onSocksRequested(uid: string, host: string, port: number): Promise<void> {
|
private async _onSocksRequested(uid: string, host: string, port: number): Promise<void> {
|
||||||
|
if (host === 'local.playwright')
|
||||||
|
host = 'localhost';
|
||||||
try {
|
try {
|
||||||
if (this._redirectPortForTest)
|
if (this._redirectPortForTest)
|
||||||
port = this._redirectPortForTest;
|
port = this._redirectPortForTest;
|
||||||
|
@ -76,7 +76,7 @@ const it = contextTest.extend<{ pageFactory: (redirectPortForTest?: number) => P
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
it.fixme(({ platform, browserName }) => browserName === 'webkit' && platform !== 'linux');
|
it.fixme(({ platform, browserName }) => browserName === 'webkit' && platform === 'win32');
|
||||||
it.skip(({ mode }) => mode !== 'default');
|
it.skip(({ mode }) => mode !== 'default');
|
||||||
|
|
||||||
async function startTestServer() {
|
async function startTestServer() {
|
||||||
@ -102,7 +102,8 @@ it('should forward non-forwarded requests', async ({ pageFactory, server }) => {
|
|||||||
expect(reachedOriginalTarget).toBe(true);
|
expect(reachedOriginalTarget).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should proxy local requests', async ({ pageFactory, server }, workerInfo) => {
|
it('should proxy localhost requests', async ({ pageFactory, server, browserName, platform }, workerInfo) => {
|
||||||
|
it.skip(browserName === 'webkit' && platform === 'darwin');
|
||||||
const { testServerPort, stopTestServer } = await startTestServer();
|
const { testServerPort, stopTestServer } = await startTestServer();
|
||||||
let reachedOriginalTarget = false;
|
let reachedOriginalTarget = false;
|
||||||
server.setRoute('/foo.html', async (req, res) => {
|
server.setRoute('/foo.html', async (req, res) => {
|
||||||
@ -117,6 +118,22 @@ it('should proxy local requests', async ({ pageFactory, server }, workerInfo) =>
|
|||||||
stopTestServer();
|
stopTestServer();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should proxy local.playwright requests', async ({ pageFactory, server, browserName }, workerInfo) => {
|
||||||
|
it.fixme(browserName === 'firefox', 'Firefox performs DNS on browser side');
|
||||||
|
const { testServerPort, stopTestServer } = await startTestServer();
|
||||||
|
let reachedOriginalTarget = false;
|
||||||
|
server.setRoute('/foo.html', async (req, res) => {
|
||||||
|
reachedOriginalTarget = true;
|
||||||
|
res.end('<html><body></body></html>');
|
||||||
|
});
|
||||||
|
const examplePort = 20_000 + workerInfo.workerIndex * 3;
|
||||||
|
const page = await pageFactory(testServerPort);
|
||||||
|
await page.goto(`http://local.playwright:${examplePort}/foo.html`);
|
||||||
|
expect(await page.content()).toContain('from-retargeted-server');
|
||||||
|
expect(reachedOriginalTarget).toBe(false);
|
||||||
|
stopTestServer();
|
||||||
|
});
|
||||||
|
|
||||||
it('should lead to the error page for forwarded requests when the connection is refused', async ({ pageFactory, browserName }, workerInfo) => {
|
it('should lead to the error page for forwarded requests when the connection is refused', async ({ pageFactory, browserName }, workerInfo) => {
|
||||||
const examplePort = 20_000 + workerInfo.workerIndex * 3;
|
const examplePort = 20_000 + workerInfo.workerIndex * 3;
|
||||||
const page = await pageFactory();
|
const page = await pageFactory();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user