From 9d247b2154b4a9b0a42c606ff07e0593f8e922af Mon Sep 17 00:00:00 2001 From: t4y3 Date: Fri, 8 Nov 2024 12:14:31 +0900 Subject: [PATCH] fix: use globalThis.window for inBrowser conditions --- .eslintrc.json | 5 ++++- player/js/module.js | 2 +- player/js/modules/main.js | 2 +- rollup.config.js | 2 +- tasks/build.js | 2 +- tasks/build_worker.js | 2 +- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 8c7c96f5a..610bdbd8f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -26,7 +26,7 @@ "exports": "always-multiline", "functions": "never" }], - + "no-restricted-properties": "off", "prefer-spread": "off", "no-restricted-globals": "off", @@ -42,5 +42,8 @@ "vars-on-top": "off", "no-use-before-define": "off", "-------": "off" + }, + "globals": { + "globalThis": "readonly" } } diff --git a/player/js/module.js b/player/js/module.js index 7526c8e13..f671b9d1a 100644 --- a/player/js/module.js +++ b/player/js/module.js @@ -67,7 +67,7 @@ function setQuality(value) { } function inBrowser() { - return typeof navigator !== 'undefined'; + return globalThis.window === globalThis && typeof globalThis.document !== 'undefined'; } function installPlugin(type, plugin) { diff --git a/player/js/modules/main.js b/player/js/modules/main.js index 3f420629a..b46821e61 100644 --- a/player/js/modules/main.js +++ b/player/js/modules/main.js @@ -69,7 +69,7 @@ function setQuality(value) { } function inBrowser() { - return typeof navigator !== 'undefined'; + return globalThis.window === globalThis && typeof globalThis.document !== 'undefined'; } function installPlugin(type, plugin) { diff --git a/rollup.config.js b/rollup.config.js index 0d7ad02a2..a19dbd157 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -16,7 +16,7 @@ const addNavigatorValidation = (options = {}) => { return { name: 'inject-version', renderChunk: (code) => { - return '(typeof navigator !== "undefined") && ' + code + return '(globalThis.window === globalThis && typeof globalThis.document !== "undefined") && ' + code }, } } diff --git a/tasks/build.js b/tasks/build.js index 3cef2eb15..7917b868b 100644 --- a/tasks/build.js +++ b/tasks/build.js @@ -604,7 +604,7 @@ function uglifyCode(code) { async function modularizeCode(code, build) { const globalScope = (build =='canvas_worker' || build =='lottie_worker') ? 'self' : 'window' - return `(typeof navigator !== "undefined") && (function(root, factory) { + return `(globalThis.window === globalThis && typeof globalThis.document !== "undefined") && (function(root, factory) { if (typeof define === "function" && define.amd) { define(function() { return factory(root); diff --git a/tasks/build_worker.js b/tasks/build_worker.js index c11a3bfb0..c2a6a5ee3 100644 --- a/tasks/build_worker.js +++ b/tasks/build_worker.js @@ -52,7 +52,7 @@ function uglifyCode(code) { async function modularizeCode(code, build) { const globalScope = (build =='canvas_worker' || build =='lottie_worker') ? 'self' : 'window' - return `(typeof navigator !== "undefined") && (function(root, factory) { + return `(globalThis.window === globalThis && typeof globalThis.document !== "undefined") && (function(root, factory) { if (typeof define === "function" && define.amd) { define(function() { return factory(root);