Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use globalThis.window for inBrowser conditions #3129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"exports": "always-multiline",
"functions": "never"
}],

"no-restricted-properties": "off",
"prefer-spread": "off",
"no-restricted-globals": "off",
Expand All @@ -42,5 +42,8 @@
"vars-on-top": "off",
"no-use-before-define": "off",
"-------": "off"
},
"globals": {
"globalThis": "readonly"
}
}
2 changes: 1 addition & 1 deletion player/js/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion player/js/modules/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tasks/build_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down