Skip to content

Commit

Permalink
πŸ› [Amp story] Catch ScreenOrientation.lock promise (#35767)
Browse files Browse the repository at this point in the history
* Catch for promise.

* Update comment.

* Send e.
  • Loading branch information
processprocess committed Aug 26, 2021
1 parent f60679c commit e1edbde
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions extensions/amp-story/1.0/amp-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -948,8 +948,18 @@ export class AmpStory extends AMP.BaseElement {
return;
}

const orientationWarning = (e) =>
dev().warn(TAG, 'Failed to lock screen orientation:', e.message);

// Returns a promise.
const lockOrientationPromise = screen.orientation?.lock;
if (lockOrientationPromise) {
lockOrientationPromise('portrait').catch(orientationWarning);
return;
}

// Returns boolean or undefined.
const lockOrientation =
screen.orientation?.lock ||
screen.lockOrientation ||
screen.mozLockOrientation ||
screen.msLockOrientation ||
Expand All @@ -958,7 +968,7 @@ export class AmpStory extends AMP.BaseElement {
try {
lockOrientation('portrait');
} catch (e) {
dev().warn(TAG, 'Failed to lock screen orientation:', e.message);
orientationWarning(e);
}
}

Expand Down

0 comments on commit e1edbde

Please sign in to comment.