Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to make registerUriHandler work #3891

Unanswered
futurist asked this question in Q&A
Discussion options

How to handle protocol vscode:// uri with existing extension?

From documentation of vscode.window.registerUriHandler():

Registers a uri handler capable of handling system-wide uris. In case there are multiple windows open, the topmost window > will handle the uri. A uri handler is scoped to the extension it is contributed from; it will only be able to handle uris which are > directed to the extension itself.

I want to migrate an existing vscode plugin to code-server, but don't know how to get handleUri event work like below code:

vscode.window.registerUriHandler({
 handleUri(uri:vscode.Uri) {
 // extension logic for `vscode://my-plugin/path`
 }
});

Local vscode can trigger handleUri message when open vscode://my-plugin/path from browser, how does code-server do similar like this? That is code-server already in browser, and how to notify my plugin with message passed from vscode://my-plugin/path, what's the right entry for this special URI?

You must be logged in to vote

Replies: 3 comments 6 replies

Comment options

Oh this is a great question. I think @code-asher might have some tips/ideas

You must be logged in to vote
0 replies
Comment options

I bet this hasn't been modified to work in the browser yet.

We'll likely need to patch VS Code to use https://developer.mozilla.org/en-US/docs/Web/API/Navigator/registerProtocolHandler

But this is definitely better done upstream.

You must be logged in to vote
0 replies
Comment options

Does navigator.registerProtocolHandler conflict with user's local VSCode? For example with the link vscode://my-plugin/path, should it be handled by browser or by VSCode? Also, user can have multiple instances of code-server.

Maybe code-server can have a special route it self to handle this message? Like below:

https://code-server-url/protocol-handler?uri=vscode://my-plugin/path

This added the benefit: there're no notification/confirmation when user open it, more smooth than VSCode.

You must be logged in to vote
6 replies
Comment options

I do not think browsers allow handling vscode:// anyway, at best we could do web+vscode:// or web+code-server://.

See permitted schemes: https://developer.mozilla.org/en-US/docs/Web/API/Navigator/registerProtocolHandler#permitted_schemes

The /protocol-handler idea is interesting! I think the only problem is how to get code-server-url. For example if GitHub had an "Open in code-server" button they would not have anything to put for the domain. So we will probably need something like web+code-server://my-plugin/path.

Comment options

@code-asher was wondering if something like this is possible now? I love being able to clone directly from a GitHub button and would love for this functionality to be possible with code-server!

For example, the URL below clones a GitHub repo in your local Vscode.

vscode://vscode.git/clone?url=url
Comment options

No, I do not think anything has changed here yet.

Comment options

Could the protocl_handlers property in the PWA manifest help? (https://developer.mozilla.org/en-US/docs/Web/Manifest/protocol_handlers)

I'm also trying to make this work with a setup like this:

Comment options

Could the protocl_handlers property in the PWA manifest help? (https://developer.mozilla.org/en-US/docs/Web/Manifest/protocol_handlers)

I'm also trying to make this work with a setup like this:

I know it's an old thread but just adjusting the manifest Works for me. You can test by overriding sources.
It must be served over https:// as per PWA spec.

Screenshot 2024年11月06日 at 10 20 55 PM Screenshot 2024年11月06日 at 10 21 06 PM Screenshot 2024年11月06日 at 10 21 12 PM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /