From ff7b9ad685e9dd1a02a4f2b5d23aa45b64a111a2 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Wed, 19 Jan 2022 10:07:38 -0800 Subject: [PATCH] cherry-pick(#11481): fix(webkit): improve orientation detection --- packages/playwright-core/src/server/webkit/wkPage.ts | 5 +++++ tests/assets/modernizr.html | 5 +++++ tests/assets/modernizr/mobile-safari-14-1.json | 3 +++ tests/assets/modernizr/safari-14-1.json | 3 +++ 4 files changed, 16 insertions(+) diff --git a/packages/playwright-core/src/server/webkit/wkPage.ts b/packages/playwright-core/src/server/webkit/wkPage.ts index 635ed59b9f0b4..45c20dff4f5a9 100644 --- a/packages/playwright-core/src/server/webkit/wkPage.ts +++ b/packages/playwright-core/src/server/webkit/wkPage.ts @@ -728,6 +728,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 77981834bc3fe..5096ffba74789 100644 --- a/tests/assets/modernizr.html +++ b/tests/assets/modernizr.html @@ -10,6 +10,11 @@ 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 bb30a7dc4add4..58fd04c6e6730 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 5cb80869a42a0..dde865a164caa 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,