Text of code.visualstudio.com › api › extension-guides › web-extensions as Styx crawled it on Oct 9, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

Web Extensions | Visual Studio Code Extension API

AI agents: See llms.txt for documentation discovery and navigation. Documentation articles are also available as Markdown by appending .md to the article URL. 🎬 Watch The Story of VS Code! VS Code is now on Instagram, follow @vscode.ig for updates, tips, and more. Rewatch GitHub Copilot Day. Web Extensions View as Markdown Ask in VS Code Ask in VS Code Insiders Visual Studio Code can run as an editor in the browser.

One example is the github.dev user interface reached by pressing . (the period key) when browsing a repository or Pull Request in GitHub. When VS Code is used in the Web, installed extensions are run in an extension host in the browser, called the 'web extension host'. An extension that can run in a web extension host is called a 'web extension'. Web extensions share the same structure as regular extensions, but given the different runtime, don't run with the same code as extensions written for a Node.js runtime.

Web extensions still have access to the full VS Code API, but no longer to the Node.js APIs and module loading. Instead, web extensions are restricted by the browser sandbox and therefore have limitations compared to normal extensions. The web extension runtime is supported on VS Code desktop too. If you decide to create your extension as a web extension, it will be supported on VS Code for the Web (including vscode.dev and github.dev ) as well as on the desktop and in services like GitHub Codespaces .

Web extension anatomy A web extension is structured like a regular extension . The extension manifest ( package.json ) defines the entry file for the extension's source code and declares extension contributions. For web extensions, the main entry file is defined by the browser property, and not by the main property as with regular extensions. The contributes property works the same way for both web and regular extensions.

The example below shows the package.json for a simple hello world extension, that runs in the web extension host only (it only has a browser entry point): { "name" : "helloworld-web-sample" , "displayName" : "helloworld-web-sample" , "description" : "HelloWorld example for VS Code in the browser" , "version" : "0.0.1" , "publisher" : "vscode-samples" , "repository" : "https://github.com/microsoft/vscode-extension-samples/helloworld-web-sample" , "engines" : { "vscode" : "^1.74.0" }, "categories" : [ "Other" ], "activationEvents" : [], "browser" : "./dist/web/extension.js" , "contributes" : { "commands" : [ { "command" : "helloworld-web-sample.helloWorld" , "title" : "Hello World" } ] }, "scripts" : { "vscode:prepublish" : "npm run package-web" , "compile-web" : "webpack" , "watch-web" : "webpack --watch" , "package-web" : "webpack --mode production --devtool hidden-source-map" }, "devDependencies" : { "@types/vscode" : "^1.59.0" , "ts-loader" : "^9.2.2" , "webpack" : "^5.38.1" , "webpack-cli" : "^4.7.0" , "@types/webpack-env" : "^1.16.0" , "process" : "^0.11.10" } } Note : If your extension targets a VS Code version prior to 1.74, you must explicitly list onCommand:helloworld-web-sample.helloWorld in activationEvents .

Extensions that have only a main entry point, but no browser are not web extensions. They are ignored by the web extension host and not available for download in the Extensions view. Extensions with only declarative contributions (only contributes , no main or browser ) can be web extensions. They can be installed and run in VS Code for the Web without any modifications by the extension author. Examples of extensions with declarative contributions include themes, grammars, and snippets.

Extensions can have both browser and main entry points in order to run in browser and in Node.js runtimes. The Update existing extensions to Web extensions section shows how to migrate an extension to work in both runtimes. The web extension enablement section lists the rules used to decide whether an extension can be loaded in a web extension host. Web extension main file The web extension's main file is defined by the browser property.

The script runs in the web extension host in a Browser WebWorker environment. It is restricted by the browser worker sandbox and has limitations compared to normal extensions running in a Node.js runtime. Importing or requiring other modules is not supported. importScripts is not available as well. As a consequence, the code must be packaged to a single file. The VS Code API can be loaded via the pattern require('vscode') .

This will work because there is a shim for require , but this shim cannot be used to load additional extension files or additional node modules. It only works with require('vscode') . Node.js globals and libraries such as process , os , setImmediate , path , util , url are not available at runtime. They can, however, be added with tools like webpack. The webpack configuration section explains how this is done. The opened workspace or folder is on a virtual file system.

Access to workspace files needs to go through the VS Code file system API accessible at vscode.workspace.fs . Extension context locations ( ExtensionContext.extensionUri ) and storage locations ( ExtensionContext.storageUri , globalStorageUri ) are also on a virtual file system and need to go through vscode.workspace.fs . For accessing web resources, the Fetch API must be used. Accessed resources need to support Cross-Origin Resource Sharing (CORS) Creating child processes or running executables is not possible.

However, web workers can be created through the Worker API. This is used for running language servers as described in the Language Server Protocol in web extensions section. As with regular extensions, the extension's activate/deactivate functions need to be exported via the pattern exports.activate = ... . Develop a web extension Thankfully, tools like TypeScript and webpack can hide many of the browser runtime constraints and allow you to write web extensions the same way as regular extensions.

Both a web extension and a regular extension can often be generated from the same source code. For example, the Hello Web Extension created by the yo code generator only differs in the build scripts. You can run and debug the generated extension just like traditional Node.js extensions by using the provided launch configurations accessible using the Debug: Select and Start Debugging command. Create a web extension To scaffold a new web extension, use yo code and pick New Web Extension .

Make sure to have the latest version of generator-code (>= generator-code@1.6) installed. To update the generator and yo, run npm i -g yo generator-code . The extension that is created consists of the extension's source code (a command showing a hello world notification), the package.json manifest file, and a webpack or esbuild configuration file. To keep things simpler, we assume you use webpack as the bundler. At the end of the article we also explain what is different when choosing esbuild . src/web/extension.ts is the extension's entry source code file.

It's identical to the regular hello extension. package.json is the extension manifest. It points to the entry file using the browser property. It provides scripts: compile-web , watch-web and package-web to compile, watch, and package. webpack.config.js is the webpack config file that compiles and bundles the extension sources into a single file. .vscode/launch.json contains the launch configurations that run the web extension and the tests in the VS Code desktop with a web extension host (setting extensions.webWorker is no longer needed). .vscode/task.json contains the build task used by the launch configuration.

It uses npm run watch-web and depends on the webpack specific ts-webpack-watch problem matcher. .vscode/extensions.json contains the extensions that provide the problem matchers. These extensions need to be installed for the launch configurations to work. tsconfig.json defines the compile options matching the webworker runtime. The source code in th

The rest of this page is on the live site.