From 8c8f7e460581b36b512f58dffdd0acbf4345617e Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 9 Sep 2019 18:11:27 +0200 Subject: [PATCH] Fix 'document' not defined in the worker context --- www/common/notify.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/www/common/notify.js b/www/common/notify.js index 5b49de991..101bae6ee 100644 --- a/www/common/notify.js +++ b/www/common/notify.js @@ -4,6 +4,7 @@ define(['/api/config'], function (ApiConfig) { var DEFAULT_MAIN = '/customize/main-favicon.png?' + ApiConfig.requireConf.urlArgs; var DEFAULT_ALT = '/customize/alt-favicon.png?' + ApiConfig.requireConf.urlArgs; + var document = window.document; var isSupported = Module.isSupported = function () { return typeof(window.Notification) === 'function' && window.location.protocol === 'https:'; @@ -22,7 +23,7 @@ define(['/api/config'], function (ApiConfig) { }; var create = Module.create = function (msg, title, icon) { - if (!icon) { + if (document && !icon) { var favicon = document.getElementById('favicon'); icon = favicon.getAttribute('data-main-favicon') || DEFAULT_MAIN; } @@ -52,6 +53,9 @@ define(['/api/config'], function (ApiConfig) { }; var createFavicon = function () { + if (!document) { + return void console.error('document is not available in this context'); + } console.debug("creating favicon"); var fav = document.createElement('link'); var attrs = { @@ -68,9 +72,12 @@ define(['/api/config'], function (ApiConfig) { document.head.appendChild(fav); }; - if (!document.getElementById('favicon')) { createFavicon(); } + if (document && !document.getElementById('favicon')) { createFavicon(); } Module.tab = function (frequency, count) { + if (!document) { + return void console.error('document is not available in this context'); + } var key = '_pendingTabNotification'; var favicon = document.getElementById('favicon');