-
Notifications
You must be signed in to change notification settings - Fork 6.3k
-
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?
Beta Was this translation helpful? Give feedback.
All reactions
-
👀 1
Replies: 3 comments 6 replies
-
Oh this is a great question. I think @code-asher might have some tips/ideas
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
@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
Beta Was this translation helpful? Give feedback.
All reactions
-
No, I do not think anything has changed here yet.
Beta Was this translation helpful? Give feedback.
All reactions
-
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:
- test different urls within gitea 1.22.0 (https://blog.gitea.com/release-of-1.22.0/#rocket-customizable-open-with-ide-menu-29320)
- try to open code-server installed as PWA via Chrome on Windows
- testing workarounds like https://github.com/shengyou/vscode-handler
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Could the
protocl_handlersproperty 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:
- test different urls within gitea 1.22.0 (https://blog.gitea.com/release-of-1.22.0/#rocket-customizable-open-with-ide-menu-29320)
- try to open code-server installed as PWA via Chrome on Windows
- testing workarounds like https://github.com/shengyou/vscode-handler
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1 -
🎉 1