Skip to content

Commit

Permalink
Added worker environment (#6108)
Browse files Browse the repository at this point in the history
  • Loading branch information
marklundin authored Mar 5, 2024
1 parent 7bf416b commit 7d56fe9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/core/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const detectPassiveEvents = () => {
};

const ua = (typeof navigator !== 'undefined') ? navigator.userAgent : '';
const environment = (typeof window !== 'undefined') ? 'browser' : 'node';
const environment = typeof window !== 'undefined' ? 'browser' :
typeof global !== 'undefined' ? 'node' : 'worker';

// detect platform
const platformName =
Expand Down Expand Up @@ -62,19 +63,22 @@ const platform = {
name: platformName,

/**
* String identifying the current runtime environment. Either 'browser' or 'node'.
* String identifying the current runtime environment. Either 'browser', 'node' or 'worker'.
*
* @type {'browser' | 'node'}
* @type {'browser' | 'node' | 'worker'}
*/
environment: environment,

/**
* The global object. This will be the window object when running in a browser and the global
* object when running in nodejs.
* object when running in nodejs and self when running in a worker.
*
* @type {object}
*/
global: (environment === 'browser') ? window : global,
global: globalThis ??
(environment === 'browser' && window) ??
(environment === 'node' && global) ??
(environment === 'worker' && self),

/**
* Convenience boolean indicating whether we're running in the browser.
Expand Down

0 comments on commit 7d56fe9

Please sign in to comment.