// The .NET Foundation licenses this file to you under the MIT license.
import type { BootJsonData } from "../../types/blazor";
+import { loaderHelpers } from "../globals";
let testAnchor: HTMLAnchorElement;
export function toAbsoluteUri(relativeUri: string): string {
const hasReferencedPdbs = !!bootConfig.resources.pdb;
const debugBuild = bootConfig.debugBuild;
- const navigatorUA = navigator as MonoNavigatorUserAgent;
- const brands = navigatorUA.userAgentData && navigatorUA.userAgentData.brands;
- const currentBrowserIsChromeOrEdge = brands
- ? brands.some(b => b.brand === "Google Chrome" || b.brand === "Microsoft Edge" || b.brand === "Chromium")
- : (window as any).chrome;
-
- return (hasReferencedPdbs || debugBuild) && (currentBrowserIsChromeOrEdge || navigator.userAgent.includes("Firefox"));
-}
-
-// can be removed once userAgentData is part of lib.dom.d.ts
-declare interface MonoNavigatorUserAgent extends Navigator {
- readonly userAgentData: MonoUserAgentData;
-}
-
-declare interface MonoUserAgentData {
- readonly brands: ReadonlyArray<MonoUserAgentDataBrandVersion>;
- readonly platform: string;
-}
-
-declare interface MonoUserAgentDataBrandVersion {
- brand?: string;
- version?: string;
+ return (hasReferencedPdbs || debugBuild) && (loaderHelpers.isChromium || loaderHelpers.isFirefox);
}
\ No newline at end of file
import type { DotnetModuleInternal } from "../types/internal";
-import { INTERNAL, ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_SHELL, loaderHelpers } from "./globals";
+import { INTERNAL, ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_SHELL, loaderHelpers, ENVIRONMENT_IS_WEB } from "./globals";
let node_fs: any | undefined = undefined;
let node_url: any | undefined = undefined;
-export async function init_polyfills(module: DotnetModuleInternal): Promise<void> {
+export async function detect_features_and_polyfill(module: DotnetModuleInternal): Promise<void> {
loaderHelpers.scriptUrl = normalizeFileUrl(/* webpackIgnore: true */import.meta.url);
loaderHelpers.scriptDirectory = normalizeDirectoryUrl(loaderHelpers.scriptUrl);
loaderHelpers.err = console.error;
loaderHelpers.getApplicationEnvironment = module.getApplicationEnvironment;
+ if (ENVIRONMENT_IS_WEB && globalThis.navigator) {
+ const navigator: any = globalThis.navigator;
+ const brands = navigator.userAgentData && navigator.userAgentData.brands;
+ if (brands && brands.length > 0) {
+ loaderHelpers.isChromium = brands.some((b: any) => b.brand === "Google Chrome" || b.brand === "Microsoft Edge" || b.brand === "Chromium");
+ }
+ else if (navigator.userAgent) {
+ loaderHelpers.isChromium = navigator.userAgent.includes("Chrome");
+ loaderHelpers.isFirefox = navigator.userAgent.includes("Firefox");
+ }
+ }
+
if (ENVIRONMENT_IS_NODE) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore:
import { mono_exit } from "./exit";
import { setup_proxy_console } from "./logging";
import { resolve_asset_path, start_asset_download } from "./assets";
-import { init_polyfills } from "./polyfills";
+import { detect_features_and_polyfill } from "./polyfills";
import { runtimeHelpers, loaderHelpers } from "./globals";
import { init_globalization } from "./icu";
import { setupPreloadChannelToMainThread } from "./worker";
}
async function createEmscriptenMain(): Promise<RuntimeAPI> {
- await init_polyfills(module);
+ await detect_features_and_polyfill(module);
if (!module.configSrc && (!module.config || Object.keys(module.config).length === 0 || !module.config.assets)) {
// if config file location nor assets are provided
}
async function createEmscriptenWorker(): Promise<EmscriptenModuleInternal> {
- await init_polyfills(module);
+ await detect_features_and_polyfill(module);
setupPreloadChannelToMainThread();
// The .NET Foundation licenses this file to you under the MIT license.
import cwraps from "./cwraps";
+import { loaderHelpers } from "./globals";
let spread_timers_maximum = 0;
-export let isChromium = false;
let pump_count = 0;
-if (globalThis.navigator) {
- const nav: any = globalThis.navigator;
- if (nav.userAgentData && nav.userAgentData.brands) {
- isChromium = nav.userAgentData.brands.some((i: any) => i.brand == "Chromium");
- }
- else if (nav.userAgent) {
- isChromium = nav.userAgent.includes("Chrome");
- }
-}
-
export function prevent_timer_throttling(): void {
- if (!isChromium) {
+ if (!loaderHelpers.isChromium) {
return;
}
out(message: string): void;
err(message: string): void;
getApplicationEnvironment?: (bootConfigResponse: Response) => string | null;
+
+ isChromium: boolean,
+ isFirefox: boolean,
}
export type RuntimeHelpers = {
config: MonoConfigInternal;