Skip to content

Commit

Permalink
Eliminate useless The play() request was interrupted by a call to pau…
Browse files Browse the repository at this point in the history
…se() errors from being logged (ampproject#6680)

* Eliminate useless The play() request was interrupted by a call to pause() errors from being logged

* Eliminate useless The play() request was interrupted by a call to pause() errors from being logged
  • Loading branch information
aghassemi authored and torch2424 committed Jan 3, 2017
1 parent 81130cc commit dd49f77
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
12 changes: 11 additions & 1 deletion builtins/amp-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,17 @@ export function installVideo(win) {
* @override
*/
play(unusedIsAutoplay) {
this.video_.play();
const ret = this.video_.play();

if (ret && ret.catch) {
ret.catch(() => {
// Empty catch to prevent useless unhandled promise rejection logging.
// Play can fail for many reasons such as video getting paused before
// play() is finished.
// We use events to know the state of the video and do not care about
// the success or failure of the play()'s returned promise.
});
}
}

/**
Expand Down
16 changes: 16 additions & 0 deletions test/functional/test-amp-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,22 @@ describe('amp-video', () => {
});
});

it('play() should not log promise rejections', () => {
const playPromise = Promise.reject('The play() request was interrupted');
const catchSpy = sandbox.spy(playPromise, 'catch');
return getVideo({
src: 'video.mp4',
width: 160,
height: 90,
}, null, function(element) {
const impl = element.implementation_;
sandbox.stub(impl.video_, 'play').returns(playPromise);
impl.play();
}).then(() => {
expect(catchSpy.called).to.be.true;
});
});

it('should propagate ARIA attributes', () => {
return getVideo({
src: 'video.mp4',
Expand Down

0 comments on commit dd49f77

Please sign in to comment.