From 31b037891bf8a5625d5bd6818fa25cb9f33995a3 Mon Sep 17 00:00:00 2001 From: Josep Boix Date: Fri, 3 May 2024 14:11:03 +0200 Subject: [PATCH] fix: prevent error for root shadow elements when restorEl is enabled (#8679) 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) => {