MCPcopy Create free account
hub / github.com/CoderLine/alphaTab / _detectWebPlatform

Method _detectWebPlatform

packages/alphatab/src/Environment.ts:741–779  ·  view source on GitHub ↗

* @target web

()

Source from the content-addressed store, hash-verified

739 * @target web
740 */
741 private static _detectWebPlatform(): WebPlatform {
742 // There might be polyfills or platforms like Electron which have a global process object defined even in the browser.
743 // We need to differenciate between those platforms and a real nodejs
744
745 // the webPlatform is currently only relevant on the main process side and not within workers/worklets
746 // so it is OK if we wrongly detect node.js inside them.
747 const isBrowserLike =
748 // browser UI thread
749 typeof Environment.globalThis.Window !== 'undefined' &&
750 Environment.globalThis instanceof Environment.globalThis.Window;
751
752 if (!isBrowserLike) {
753 try {
754 // Credit of the node.js detection goes to
755 // https://github.com/iliakan/detect-node
756 // MIT License
757 // Copyright (c) 2017 Ilya Kantor
758 // tslint:disable-next-line: strict-type-predicates
759 if (
760 Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]'
761 ) {
762 return WebPlatform.NodeJs;
763 }
764 } catch {
765 // no node.js
766 }
767 }
768
769 try {
770 const url: any = import.meta.url;
771 if (url && typeof url === 'string' && !url.startsWith('file://')) {
772 return WebPlatform.BrowserModule;
773 }
774 } catch {
775 // no browser module
776 }
777
778 return WebPlatform.Browser;
779 }
780
781 /**
782 * Prints the environment information for easier troubleshooting.

Callers 1

EnvironmentClass · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected