Handle null document body

This commit is contained in:
Michael Campagnaro 2021-03-10 17:27:34 -05:00
parent 69eb447c28
commit 6999490a60

View File

@ -95,15 +95,19 @@ const ContentScript = new function() {
}
}
});
if (window.document.body)
if (window.document.body)
observer.observe((href.search("^https?:") == -1) ? window.document : window.document.body
, { subtree: true, childList: true});
else
else if (window.document.documentElement) {
docObserver.observe(window.document.documentElement, { childList: true});
// workaround for chrome no events on blank iframe ...
setTimeout( function() {
}
else {
return;
}
// workaround for chrome no events on blank iframe ...
setTimeout( function() {
window.addEventListener("mousedown", onContextMenu, true);
["mousedown","click"].forEach((a) => window.addEventListener(a, function(e) {
if (e.isTrusted && e.button == 0) {
@ -146,10 +150,14 @@ const ContentScript = new function() {
function handleDocument()
{
var nodes = handleNodesDeep(window.document.body || window.document.documentElement);
var frames = (window.document.body || window.document.documentElement).querySelectorAll(frameSelector);
if (frames.length) handleFrames(frames);
return nodes;
var body = (window.document.body || window.document.documentElement);
if (body) {
var nodes = handleNodesDeep(body);
var frames = body.querySelectorAll(frameSelector);
if (frames.length) handleFrames(frames);
return nodes;
}
return null;
};
function handleNodes(nodes, delayed)
@ -185,9 +193,11 @@ const ContentScript = new function() {
};
});
};
function handleNodesDeep(node, match)
{
if (!node) return null;
var nodes = match && (node.matches(selector) || node.shadowRoot) ? [node] : [];
var count = nodes.push(...node.querySelectorAll(selector));
for (var el of nodes.filter((a) => a.shadowRoot)) {