Skip to content
Merged
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions packages/playwright-core/src/server/webkit/wkPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -781,10 +781,33 @@ export class WKPage implements PageDelegate {
}
scripts.push('if (!window.safari) window.safari = { pushNotification: { toString() { return "[object SafariRemoteNotification]"; } } };');
scripts.push('if (!window.GestureEvent) window.GestureEvent = function GestureEvent() {};');
scripts.push(this._publicKeyCredentialScript());
scripts.push(...this._page.allInitScripts().map(script => script.source));
return scripts.join(';\n');
}

private _publicKeyCredentialScript(): string {
function polyfill() {
/**
* Some sites don't check existance of PublicKeyCredentials because all browsers except Webkit on Linux implement it.
* We polyfill the subset that's used for feature detection, so that login flows that'd work in Safari don't crash with "PublicKeyCredential is not defined" in CI.
* https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredential
*/
window.PublicKeyCredential ??= {
async getClientCapabilities() {
return {};
},
async isConditionalMediationAvailable() {
return false;
},
async isUserVerifyingPlatformAuthenticatorAvailable() {
return false;
},
} as any;
}
return `(${polyfill.toString()})();`;
}

async _updateBootstrapScript(): Promise<void> {
await this._updateState('Page.setBootstrapScript', { source: this._calculateBootstrapScript() });
}
Expand Down
14 changes: 14 additions & 0 deletions tests/library/capabilities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,3 +480,17 @@ it('should not auto play audio', {
await page.goto('http://127.0.0.1/audio.html');
await expect(page.locator('#log')).toHaveText('State: suspended');
});

it('should not crash on feature detection for PublicKeyCredential', {
annotation: {
type: 'issue',
description: 'https://github.com/microsoft/playwright/issues/35433'
}
}, async ({ page, server }) => {
await page.goto(server.EMPTY_PAGE);
await page.evaluate(async () => {
await PublicKeyCredential.getClientCapabilities();
await PublicKeyCredential.isConditionalMediationAvailable();
await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable();
});
});
2 changes: 0 additions & 2 deletions tests/library/modernizr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ it('Safari Desktop', async ({ browser, browserName, platform, server, headless }

if (platform === 'linux') {
expected.speechrecognition = false;
expected.publickeycredential = false;
expected.mediastream = false;
if (headless)
expected.todataurlwebp = true;
Expand Down Expand Up @@ -118,7 +117,6 @@ it('Mobile Safari', async ({ playwright, browser, browserName, platform, server,

if (platform === 'linux') {
expected.speechrecognition = false;
expected.publickeycredential = false;
expected.mediastream = false;
if (headless)
expected.todataurlwebp = true;
Expand Down
Loading