Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

feat(webkit): match Safari for device orientation, motion and push (#41660)

Yury Semikhatsky6f3cce9ab58d
diff --git a/packages/playwright-core/src/server/webkit/wkPage.ts b/packages/playwright-core/src/server/webkit/wkPage.ts
index dcc17c8b14..06ceb0ac28 100644
--- a/packages/playwright-core/src/server/webkit/wkPage.ts
+++ b/packages/playwright-core/src/server/webkit/wkPage.ts
@@ -215,13 +215,13 @@ export class WKPage implements PageDelegate {
}
if (this._page.fileChooserIntercepted())
promises.push(session.send('Page.setInterceptFileChooserDialog', { enabled: true }));
- promises.push(session.send('Page.overrideSetting', { setting: 'DeviceOrientationEventEnabled', value: contextOptions.isMobile }));
promises.push(session.send('Page.overrideSetting', { setting: 'FullScreenEnabled', value: !contextOptions.isMobile }));
promises.push(session.send('Page.overrideSetting', { setting: 'NotificationsEnabled', value: !contextOptions.isMobile }));
promises.push(session.send('Page.overrideSetting', { setting: 'PointerLockEnabled', value: !contextOptions.isMobile }));
promises.push(session.send('Page.overrideSetting', { setting: 'InputTypeMonthEnabled', value: contextOptions.isMobile }));
promises.push(session.send('Page.overrideSetting', { setting: 'InputTypeWeekEnabled', value: contextOptions.isMobile }));
promises.push(session.send('Page.overrideSetting', { setting: 'FixedBackgroundsPaintRelativeToDocument', value: contextOptions.isMobile }));
+ promises.push(session.send('Page.overrideSetting', { setting: 'PushAPIEnabled', value: !contextOptions.isMobile }));
await Promise.all(promises);
}
@@ -795,11 +795,8 @@ export class WKPage implements PageDelegate {
private _calculateBootstrapScript(): string {
const scripts: string[] = [];
- if (!this._page.browserContext._options.isMobile) {
+ if (!this._page.browserContext._options.isMobile)
scripts.push('delete window.orientation');
- scripts.push('delete window.ondevicemotion');
- scripts.push('delete window.ondeviceorientation');
- }
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());
diff --git a/tests/assets/modernizr/mobile-safari-18.json b/tests/assets/modernizr/mobile-safari-26.json
similarity index 99%
rename from tests/assets/modernizr/mobile-safari-18.json
rename to tests/assets/modernizr/mobile-safari-26.json
index cff9199bb2..57aaebc27f 100644
--- a/tests/assets/modernizr/mobile-safari-18.json
+++ b/tests/assets/modernizr/mobile-safari-26.json
@@ -17,7 +17,7 @@
"ambientlight": false,
"applicationcache": false,
"audio": {
- "ogg": "",
+ "ogg": "probably",
"mp3": "probably",
"opus": "probably",
"wav": "probably",
@@ -103,7 +103,7 @@
"flexwrap": true,
"focusvisible": true,
"focuswithin": true,
- "fontdisplay": false,
+ "fontdisplay": true,
"fontface": true,
"generatedcontent": true,
"cssgradients": true,
diff --git a/tests/assets/modernizr/safari-18.json b/tests/assets/modernizr/safari-26.json
similarity index 99%
rename from tests/assets/modernizr/safari-18.json
rename to tests/assets/modernizr/safari-26.json
index 508a4fa977..4bbfa95d16 100644
--- a/tests/assets/modernizr/safari-18.json
+++ b/tests/assets/modernizr/safari-26.json
@@ -17,7 +17,7 @@
"ambientlight": false,
"applicationcache": false,
"audio": {
- "ogg": "",
+ "ogg": "probably",
"mp3": "probably",
"opus": "probably",
"wav": "probably",
@@ -103,7 +103,7 @@
"flexwrap": true,
"focusvisible": true,
"focuswithin": true,
- "fontdisplay": false,
+ "fontdisplay": true,
"fontface": true,
"generatedcontent": true,
"cssgradients": true,
@@ -342,7 +342,7 @@
"webm": "probably",
"vp9": "probably",
"hls": "probably",
- "av1": ""
+ "av1": "probably"
},
"videocrossorigin": true,
"videoloop": true,
diff --git a/tests/library/modernizr.spec.ts b/tests/library/modernizr.spec.ts
index 9a3bdc65d0..e8aec532bc 100644
--- a/tests/library/modernizr.spec.ts
+++ b/tests/library/modernizr.spec.ts
@@ -40,11 +40,12 @@ it('Safari Desktop', async ({ browser, browserName, platform, httpsServer, chann
deviceScaleFactor: 2,
ignoreHTTPSErrors: true,
});
- const { actual, expected } = await checkFeatures('safari-18', context, httpsServer);
+ const { actual, expected } = await checkFeatures('safari-26', context, httpsServer);
- expected.pushmanager = false;
- expected.devicemotion2 = false;
- expected.deviceorientation3 = false;
+ // Shipping Safari exposes `font-display` as a settable CSS property (element.style.fontDisplay === ''),
+ // but open-source WebKit keeps it a @font-face descriptor only, so it is undefined here. No runtime
+ // flag bridges the gap, hence the override.
+ expected.fontdisplay = false;
delete expected.webglextensions;
delete actual.webglextensions;
@@ -96,7 +97,7 @@ it('Mobile Safari', async ({ playwright, browser, browserName, platform, httpsSe
...iPhone,
ignoreHTTPSErrors: true,
});
- const { actual, expected } = await checkFeatures('mobile-safari-18', context, httpsServer);
+ const { actual, expected } = await checkFeatures('mobile-safari-26', context, httpsServer);
{
// All platforms.
@@ -108,6 +109,11 @@ it('Mobile Safari', async ({ playwright, browser, browserName, platform, httpsSe
expected.mediasource = true;
expected.scrolltooptions = false;
+ // Shipping Safari exposes `font-display` as a settable CSS property (element.style.fontDisplay === ''),
+ // but open-source WebKit keeps it a @font-face descriptor only, so it is undefined here. No runtime
+ // flag bridges the gap, hence the override.
+ expected.fontdisplay = false;
+
delete expected.webglextensions;
delete actual.webglextensions;
expected.audio = !!expected.audio;