Skip to content

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

fix(webkit): improve orientation detection (#11481)

Pavel Feldmana65f7066d5e3
diff --git a/packages/playwright-core/src/server/webkit/wkPage.ts b/packages/playwright-core/src/server/webkit/wkPage.ts
index b5560a6472..f4e3f6c1cd 100644
--- a/packages/playwright-core/src/server/webkit/wkPage.ts
+++ b/packages/playwright-core/src/server/webkit/wkPage.ts
@@ -732,6 +732,11 @@ export class WKPage implements PageDelegate {
private _calculateBootstrapScript(): string {
const scripts: string[] = [];
+ if (!this._page.context()._options.isMobile) {
+ scripts.push('delete window.orientation');
+ scripts.push('delete window.ondevicemotion');
+ scripts.push('delete window.ondeviceorientation');
+ }
for (const binding of this._page.allBindings())
scripts.push(this._bindingToScript(binding));
scripts.push(...this._browserContext._evaluateOnNewDocumentSources);
diff --git a/tests/assets/modernizr.html b/tests/assets/modernizr.html
index 77981834bc..5096ffba74 100644
--- a/tests/assets/modernizr.html
+++ b/tests/assets/modernizr.html
@@ -10,6 +10,11 @@ for (const name in Modernizr) {
let value = Modernizr[name];
report[name] = value;
}
+
+report['devicemotion2'] = 'ondevicemotion' in window;
+report['deviceorientation2'] = 'orientation' in window;
+report['deviceorientation3'] = 'ondeviceorientation' in window;
+
document.body.style.whiteSpace = 'pre';
document.body.textContent = JSON.stringify(report, undefined, 4);
window.report = JSON.parse(document.body.textContent);
diff --git a/tests/assets/modernizr/mobile-safari-14-1.json b/tests/assets/modernizr/mobile-safari-14-1.json
index bb30a7dc4a..58fd04c6e6 100644
--- a/tests/assets/modernizr/mobile-safari-14-1.json
+++ b/tests/assets/modernizr/mobile-safari-14-1.json
@@ -90,7 +90,10 @@
"promises": true,
"es6string": true,
"devicemotion": true,
+ "devicemotion2": true,
"deviceorientation": true,
+ "deviceorientation2": true,
+ "deviceorientation3": true,
"filereader": true,
"urlparser": true,
"urlsearchparams": true,
diff --git a/tests/assets/modernizr/safari-14-1.json b/tests/assets/modernizr/safari-14-1.json
index 5cb80869a4..dde865a164 100644
--- a/tests/assets/modernizr/safari-14-1.json
+++ b/tests/assets/modernizr/safari-14-1.json
@@ -90,7 +90,10 @@
"promises": true,
"es6string": true,
"devicemotion": false,
+ "devicemotion2": false,
"deviceorientation": false,
+ "deviceorientation2": false,
+ "deviceorientation3": false,
"filereader": true,
"urlparser": true,
"urlsearchparams": true,