Skip to content

Commit

Permalink
fix: prevent error for root shadow elements when restorEl is enabled (#…
Browse files Browse the repository at this point in the history
…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`.
  • Loading branch information
jboix authored May 3, 2024
1 parent 992af3b commit 31b0378
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/js/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 31b0378

Please sign in to comment.