From 68f1429d9baafac99a9d2a16be70f21097f02fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <34163393+amtins@users.noreply.github.com> Date: Wed, 27 Sep 2023 10:18:58 +0200 Subject: [PATCH] fix(error): chromium reset mediaError when the poster is invalid (#8410) When both the media URL and the poster return a response other than 200. The media error is overwritten by an empty error, leaving the player in an inconsistent state. - add a condition to `handleTechError_` to ensure that the `error` is truthy - add a test case Fixes #8409 --- src/js/player.js | 4 +++- test/unit/player.test.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/js/player.js b/src/js/player.js index 83272e1d74..826c1b3ab0 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -2160,7 +2160,9 @@ class Player extends Component { handleTechError_() { const error = this.tech_.error(); - this.error(error); + if (error) { + this.error(error); + } } /** diff --git a/test/unit/player.test.js b/test/unit/player.test.js index 25d0048bf2..3b77360594 100644 --- a/test/unit/player.test.js +++ b/test/unit/player.test.js @@ -3383,3 +3383,37 @@ QUnit.test('crossOrigin value should be maintained after loadMedia is called', f playerExample2.dispose(); playerExample3.dispose(); }); + +QUnit.test('should not reset the error when the tech triggers an error that is null', function(assert) { + sinon.stub(log, 'error'); + + const player = TestHelpers.makePlayer(); + + player.src({ + src: 'http://example.com/movie.unsupported-format', + type: 'video/unsupported-format' + }); + + this.clock.tick(60); + + // Simulates Chromium's behavior when the poster is invalid + + // is only there for context, but does nothing + player.poster('invalid'); + + const spyError = sinon.spy(player, 'error'); + // Chromium behavior produced by the video element + const errorStub = sinon.stub(player.tech(true), 'error').callsFake(() => null); + + player.tech(true).trigger('error'); + // End + + assert.ok(player.hasClass('vjs-error'), 'player has vjs-error class'); + assert.ok(spyError.notCalled, 'error was not called'); + assert.ok(player.error(), 'error is retained'); + + player.dispose(); + spyError.restore(); + errorStub.restore(); + log.error.restore(); +});