fix(browser): add Edge LaunchServices bundle IDs for macOS default browser detection

macOS registers Edge as 'com.microsoft.edgemac' in LaunchServices, which
differs from the CFBundleIdentifier 'com.microsoft.Edge' in the app's own
Info.plist. Without recognising the LaunchServices IDs, Edge users who set
Edge as their default browser are not detected as having a Chromium browser.

Add the four com.microsoft.edgemac* variants to CHROMIUM_BUNDLE_IDS and a
corresponding test that mocks the LaunchServices → osascript resolution
path for Edge.
This commit is contained in:
Zoher Ghadyali
2026-03-24 16:23:09 -07:00
committed by Ayaan Zaidi
parent 55dc6a8bb2
commit 2fe38b0201
2 changed files with 54 additions and 0 deletions

View File

@@ -82,6 +82,54 @@ describe("browser default executable detection", () => {
expect(exe?.kind).toBe("chrome");
});
it("detects Edge via LaunchServices bundle ID (com.microsoft.edgemac)", async () => {
const edgeExecutablePath = "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge";
// macOS LaunchServices registers Edge as "com.microsoft.edgemac", which
// differs from the CFBundleIdentifier "com.microsoft.Edge" in the app's
// own Info.plist. Both must be recognised.
//
// The existsSync mock deliberately only returns true for the Edge path
// when checked via the resolved osascript/defaults path — Chrome's
// fallback candidate path is the only other "existing" binary. This
// ensures the test fails if the default-browser detection branch is
// broken, because the fallback candidate list would return Chrome, not
// Edge.
vi.mocked(execFileSync).mockImplementation((cmd, args) => {
const argsStr = Array.isArray(args) ? args.join(" ") : "";
if (cmd === "/usr/bin/plutil" && argsStr.includes("LSHandlers")) {
return JSON.stringify([
{ LSHandlerURLScheme: "http", LSHandlerRoleAll: "com.microsoft.edgemac" },
]);
}
if (cmd === "/usr/bin/osascript" && argsStr.includes("path to application id")) {
return "/Applications/Microsoft Edge.app/";
}
if (cmd === "/usr/bin/defaults") {
return "Microsoft Edge";
}
return "";
});
vi.mocked(fs.existsSync).mockImplementation((p) => {
const value = String(p);
if (value.includes(launchServicesPlist)) {
return true;
}
// Only Edge (via osascript resolution) and Chrome (fallback candidate)
// "exist". If default-browser detection breaks, the resolver would
// return Chrome from the fallback list — not Edge — failing the assert.
return value === edgeExecutablePath || value.includes(chromeExecutablePath);
});
const resolveBrowserExecutableForPlatform = await loadResolveBrowserExecutableForPlatform();
const exe = resolveBrowserExecutableForPlatform(
{} as Parameters<typeof resolveBrowserExecutableForPlatform>[0],
"darwin",
);
expect(exe?.path).toBe(edgeExecutablePath);
expect(exe?.kind).toBe("edge");
});
it("falls back when default browser is non-Chromium on macOS", async () => {
mockMacDefaultBrowser("com.apple.Safari");
mockChromeExecutableExists();

View File

@@ -23,6 +23,12 @@ const CHROMIUM_BUNDLE_IDS = new Set([
"com.microsoft.EdgeBeta",
"com.microsoft.EdgeDev",
"com.microsoft.EdgeCanary",
// Edge LaunchServices IDs (used in macOS default browser registration —
// these differ from CFBundleIdentifier and are what plutil returns)
"com.microsoft.edgemac",
"com.microsoft.edgemac.beta",
"com.microsoft.edgemac.dev",
"com.microsoft.edgemac.canary",
"org.chromium.Chromium",
"com.vivaldi.Vivaldi",
"com.operasoftware.Opera",