Handle null document body
This commit is contained in:
parent
69eb447c28
commit
6999490a60
|
@ -99,8 +99,12 @@ const ContentScript = new function() {
|
||||||
if (window.document.body)
|
if (window.document.body)
|
||||||
observer.observe((href.search("^https?:") == -1) ? window.document : window.document.body
|
observer.observe((href.search("^https?:") == -1) ? window.document : window.document.body
|
||||||
, { subtree: true, childList: true});
|
, { subtree: true, childList: true});
|
||||||
else
|
else if (window.document.documentElement) {
|
||||||
docObserver.observe(window.document.documentElement, { childList: true});
|
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() {
|
setTimeout( function() {
|
||||||
|
@ -146,10 +150,14 @@ const ContentScript = new function() {
|
||||||
|
|
||||||
function handleDocument()
|
function handleDocument()
|
||||||
{
|
{
|
||||||
var nodes = handleNodesDeep(window.document.body || window.document.documentElement);
|
var body = (window.document.body || window.document.documentElement);
|
||||||
var frames = (window.document.body || window.document.documentElement).querySelectorAll(frameSelector);
|
if (body) {
|
||||||
|
var nodes = handleNodesDeep(body);
|
||||||
|
var frames = body.querySelectorAll(frameSelector);
|
||||||
if (frames.length) handleFrames(frames);
|
if (frames.length) handleFrames(frames);
|
||||||
return nodes;
|
return nodes;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
function handleNodes(nodes, delayed)
|
function handleNodes(nodes, delayed)
|
||||||
|
@ -188,6 +196,8 @@ const ContentScript = new function() {
|
||||||
|
|
||||||
function handleNodesDeep(node, match)
|
function handleNodesDeep(node, match)
|
||||||
{
|
{
|
||||||
|
if (!node) return null;
|
||||||
|
|
||||||
var nodes = match && (node.matches(selector) || node.shadowRoot) ? [node] : [];
|
var nodes = match && (node.matches(selector) || node.shadowRoot) ? [node] : [];
|
||||||
var count = nodes.push(...node.querySelectorAll(selector));
|
var count = nodes.push(...node.querySelectorAll(selector));
|
||||||
for (var el of nodes.filter((a) => a.shadowRoot)) {
|
for (var el of nodes.filter((a) => a.shadowRoot)) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user