Skip to content

Commit db2bb68

Browse files
authored
fix: parse proxy URLs correctly when using useIncognitoPages (apify#3433)
1 parent 1f31779 commit db2bb68

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

packages/browser-pool/src/playwright/playwright-controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class PlaywrightController extends BrowserController<
2727

2828
return {
2929
proxy: {
30-
server: url.origin,
30+
server: `${url.protocol}//${url.host}`,
3131
username,
3232
password,
3333
bypass: pageOptions?.proxy?.bypass,

packages/browser-pool/src/puppeteer/puppeteer-controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class PuppeteerController extends BrowserController<
3131
const password = decodeURIComponent(url.password);
3232

3333
return {
34-
proxyServer: url.origin,
34+
proxyServer: `${url.protocol}//${url.host}`,
3535
proxyUsername: username,
3636
proxyPassword: password,
3737
proxyBypassList: pageOptions?.proxyBypassList,

packages/stagehand-crawler/src/internals/stagehand-controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class StagehandController extends BrowserController<BrowserType, LaunchOp
8484

8585
return {
8686
proxy: {
87-
server: url.origin,
87+
server: `${url.protocol}//${url.host}`,
8888
username,
8989
password,
9090
bypass: pageOptions?.proxy?.bypass,

test/browser-pool/browser-plugins/plugins.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,38 @@ describe('Plugins', () => {
356356

357357
runPluginTest(PuppeteerPlugin, PuppeteerController, puppeteer);
358358

359+
describe('normalizeProxyOptions', () => {
360+
test.each([
361+
['socks5://user:pass@proxy.example.com:1080', 'socks5://proxy.example.com:1080'],
362+
['http://user:pass@proxy.example.com:8080', 'http://proxy.example.com:8080'],
363+
])('PlaywrightController should handle %s', (proxyUrl, expectedServer) => {
364+
const plugin = new PlaywrightPlugin(playwright.chromium);
365+
const browserController = new PlaywrightController(plugin);
366+
367+
const result = browserController.normalizeProxyOptions(proxyUrl, {});
368+
369+
expect(result).toMatchObject({
370+
proxy: { server: expectedServer, username: 'user', password: 'pass' },
371+
});
372+
});
373+
374+
test.each([
375+
['socks5://user:pass@proxy.example.com:1080', 'socks5://proxy.example.com:1080'],
376+
['http://user:pass@proxy.example.com:8080', 'http://proxy.example.com:8080'],
377+
])('PuppeteerController should handle %s', (proxyUrl, expectedServer) => {
378+
const plugin = new PuppeteerPlugin(puppeteer);
379+
const browserController = new PuppeteerController(plugin);
380+
381+
const result = browserController.normalizeProxyOptions(proxyUrl, {});
382+
383+
expect(result).toMatchObject({
384+
proxyServer: expectedServer,
385+
proxyUsername: 'user',
386+
proxyPassword: 'pass',
387+
});
388+
});
389+
});
390+
359391
describe('Playwright specifics', () => {
360392
let browser: playwright.Browser;
361393

0 commit comments

Comments
 (0)