Skip to content

Commit 03f2be6

Browse files
thaystgpavelsavara
andauthored
[wasm][debugging] Enable debugging when Device Toolbar is enabled and Iphone is selected (#86920)
* Enable debugging when Device Toolbar is enabled and Iphone is selected * unify browser detection Co-authored-by: pavelsavara <[email protected]>
1 parent d3ea4a9 commit 03f2be6

File tree

5 files changed

+24
-39
lines changed

5 files changed

+24
-39
lines changed

src/mono/wasm/runtime/loader/blazor/_Polyfill.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
import type { BootJsonData } from "../../types/blazor";
5+
import { loaderHelpers } from "../globals";
56

67
let testAnchor: HTMLAnchorElement;
78
export function toAbsoluteUri(relativeUri: string): string {
@@ -16,26 +17,5 @@ export function hasDebuggingEnabled(bootConfig: BootJsonData): boolean {
1617
const hasReferencedPdbs = !!bootConfig.resources.pdb;
1718
const debugBuild = bootConfig.debugBuild;
1819

19-
const navigatorUA = navigator as MonoNavigatorUserAgent;
20-
const brands = navigatorUA.userAgentData && navigatorUA.userAgentData.brands;
21-
const currentBrowserIsChromeOrEdge = brands
22-
? brands.some(b => b.brand === "Google Chrome" || b.brand === "Microsoft Edge" || b.brand === "Chromium")
23-
: (window as any).chrome;
24-
25-
return (hasReferencedPdbs || debugBuild) && (currentBrowserIsChromeOrEdge || navigator.userAgent.includes("Firefox"));
26-
}
27-
28-
// can be removed once userAgentData is part of lib.dom.d.ts
29-
declare interface MonoNavigatorUserAgent extends Navigator {
30-
readonly userAgentData: MonoUserAgentData;
31-
}
32-
33-
declare interface MonoUserAgentData {
34-
readonly brands: ReadonlyArray<MonoUserAgentDataBrandVersion>;
35-
readonly platform: string;
36-
}
37-
38-
declare interface MonoUserAgentDataBrandVersion {
39-
brand?: string;
40-
version?: string;
20+
return (hasReferencedPdbs || debugBuild) && (loaderHelpers.isChromium || loaderHelpers.isFirefox);
4121
}

src/mono/wasm/runtime/loader/polyfills.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22
import type { DotnetModuleInternal } from "../types/internal";
3-
import { INTERNAL, ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_SHELL, loaderHelpers } from "./globals";
3+
import { INTERNAL, ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_SHELL, loaderHelpers, ENVIRONMENT_IS_WEB } from "./globals";
44

55
let node_fs: any | undefined = undefined;
66
let node_url: any | undefined = undefined;
77

8-
export async function init_polyfills(module: DotnetModuleInternal): Promise<void> {
8+
export async function detect_features_and_polyfill(module: DotnetModuleInternal): Promise<void> {
99

1010
loaderHelpers.scriptUrl = normalizeFileUrl(/* webpackIgnore: true */import.meta.url);
1111
loaderHelpers.scriptDirectory = normalizeDirectoryUrl(loaderHelpers.scriptUrl);
@@ -21,6 +21,18 @@ export async function init_polyfills(module: DotnetModuleInternal): Promise<void
2121
loaderHelpers.err = console.error;
2222
loaderHelpers.getApplicationEnvironment = module.getApplicationEnvironment;
2323

24+
if (ENVIRONMENT_IS_WEB && globalThis.navigator) {
25+
const navigator: any = globalThis.navigator;
26+
const brands = navigator.userAgentData && navigator.userAgentData.brands;
27+
if (brands && brands.length > 0) {
28+
loaderHelpers.isChromium = brands.some((b: any) => b.brand === "Google Chrome" || b.brand === "Microsoft Edge" || b.brand === "Chromium");
29+
}
30+
else if (navigator.userAgent) {
31+
loaderHelpers.isChromium = navigator.userAgent.includes("Chrome");
32+
loaderHelpers.isFirefox = navigator.userAgent.includes("Firefox");
33+
}
34+
}
35+
2436
if (ENVIRONMENT_IS_NODE) {
2537
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2638
// @ts-ignore:

src/mono/wasm/runtime/loader/run.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { deep_merge_config, deep_merge_module, mono_wasm_load_config } from "./c
99
import { mono_exit } from "./exit";
1010
import { setup_proxy_console } from "./logging";
1111
import { resolve_asset_path, start_asset_download } from "./assets";
12-
import { init_polyfills } from "./polyfills";
12+
import { detect_features_and_polyfill } from "./polyfills";
1313
import { runtimeHelpers, loaderHelpers } from "./globals";
1414
import { init_globalization } from "./icu";
1515
import { setupPreloadChannelToMainThread } from "./worker";
@@ -391,7 +391,7 @@ function initializeModules(es6Modules: [RuntimeModuleExportsInternal, NativeModu
391391
}
392392

393393
async function createEmscriptenMain(): Promise<RuntimeAPI> {
394-
await init_polyfills(module);
394+
await detect_features_and_polyfill(module);
395395

396396
if (!module.configSrc && (!module.config || Object.keys(module.config).length === 0 || !module.config.assets)) {
397397
// if config file location nor assets are provided
@@ -425,7 +425,7 @@ async function createEmscriptenMain(): Promise<RuntimeAPI> {
425425
}
426426

427427
async function createEmscriptenWorker(): Promise<EmscriptenModuleInternal> {
428-
await init_polyfills(module);
428+
await detect_features_and_polyfill(module);
429429

430430
setupPreloadChannelToMainThread();
431431

src/mono/wasm/runtime/scheduling.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,13 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
import cwraps from "./cwraps";
5+
import { loaderHelpers } from "./globals";
56

67
let spread_timers_maximum = 0;
7-
export let isChromium = false;
88
let pump_count = 0;
99

10-
if (globalThis.navigator) {
11-
const nav: any = globalThis.navigator;
12-
if (nav.userAgentData && nav.userAgentData.brands) {
13-
isChromium = nav.userAgentData.brands.some((i: any) => i.brand == "Chromium");
14-
}
15-
else if (nav.userAgent) {
16-
isChromium = nav.userAgent.includes("Chrome");
17-
}
18-
}
19-
2010
export function prevent_timer_throttling(): void {
21-
if (!isChromium) {
11+
if (!loaderHelpers.isChromium) {
2212
return;
2313
}
2414

src/mono/wasm/runtime/types/internal.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ export type LoaderHelpers = {
131131
out(message: string): void;
132132
err(message: string): void;
133133
getApplicationEnvironment?: (bootConfigResponse: Response) => string | null;
134+
135+
isChromium: boolean,
136+
isFirefox: boolean,
134137
}
135138
export type RuntimeHelpers = {
136139
config: MonoConfigInternal;

0 commit comments

Comments
 (0)