diff --git a/aem-chrome-plugin--adaptive-form--content-script.js b/aem-chrome-plugin--adaptive-form--content-script.js index cc1e06b..a76aecb 100644 --- a/aem-chrome-plugin--adaptive-form--content-script.js +++ b/aem-chrome-plugin--adaptive-form--content-script.js @@ -18,15 +18,19 @@ * #L% */ -(function(){ - var s = document.createElement('script'); - s.src = chrome.extension.getURL('aem-chrome-plugin--adaptive-form--custom-script.js'); - (document.head || document.documentElement).appendChild(s); +try { + (function(){ + var s = document.createElement('script'); + s.src = chrome.extension.getURL('aem-chrome-plugin--adaptive-form--custom-script.js'); + (document.head || document.documentElement).appendChild(s); - window.addEventListener('af-editor-loaded.afPlugin', function () { - chrome.runtime.sendMessage({url: window.location.href, action: "af-editor-loaded"}, function (response) { - // Reduce console.log clutter - // console.log(response); + window.addEventListener('af-editor-loaded.afPlugin', function () { + chrome.runtime.sendMessage({url: window.location.href, action: "af-editor-loaded"}, function (response) { + // Reduce console.log clutter + // console.log(response); + }); }); - }); -})(); + })(); +} catch(err) { + // Do not bother user if an error occurs, as this is loaded everywhere. +} \ No newline at end of file diff --git a/aem-chrome-plugin--adaptive-form--custom-script.js b/aem-chrome-plugin--adaptive-form--custom-script.js index 150ab17..48f6c6b 100644 --- a/aem-chrome-plugin--adaptive-form--custom-script.js +++ b/aem-chrome-plugin--adaptive-form--custom-script.js @@ -34,12 +34,16 @@ document.addEventListener("DOMContentLoaded", function () { * So, we set a flag (editorFrameLoaded) on window. In authorUtils, we evaluate this flag * on the console and display the authoring frame. */ - if(window.jQuery) { - $(document).on("cq-editor-loaded", function () { - window.editorFrameLoaded = true; - window.dispatchEvent(new Event('af-editor-loaded.afPlugin')); - addAuthoringUtils(); - }); + try { + if ($) { + $(document).on("cq-editor-loaded", function () { + window.editorFrameLoaded = true; + window.dispatchEvent(new Event('af-editor-loaded.afPlugin')); + addAuthoringUtils(); + }); + } + } catch(err) { + // Do not bother user with errors as this script can be injected in unexpected contexts (though we try not to). } });