Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add an option to suppress out of dom warning #7808

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/js/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,18 @@ function videojs(id, options, ready) {
throw new TypeError('The element or ID supplied is not valid. (videojs)');
}

options = options || {};

// document.body.contains(el) will only check if el is contained within that one document.
// This causes problems for elements in iframes.
// Instead, use the element's ownerDocument instead of the global document.
// This will make sure that the element is indeed in the dom of that document.
// Additionally, check that the document in question has a default view.
// If the document is no longer attached to the dom, the defaultView of the document will be null.
if (!el.ownerDocument.defaultView || !el.ownerDocument.body.contains(el)) {
if ((!el.ownerDocument.defaultView || !el.ownerDocument.body.contains(el)) && !options.noWarnOutOfDom) {
log.warn('The element supplied is not included in the DOM');
}

options = options || {};

// 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) {
Expand Down
7 changes: 7 additions & 0 deletions test/unit/video.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ QUnit.test(
videojs('test_vid_id2');
assert.equal(warnLogs.length, 1, 'did not log another warning');

const vid3 = document.createElement('video');

videojs(vid3, {
noWarnOutOfDom: true
});
assert.equal(warnLogs.length, 1, 'did not log another warning');

log.warn = origWarnLog;
}
);
Expand Down