[wasm][debugging] Enable debugging when Device Toolbar is enabled and Iphone is selec...
authorThays Grazia <thaystg@gmail.com>
Thu, 8 Jun 2023 10:20:21 +0000 (07:20 -0300)
committerGitHub <noreply@github.com>
Thu, 8 Jun 2023 10:20:21 +0000 (12:20 +0200)
* Enable debugging when Device Toolbar is enabled and Iphone is selected
* unify browser detection
Co-authored-by: pavelsavara <pavel.savara@gmail.com>
src/mono/wasm/runtime/loader/blazor/_Polyfill.ts
src/mono/wasm/runtime/loader/polyfills.ts
src/mono/wasm/runtime/loader/run.ts
src/mono/wasm/runtime/scheduling.ts
src/mono/wasm/runtime/types/internal.ts

index 4eeefe2..ea9b13b 100644 (file)
@@ -2,6 +2,7 @@
 // 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 {
@@ -16,26 +17,5 @@ export function hasDebuggingEnabled(bootConfig: BootJsonData): boolean {
     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
index fb5c4bc..5a6a6d5 100644 (file)
@@ -1,11 +1,11 @@
 
 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);
@@ -21,6 +21,18 @@ export async function init_polyfills(module: DotnetModuleInternal): Promise<void
     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:
index 973f530..a147f9f 100644 (file)
@@ -9,7 +9,7 @@ import { deep_merge_config, deep_merge_module, mono_wasm_load_config } from "./c
 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";
@@ -391,7 +391,7 @@ function initializeModules(es6Modules: [RuntimeModuleExportsInternal, NativeModu
 }
 
 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
@@ -425,7 +425,7 @@ async function createEmscriptenMain(): Promise<RuntimeAPI> {
 }
 
 async function createEmscriptenWorker(): Promise<EmscriptenModuleInternal> {
-    await init_polyfills(module);
+    await detect_features_and_polyfill(module);
 
     setupPreloadChannelToMainThread();
 
index 7b0755b..b0ce9c0 100644 (file)
@@ -2,23 +2,13 @@
 // 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;
     }
 
index f9a1623..5816f9a 100644 (file)
@@ -131,6 +131,9 @@ export type LoaderHelpers = {
     out(message: string): void;
     err(message: string): void;
     getApplicationEnvironment?: (bootConfigResponse: Response) => string | null;
+
+    isChromium: boolean,
+    isFirefox: boolean,
 }
 export type RuntimeHelpers = {
     config: MonoConfigInternal;