diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md
index eb695339e..a71bf8156 100644
--- a/ci/release/changelogs/next.md
+++ b/ci/release/changelogs/next.md
@@ -4,6 +4,7 @@
#### Improvements 🧹
+- `--browser` flag on CLI controls `BROWSER` environment variable for not opening browser in watch mode. [#1052](https://github.com/terrastruct/d2/pull/1052)
- `elk` layout containers no longer overlap the label with children. [#1055](https://github.com/terrastruct/d2/pull/1055)
- `
` attribute of HTML in watch mode is the base file name, instead of the whole path. [#1054](https://github.com/terrastruct/d2/pull/1054)
diff --git a/ci/release/template/man/d2.1 b/ci/release/template/man/d2.1
index cc012ef7e..6dce8cf36 100644
--- a/ci/release/template/man/d2.1
+++ b/ci/release/template/man/d2.1
@@ -83,6 +83,9 @@ Center the SVG in the containing viewbox, such as your browser screen
.It Fl -pad Ar 100
Pixels padded around the rendered diagram
.Ns .
+.It Fl -browser Ar true
+Browser executable that watch opens. Setting to 0 opens no browser
+.Ns .
.It Fl l , -layout Ar dagre
Set the diagram layout engine to the passed string. For a list of available options, run
.Ar layout
diff --git a/d2cli/main.go b/d2cli/main.go
index 4763b8cff..fbf690930 100644
--- a/d2cli/main.go
+++ b/d2cli/main.go
@@ -83,6 +83,7 @@ func Run(ctx context.Context, ms *xmain.State) (err error) {
if err != nil {
return err
}
+ browserFlag := ms.Opts.String("BROWSER", "browser", "", "", "browser executable that watch opens. Setting to 0 opens no browser.")
centerFlag, err := ms.Opts.Bool("D2_CENTER", "center", "c", false, "center the SVG in the containing viewbox, such as your browser screen")
if err != nil {
return err
@@ -130,6 +131,9 @@ func Run(ctx context.Context, ms *xmain.State) (err error) {
if *debugFlag {
ms.Env.Setenv("DEBUG", "1")
}
+ if *browserFlag != "" {
+ ms.Env.Setenv("BROWSER", *browserFlag)
+ }
var inputPath string
var outputPath string