How to callback to your extension from outside VS Code
This post is over a year old, some of this information may be out of date.
While creating the authentication provider, I discovered a helpful handler in the Visual Studio Code API, which allows you to handle system-wide URIs and callback into your extension.
In the case of the authentication provider, I use it to retrieve the token that gets passed from the callback, but you can use the registerUriHandler for many more scenarios. You can, for instance, integrate a callback from your website into VS Code. Execute scripts that open a file/content you want to get processed by your extension.
How to use the registerUriHandler
It is relatively simple to create your own URI handler. All you need is the following code:
import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
const handleUri = (uri: vscode.Uri) => { const queryParams = new URLSearchParams(uri.query);
if (queryParams.has('say')) { vscode.window.showInformationMessage(`URI Handler says: ${queryParams.get('say') as string}`); } };
context.subscriptions.push( vscode.window.registerUriHandler({ handleUri }) );}
export function deactivate() {}
Calling back to your extension
To trigger the handleUri method, you need to trigger it from the following URL vscode://<publisher>.<extension name>
.
In the case of my example, I use the following URL: vscode://eliostruyf.vscode-urihandler-test?say=How are you doing?
, which results in the subsequent notification:

Related articles
#DevHack: Open custom VSCode WebView panel and focus input
#DevHack: How to rename a file from a VSCode extension
In this DevHack we will learn how to rename a file from a vscode extension. If you are looking for a simple appraoch, this will be the one to use.
#DevHack: language-specific settings in a VSCode extension
Get to know how you can set language-specific settings straight from within the code of your Visual Studio Code extension.
Report issues or make changes on GitHub
Found a typo or issue in this article? Visit the GitHub repository to make changes or submit a bug report.
Comments
Let's build together
Manage content in VS Code
Present from VS Code