aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-05-24 14:01:21 -0400
committerGitHub <noreply@github.com>2020-05-24 14:01:21 -0400
commit6dd6af05e1ed3e0da4091af073c38e1d8ec0268d (patch)
tree7262add632fac645ca0481abbb63efb3b8291bb8 /ext/mixed/js
parent3c4c82dcfc66a1b24a3df3d4b15283235c72cf66 (diff)
Update background global object usage (#556)
* Omit global window object for scripts used on the background page * Validate document exists before using * Remove dom.js from background.html
Diffstat (limited to 'ext/mixed/js')
-rw-r--r--ext/mixed/js/core.js20
1 files changed, 11 insertions, 9 deletions
diff --git a/ext/mixed/js/core.js b/ext/mixed/js/core.js
index 257c7edf..bf877e72 100644
--- a/ext/mixed/js/core.js
+++ b/ext/mixed/js/core.js
@@ -177,7 +177,7 @@ function promiseTimeout(delay, resolveValue) {
const complete = (callback, value) => {
if (callback === null) { return; }
if (timer !== null) {
- window.clearTimeout(timer);
+ clearTimeout(timer);
timer = null;
}
promiseResolve = null;
@@ -192,7 +192,7 @@ function promiseTimeout(delay, resolveValue) {
promiseResolve = resolve2;
promiseReject = reject2;
});
- timer = window.setTimeout(() => {
+ timer = setTimeout(() => {
timer = null;
resolve(resolveValue);
}, delay);
@@ -331,7 +331,7 @@ const yomichan = (() => {
generateId(length) {
const array = new Uint8Array(length);
- window.crypto.getRandomValues(array);
+ crypto.getRandomValues(array);
let id = '';
for (const value of array) {
id += value.toString(16).padStart(2, '0');
@@ -364,7 +364,7 @@ const yomichan = (() => {
const runtimeMessageCallback = ({action, params}, sender, sendResponse) => {
let timeoutId = null;
if (timeout !== null) {
- timeoutId = window.setTimeout(() => {
+ timeoutId = setTimeout(() => {
timeoutId = null;
eventHandler.removeListener(runtimeMessageCallback);
reject(new Error(`Listener timed out in ${timeout} ms`));
@@ -373,7 +373,7 @@ const yomichan = (() => {
const cleanupResolve = (value) => {
if (timeoutId !== null) {
- window.clearTimeout(timeoutId);
+ clearTimeout(timeoutId);
timeoutId = null;
}
eventHandler.removeListener(runtimeMessageCallback);
@@ -453,10 +453,12 @@ const yomichan = (() => {
// Private
+ _getUrl() {
+ return (typeof window === 'object' && window !== null ? window.location.href : '');
+ }
+
_getLogContext() {
- return {
- url: window.location.href
- };
+ return {url: this._getUrl()};
}
_onMessage({action, params}, sender, callback) {
@@ -469,7 +471,7 @@ const yomichan = (() => {
}
_onMessageGetUrl() {
- return {url: window.location.href};
+ return {url: this._getUrl()};
}
_onMessageOptionsUpdated({source}) {