Handle null document body
This commit is contained in:
parent
69eb447c28
commit
6999490a60
|
@ -99,10 +99,14 @@ const ContentScript = new function() {
|
|||
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});
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
// workaround for chrome no events on blank iframe ...
|
||||
// workaround for chrome no events on blank iframe ...
|
||||
setTimeout( function() {
|
||||
window.addEventListener("mousedown", onContextMenu, true);
|
||||
["mousedown","click"].forEach((a) => window.addEventListener(a, function(e) {
|
||||
|
@ -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)
|
||||
|
@ -188,6 +196,8 @@ 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)) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user