Skip to content

Commit

Permalink
cherry-pick(microsoft#11481): fix(webkit): improve orientation detection
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored and aslushnikov committed Jan 19, 2022
1 parent ab2643c commit ff7b9ad
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/playwright-core/src/server/webkit/wkPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions tests/assets/modernizr.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions tests/assets/modernizr/mobile-safari-14-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@
"promises": true,
"es6string": true,
"devicemotion": true,
"devicemotion2": true,
"deviceorientation": true,
"deviceorientation2": true,
"deviceorientation3": true,
"filereader": true,
"urlparser": true,
"urlsearchparams": true,
Expand Down
3 changes: 3 additions & 0 deletions tests/assets/modernizr/safari-14-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@
"promises": true,
"es6string": true,
"devicemotion": false,
"devicemotion2": false,
"deviceorientation": false,
"deviceorientation2": false,
"deviceorientation3": false,
"filereader": true,
"urlparser": true,
"urlsearchparams": true,
Expand Down

0 comments on commit ff7b9ad

Please sign in to comment.