Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make proxy option in compatible with PlaywrightLaunchOptions format #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export interface LaunchOptions {
/** Proxy to use for the browser.
* Note: If `geoip` is `true`, a request will be sent through this proxy to find the target IP.
*/
proxy?: string;
proxy?: string | PlaywrightLaunchOptions['proxy'];

/** Cache previous pages, requests, etc. (uses more memory). */
enable_cache?: boolean;
Expand Down Expand Up @@ -568,7 +568,7 @@ export async function launchOptions({

// Find the user's IP address
if (proxy) {
geoip = await publicIP(proxy)
geoip = await publicIP(typeof proxy === 'string' ? proxy : proxy.server)
} else {
geoip = await publicIP()
}
Expand All @@ -591,7 +591,7 @@ export async function launchOptions({
// This is a very bad idea; the warning cannot be ignored with i_know_what_im_doing.
if (
proxy &&
!proxy.includes('localhost') &&
!(typeof proxy === 'string' ? proxy : proxy.server).includes('localhost') &&
!isDomainSet(config, 'geolocation:')
) {
LeakWarning.warn('proxy_without_geoip');
Expand Down Expand Up @@ -692,11 +692,15 @@ export async function launchOptions({

let pwProxy: any = undefined;
if (proxy) {
let proxyUrl = new URL(proxy);
pwProxy = {
server: proxyUrl.origin,
username: proxyUrl.username,
password: proxyUrl.password,
if (typeof proxy === 'string') {
let proxyUrl = new URL(proxy);
pwProxy = {
server: proxyUrl.origin,
username: proxyUrl.username,
password: proxyUrl.password,
}
} else {
pwProxy = proxy;
}
}

Expand Down