Skip to content

Commit 7d7bf50

Browse files
committed
fixes
1 parent 503ada9 commit 7d7bf50

File tree

6 files changed

+144
-129
lines changed

6 files changed

+144
-129
lines changed

packages/playwright-core/src/server/browser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ export abstract class Browser extends SdkObject {
101101
validateBrowserContextOptions(options, this.options);
102102
let clientCertificatesProxy: ClientCertificatesProxy | undefined;
103103
if (options.clientCertificates?.length) {
104-
clientCertificatesProxy = await progress.raceWithCleanup(ClientCertificatesProxy.create(options), proxy => proxy.close());
104+
clientCertificatesProxy = await progress.raceWithCleanup(ClientCertificatesProxy.create(options, this.attribution.browserType?.loopback(this.attribution.browser?.options.channel
105+
)), proxy => proxy.close());
105106
options = { ...options };
106107
options.proxyOverride = clientCertificatesProxy.proxySettings();
107108
options.internalIgnoreHTTPSErrors = true;

packages/playwright-core/src/server/browserType.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export abstract class BrowserType extends SdkObject {
8080
// Note: Any initial TLS requests will fail since we rely on the Page/Frames initialize which sets ignoreHTTPSErrors.
8181
let clientCertificatesProxy: ClientCertificatesProxy | undefined;
8282
if (options.clientCertificates?.length) {
83-
clientCertificatesProxy = await progress.raceWithCleanup(ClientCertificatesProxy.create(options), proxy => proxy.close());
83+
clientCertificatesProxy = await progress.raceWithCleanup(ClientCertificatesProxy.create(options, this.loopback(launchOptions.channel)), proxy => proxy.close());
8484
launchOptions.proxyOverride = clientCertificatesProxy.proxySettings();
8585
options = { ...options };
8686
options.internalIgnoreHTTPSErrors = true;
@@ -133,6 +133,7 @@ export abstract class BrowserType extends SdkObject {
133133
copyTestHooks(options, browserOptions);
134134
const browser = await progress.race(this.connectToTransport(transport, browserOptions, browserLogsCollector));
135135
(browser as any)._userDataDirForTest = userDataDir;
136+
browser.attribution.browserType = this;
136137
// We assume no control when using custom arguments, and do not prepare the default context in that case.
137138
if (persistent && !options.ignoreAllDefaultArgs)
138139
await browser._defaultContext!._loadDefaultContext(progress);
@@ -350,6 +351,7 @@ export abstract class BrowserType extends SdkObject {
350351
abstract amendEnvironment(env: Env, userDataDir: string, executable: string, browserArguments: string[], channel?: string): Env;
351352
abstract doRewriteStartupLog(error: ProtocolError): ProtocolError;
352353
abstract attemptToGracefullyCloseBrowser(transport: ConnectionTransport): void;
354+
abstract loopback(channel: string | undefined): string | undefined;
353355
}
354356

355357
function copyTestHooks(from: object, to: object) {

packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,20 +238,23 @@ class SocksProxyConnection {
238238

239239
export class ClientCertificatesProxy {
240240
_socksProxy: SocksProxy;
241+
_loopback: string;
241242
private _connections: Map<string, SocksProxyConnection> = new Map();
242243
ignoreHTTPSErrors: boolean | undefined;
243244
secureContextMap: Map<string, tls.SecureContext> = new Map();
244245
alpnCache: ALPNCache;
245246
proxyAgentFromOptions: ReturnType<typeof createProxyAgent>;
246247

247248
private constructor(
248-
contextOptions: Pick<types.BrowserContextOptions, 'clientCertificates' | 'ignoreHTTPSErrors' | 'proxy'>
249+
contextOptions: Pick<types.BrowserContextOptions, 'clientCertificates' | 'ignoreHTTPSErrors' | 'proxy'>,
250+
loopback: string | undefined
249251
) {
250252
verifyClientCertificates(contextOptions.clientCertificates);
251253
this.alpnCache = new ALPNCache();
252254
this.ignoreHTTPSErrors = contextOptions.ignoreHTTPSErrors;
253255
this.proxyAgentFromOptions = createProxyAgent(contextOptions.proxy);
254256
this._initSecureContexts(contextOptions.clientCertificates);
257+
this._loopback = loopback ?? '127.0.0.1';
255258
this._socksProxy = new SocksProxy();
256259
this._socksProxy.setPattern('*');
257260
this._socksProxy.addListener(SocksProxy.Events.SocksRequested, async (payload: SocksSocketRequestedPayload) => {
@@ -294,14 +297,14 @@ export class ClientCertificatesProxy {
294297
}
295298
}
296299

297-
public static async create(contextOptions: Pick<types.BrowserContextOptions, 'clientCertificates' | 'ignoreHTTPSErrors' | 'proxy'>) {
298-
const proxy = new ClientCertificatesProxy(contextOptions);
299-
await proxy._socksProxy.listen(0, '127.0.0.1');
300+
public static async create(contextOptions: Pick<types.BrowserContextOptions, 'clientCertificates' | 'ignoreHTTPSErrors' | 'proxy'>, loopback: string | undefined) {
301+
const proxy = new ClientCertificatesProxy(contextOptions, loopback);
302+
await proxy._socksProxy.listen(0);
300303
return proxy;
301304
}
302305

303306
public proxySettings(): types.ProxySettings {
304-
return { server: `socks5://127.0.0.1:${this._socksProxy.port()}` };
307+
return { server: `socks5://${this._loopback}:${this._socksProxy.port()}` };
305308
}
306309

307310
public async close() {

packages/playwright-core/src/server/webkit/webkit.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { spawnSync } from 'child_process';
18+
import { execSync, spawnSync } from 'child_process';
1919

2020
import { kBrowserCloseMessageId } from './wkConnection';
2121
import { wrapInASCIIBox } from '../utils/ascii';
@@ -96,6 +96,12 @@ export class WebKit extends BrowserType {
9696
webkitArguments.push('about:blank');
9797
return webkitArguments;
9898
}
99+
100+
loopback(channel: string): string | undefined {
101+
if (channel === 'webkit-wsl' && execSync('wsl -d playwright --cd /home/pwuser wslinfo --networking-mode').includes('nat'))
102+
return execSync('wsl -d playwright --cd /home/pwuser ip route show', { encoding: 'utf8' }).trim().split('\n').find(line => line.includes('default'))?.split(' ')[2];
103+
return undefined;
104+
}
99105
}
100106

101107
export function translatePathToWSL(path: string): string {

tests/library/browsercontext-cookies-third-party.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ test(`add 'Partitioned;' cookie via API`, async ({ page, context, browserName, h
323323
{
324324
name: 'top-level-partitioned',
325325
value: 'value',
326-
domain: 'localhost',
326+
domain: new URL(httpsServer.EMPTY_PAGE).hostname,
327327
path: '/',
328328
expires: -1,
329329
httpOnly: false,
@@ -335,7 +335,7 @@ test(`add 'Partitioned;' cookie via API`, async ({ page, context, browserName, h
335335
{
336336
name: 'top-level-non-partitioned',
337337
value: 'value',
338-
domain: 'localhost',
338+
domain: new URL(httpsServer.EMPTY_PAGE).hostname,
339339
path: '/',
340340
expires: -1,
341341
httpOnly: false,
@@ -345,7 +345,7 @@ test(`add 'Partitioned;' cookie via API`, async ({ page, context, browserName, h
345345
{
346346
name: 'frame-partitioned',
347347
value: 'value',
348-
domain: 'localhost',
348+
domain: new URL(httpsServer.EMPTY_PAGE).hostname,
349349
path: '/',
350350
expires: -1,
351351
httpOnly: false,
@@ -357,7 +357,7 @@ test(`add 'Partitioned;' cookie via API`, async ({ page, context, browserName, h
357357
{
358358
name: 'frame-non-partitioned',
359359
value: 'value',
360-
domain: 'localhost',
360+
domain: new URL(httpsServer.EMPTY_PAGE).hostname,
361361
path: '/',
362362
expires: -1,
363363
httpOnly: false,

0 commit comments

Comments
 (0)