diff --git a/extensions/amp-story/1.0/amp-story.js b/extensions/amp-story/1.0/amp-story.js index fcff275413974..f7906ee7d4583 100644 --- a/extensions/amp-story/1.0/amp-story.js +++ b/extensions/amp-story/1.0/amp-story.js @@ -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 || @@ -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); } }