The runtime published its bridge by setting globalThis.newIPN and the loader read it back immediately after go.run(). That works only because main() happens to reach the Set call before it blocks, so any package init that waits on a channel or makes an async JS call would leave the loader reading a global that is not there yet. Take the name of a JS callback from go.env instead, and invoke it once the bridge is built. Readiness is now the call itself, the runtime writes nothing to the shared global scope, and two runtimes in one realm cannot collide on a name. The callback receives a factory that may be used once. shutdown() exits the whole Go runtime, so a second IPN here would be torn down by the first one's shutdown; an atomic guard rejects it rather than handing back an instance that dies unpredictably. The factory returns a promise, so failures building the engine, netstack, or LocalBackend reject instead of calling log.Fatal and taking the runtime down with no explanation for the caller. Co-Authored-By: claude-opus-5 <noreply@anthropic.com>
tsconnect
The tsconnect command builds and serves the static site that is generated for the Tailscale Connect JS/WASM client.
Development
To start the development server:
./tool/go run ./cmd/tsconnect dev
The site is served at http://localhost:9090/. JavaScript, CSS and Go wasm package changes can be picked up with a browser reload. Server-side Go changes require the server to be stopped and restarted. In development mode the state the Tailscale client state is stored in sessionStorage and will thus survive page reloads (but not the tab being closed).
Deployment
To build the static assets necessary for serving, run:
./tool/go run ./cmd/tsconnect build
To serve them, run:
./tool/go run ./cmd/tsconnect serve
By default the build output is placed in the dist/ directory and embedded in the binary, but this can be controlled by the -distdir flag. The -addr flag controls the interface and port that the serve listens on.
Library / NPM Package
The client is also available as an NPM package. To build it, run:
./tool/go run ./cmd/tsconnect build-pkg
That places the output in the pkg/ directory, which may then be uploaded to a package registry (or installed from the file path directly).
To do two-sided development (on both the NPM package and code that uses it), run:
./tool/go run ./cmd/tsconnect dev-pkg
This serves the module at http://localhost:9090/pkg/pkg.js and the generated wasm file at http://localhost:9090/pkg/main.wasm. The two files can be used as drop-in replacements for normal imports of the NPM module.