Skip to content

Commit

Permalink
#40 - Avoid cluttering the console on AEM Plugin errors when its invo…
Browse files Browse the repository at this point in the history
…ked on non-candidate pages
  • Loading branch information
davidjgonzalez committed May 25, 2017
1 parent 581fd99 commit 1b0b32e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
24 changes: 14 additions & 10 deletions aem-chrome-plugin--adaptive-form--content-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
16 changes: 10 additions & 6 deletions aem-chrome-plugin--adaptive-form--custom-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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).
}
});

Expand Down

0 comments on commit 1b0b32e

Please sign in to comment.