From 4d0536b1a484c9ccfc763eade30641a04269667f Mon Sep 17 00:00:00 2001 From: sparks-alec Date: Mon, 7 Feb 2022 02:12:52 -0500 Subject: [PATCH] Update view.js --- src/view.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/view.js b/src/view.js index 6eda9eb..45cdf6f 100644 --- a/src/view.js +++ b/src/view.js @@ -90,11 +90,12 @@ generateBodyHTML = function(d){ module.exports.draw = function (device) { - let $deviceDrawArea = document.getElementById(`device-${device.id}-draw-area`).contentWindow.document; + + let $deviceDrawArea = document.getElementById(`device-${device.id}-draw-area`); if($deviceDrawArea){ - const scriptEl = $deviceDrawArea.createRange().createContextualFragment(generateBodyHTML(device)); - $deviceDrawArea.body.replaceChildren(scriptEl); + const scriptEl = $deviceDrawArea.contentWindow.document.createRange().createContextualFragment(generateBodyHTML(device)); + $deviceDrawArea.contentWindow.document.body.replaceChildren(scriptEl); }else{ @@ -107,8 +108,11 @@ module.exports.draw = function (device) { }; module.exports.update = function(device, type, data){ - let doc = document.getElementById(`device-${device.id}-draw-area`).contentWindow.document; - PLUGINS.all[device.type].update(device, doc, type, data); + let doc = document.getElementById(`device-${device.id}-draw-area`); + if(doc){ + PLUGINS.all[device.type].update(device, doc.contentWindow.document, type, data); + } + }