From d9c43abed4dd4625ddde7c2a5943fed32db0a78f Mon Sep 17 00:00:00 2001 From: Josep Boix Requesens Date: Tue, 9 Apr 2024 17:47:44 +0200 Subject: [PATCH] fix: prevent error for root shadow elements when restorEl is enabled Addresses an issue where activating the `restoreEl` option for an element at the root of a shadow DOM threw a "TypeError: el.parentNode.hasAttribute is not a function". The bug was due to the `parentNode` being a shadow root, which does not have the `hasAttribute` method. The fix implemented checks for the existence of the `hasAttribute` method on `parentNode`. --- src/js/video.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/video.js b/src/js/video.js index ae0cf473d3..474c02103e 100644 --- a/src/js/video.js +++ b/src/js/video.js @@ -167,7 +167,7 @@ function videojs(id, options, ready) { // Store a copy of the el before modification, if it is to be restored in destroy() // If div ingest, store the parent div if (options.restoreEl === true) { - options.restoreEl = (el.parentNode && el.parentNode.hasAttribute('data-vjs-player') ? el.parentNode : el).cloneNode(true); + options.restoreEl = (el.parentNode && el.parentNode.hasAttribute && el.parentNode.hasAttribute('data-vjs-player') ? el.parentNode : el).cloneNode(true); } hooks('beforesetup').forEach((hookFunction) => {