isBrowser.js 721 B

123456789101112131415161718192021
  1. import { isNodeEnv } from './node.js';
  2. import { GLOBAL_OBJ } from './worldwide.js';
  3. /**
  4. * Returns true if we are in the browser.
  5. */
  6. function isBrowser() {
  7. // eslint-disable-next-line no-restricted-globals
  8. return typeof window !== 'undefined' && (!isNodeEnv() || isElectronNodeRenderer());
  9. }
  10. // Electron renderers with nodeIntegration enabled are detected as Node.js so we specifically test for them
  11. function isElectronNodeRenderer() {
  12. return (
  13. // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
  14. (GLOBAL_OBJ ).process !== undefined && ((GLOBAL_OBJ ).process ).type === 'renderer'
  15. );
  16. }
  17. export { isBrowser };
  18. //# sourceMappingURL=isBrowser.js.map