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

Need to be able to set client certificates in browsers. #57

Open
teodesian opened this issue Apr 24, 2023 · 2 comments
Open

Need to be able to set client certificates in browsers. #57

teodesian opened this issue Apr 24, 2023 · 2 comments
Assignees

Comments

@teodesian
Copy link
Owner

microsoft/playwright#1799 (comment)

suggests there is indeed a way. The core problem I see is that you’d want the file read to get done in JS rather than passing bytes on from perl, as those tend to choke JSON encoders/decoders.

I’ll need a mechanism to hint playwright_server that it ought to read a particular file parameter.

@teodesian teodesian self-assigned this Apr 24, 2023
@kcaran
Copy link
Contributor

kcaran commented Aug 26, 2024

We use client certificates at my company, so I was able to take a look at this. I think you can close the issue.

Playwright version 1.46.0 handles client certificates natively. You can pass them in via the defineConfig configuration object or through the context declaration. I don't think we have access to defineConfig through playwright_server, but passing them through newContext worked fine for me.

my $host = 'https://my.host.com';
my $handle = Playwright->new();
my $browser = $handle->launch( headless => 0, type => 'chrome' );
my $context = $browser->newContext( {
	clientCertificates => [{
		origin => $host,
		certPath => '/Users/caran/cert/myclientcert.crt',
		keyPath => '/Users/caran/cert/myprivatekey.pem',
		passphrase => 'thepassphrase'
	}] } );

my $page = $context->newPage();
$page->goto($host, { waitUntil => 'networkidle' });

On MacOS, I did have some issues with .pfx files but splitting up the certificate and passing both parts works fine.

@teodesian
Copy link
Owner Author

that's great! I'll add this into example.pl so others don't have to look hard for it, and make a note in the POD.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants