# Make a VS Code Extension Run in the Browser as a Web Extension

Yes. An agent adds a browser entry point to your VS Code extension, bundles it for the web worker host alongside the Node build, and runs it in a headless browser.

[Run this on Rush](https://cloud.getrush.ai/run/add-web-extension-support/vscode-extension/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent clones the repository into its own cloud sandbox and reads the extension before changing its build. In an extension like the `statusbar-sample` in microsoft/vscode-extension-samples, `package.json` names it `status-ts`, requires `vscode` ^1.100.0, points `main` at `./out/extension.js`, compiles with a bare `tsc -p ./` and lints with ESLint 9 through `typescript-eslint` and `@stylistic`; `tsconfig.json` targets ES2024 as CommonJS into `out`. `src/extension.ts` is one file: it registers the `sample.showSelectionCount` command, creates a status bar item on the right with priority 100, and updates its text to `$(megaphone) N line(s) selected` on every editor and selection change. It imports only the `vscode` module and no Node API, which is what makes it a candidate for the web: the web extension host runs in a web worker with no `fs`, `child_process` or `process`. Two things in the manifest would stop it: there is no `browser` entry, and `activationEvents` is `["*"]`.

The agent follows the repository's own web sample. `helloworld-web-sample/package.json` sets `browser` to `./dist/web/extension.js`, bundles with webpack 5 for `target: 'webworker'` with `vscode` as a `commonjs` external and `mainFields` preferring `browser`, and tests with `@vscode/test-web`, which downloads a Chromium and serves VS Code for the web with the extension loaded. For a one-file extension the agent uses the smaller setup from `esbuild-sample`: an `esbuild.js` with two builds from the same `src/extension.ts`, `platform: 'node'` to `dist/extension.js` and `platform: 'browser'` with `format: 'cjs'` and `external: ['vscode']` to `dist/web/extension.js`. `main` moves to `./dist/extension.js`, `browser` points at the web file, `.vscodeignore` is added so the package ships `dist` and not `src` or `out`, and the `compile`, `watch` and `vscode:prepublish` scripts call the bundle; `tsc --noEmit` stays as the type check and `lib` gains `WebWorker` so a stray `process` reference fails at compile time.

`activationEvents` changes from `*` to `onStartupFinished`. The sample activates on everything so the status bar item exists as soon as a window opens; `onStartupFinished` gives the same result without delaying startup, which is what the extension guidelines ask for and what both hosts support. The agent adds `src/test/suite/index.ts` and one test that opens an untitled document, selects two lines, runs the command and asserts the extension is active, bundled by the same esbuild script into `dist/web/test/suite/index.js` for the web run and compiled for the desktop run. `.vscode/launch.json` gets a second configuration that launches the extension host with `--extensionDevelopmentKind=web`, beside the existing desktop one.

In the sandbox the agent runs `npm install`, `npm run compile`, `npm run lint`, and `npm run test-web`, which starts `vscode-test-web --browserType=chromium --extensionDevelopmentPath=. --extensionTestsPath=dist/web/test/suite/index.js` in headless Chromium and prints the Mocha result. It also runs the desktop test through `@vscode/test-electron` when a display is available and says so if it is not. The output of each goes into the pull request, together with the two bundle sizes from esbuild.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Make this VS Code extension run as a web extension as well as on the desktop. Read package.json, tsconfig.json and src/extension.ts first and check that the code uses no Node API. Add a browser entry point bundled for the web worker host with esbuild, keep the Node build, replace the activation event * with onStartupFinished, add a .vscodeignore, add a launch configuration for the web extension host, and add one test that runs under @vscode/test-web in headless Chromium. Run the build, the lint and the web test in your sandbox and put the output in the pull request. Open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on its own branch adding `esbuild.js`, `.vscodeignore` and `src/test/suite/`, and changing `package.json`, `tsconfig.json`, `.vscode/launch.json`, `.vscode/tasks.json` and `README.md`. `src/extension.ts` is unchanged. The description shows the build output with both bundle paths, the ESLint result, and the Mocha result from the web test run in the sandbox's headless browser.

The run's record keeps every command, including the `@vscode/test-web` session, so a reviewer can see the extension activated in the web worker host and the test passed without installing anything locally. The README gains a short section on running `npm run start-web` to try the extension in a browser on localhost.

Before merging, a reviewer checks the `engines.vscode` version against the oldest web host they want to support, decides whether `onStartupFinished` is acceptable for their users or whether a more specific event fits, and tries the new launch configuration once in their own editor.

## Run it on every extension you hand off

Start it from a terminal with `POST /o/{org}/sessions`, this body and the repository in `resources`, and come back to a pull request with the test output in it. A follow-up through `POST /o/{org}/sessions/{id}/messages` wakes the parked sandbox for the next step: a GitHub Actions workflow that runs the web test on every pull request, or packaging with `vsce` to check the `.vsix` contents.

A publisher with several extensions can start one run per repository, each in its own sandbox with its own pull request and its own test output. Send a `request_id`, a UUID per repository, so a retried script returns the run already started.

## Why run it on Rush?

The web extension guide is clear but long, and most of the work is plumbing: a second bundle target, a manifest field, an activation event, a test harness that needs a browser. The agent reads your extension to confirm it has no Node dependency first, so you learn early if the answer is no, and then does the plumbing in the shape the official samples use.

The sandbox has a browser, so `@vscode/test-web` runs for real and the Mocha result lands in the run's record rather than in a sentence. Several extensions can be converted at once in separate sandboxes, each with its own evidence.

## Frequently asked questions

### Does my extension need code changes to run in the browser?

This one does not: it imports only the `vscode` module. An extension that reads files with `fs`, spawns processes or depends on a Node-only package needs alternatives such as `workspace.fs` or a browser build of the dependency. The agent checks the imports first and tells you which ones block a web build before it changes anything.

### Why change activationEvents from * to onStartupFinished?

`*` activates the extension during startup and is discouraged for that reason. `onStartupFinished` activates it right after the window has finished starting, which for a status bar item is indistinguishable to the user, and it is honoured by both the desktop and the web host.

### Can I keep webpack instead of esbuild?

Yes. The repository's own web sample uses webpack 5 with `target: 'webworker'`, and the agent can follow that instead if you say so in the prompt. For a single-file extension the esbuild script is shorter and builds both targets from one file, which is why it is the default here.

### How do I try it in a browser myself?

Run `npm run start-web`, which starts `@vscode/test-web` and opens VS Code for the web on localhost with the extension loaded. To test on vscode.dev, serve the extension folder over HTTPS and use the Install Extension From Location command, as the web extension guide describes.

## More VS Code Extension jobs

- [Turn Sentry Errors Into Fix Pull Requests for a VS Code Extension](https://getrush.ai/run/fix-sentry-errors/vscode-extension/)
- [Migrate a VS Code Extension to ESLint Flat Config](https://getrush.ai/run/migrate-eslint-flat-config/vscode-extension/)
- [Migrate a VS Code Extension from TSLint to ESLint](https://getrush.ai/run/migrate-tslint-to-eslint/vscode-extension/)

## More jobs like this: Hand off a long task

- [Publish a Chrome Extension to the Chrome Web Store from GitHub Actions](https://getrush.ai/run/add-web-store-publishing/chrome-extension/)
- [Add a GitHub Webhook Receiver to a Flux Cluster](https://getrush.ai/run/add-webhook-receiver/flux/)
- [Add WebSockets to an aiohttp App](https://getrush.ai/run/add-websockets/aiohttp/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
