Skip to content

Commit

Permalink
Open devtools in default browser (#7099)
Browse files Browse the repository at this point in the history
  • Loading branch information
penalosa authored Nov 12, 2024
1 parent e189571 commit ee305dd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-hornets-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Open devtools in default browser
36 changes: 2 additions & 34 deletions packages/wrangler/src/dev/inspect.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { readFileSync } from "fs";
import os from "node:os";
import { fileURLToPath, URL } from "node:url";
import path from "path";
import open from "open";
import {
isAllowedSourceMapPath,
isAllowedSourcePath,
} from "../api/startDevWorker/bundle-allowed-paths";
import { logger } from "../logger";
import openInBrowser from "../open-in-browser";
import { getSourceMappedString } from "../sourcemap";
import type { EsbuildBundle } from "../dev/use-esbuild";
import type Protocol from "devtools-protocol";
Expand Down Expand Up @@ -257,37 +256,6 @@ export const openInspector = async (
}
query.set("debugger", "true");
const url = `https://devtools.devprod.cloudflare.dev/js_app?${query.toString()}`;
const errorMessage =
"Failed to open inspector.\nInspector depends on having a Chromium-based browser installed, maybe you need to install one?";

// see: https://github.com/sindresorhus/open/issues/177#issue-610016699
let braveBrowser: string;
switch (os.platform()) {
case "darwin":
case "win32":
braveBrowser = "Brave";
break;
default:
braveBrowser = "brave";
}

const childProcess = await open(url, {
app: [
{
name: open.apps.chrome,
},
{
name: braveBrowser,
},
{
name: open.apps.edge,
},
{
name: open.apps.firefox,
},
],
});
childProcess.on("error", () => {
logger.warn(errorMessage);
});
await openInBrowser(url);
};

0 comments on commit ee305dd

Please sign in to comment.