microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.38k stars 28.62k forks source link

URL handlers can fail if registered too late on startup #222199

Open loganlifts opened 1 month ago

loganlifts commented 1 month ago

Does this issue occur when all extensions are disabled?: Yes

Steps to Reproduce:

  1. Close all VS Code windows but don't exit the application.
  2. Go to an extension page in the VS Code Marketplace in your browser.
  3. Click install on the extension page and allow your browser to open VS Code when prompted.
  4. VS Code will open but it will show the welcome page rather than the extension page for the extension you're trying to install.

This does not occur if I keep a VS Code application window open or if I exit the application entirely before clicking install from the browser.

sandy081 commented 2 weeks ago

@bpasero This seems similar to https://github.com/microsoft/vscode/issues/73101 and the latter was fixed by adding a new workbench contribution that blocks the startup and caches the urls

https://github.com/microsoft/vscode/blob/a628b923ec0abdd3bbd289288b2339c2bf1a2809/src/vs/workbench/services/extensions/browser/extensionUrlHandler.ts#L344-L377

Root cause seems to be that url handlers which are registered later are not being called by the main.

Edit: I would prefer not to follow the above approach for opening extension url handlers. I suggest main to wait until workbench is ready to handle the URLs

https://github.com/microsoft/vscode/blob/c0592918e90ab8ecb24a4fd010403b87474e29f1/src/vs/platform/launch/electron-main/launchMainService.ts#L80-L84

bpasero commented 2 weeks ago

I do not see a problem with the work that @joaomoreno did with the bootstrap script for caching URLs except for these lines:

https://github.com/microsoft/vscode/blob/c0592918e90ab8ecb24a4fd010403b87474e29f1/src/vs/workbench/services/extensions/browser/extensionUrlHandler.ts#L368-L370

We return early here because authority is "". At least with the links from the marketplace.

Steps:

This works fine if a window is opened or VS Code is not running, so I suspect we only have a bug in the lines above.

Image

@joaomoreno can you check?

bpasero commented 2 weeks ago

Oh nevermind, looks like we have 2 handlers for extension URLs, one to open the extension page for installation and one for forwarding a request to an extension. Looks like what I found above is for the latter.

What needs to be fixed is this one:

https://github.com/microsoft/vscode/blob/90c3e495f47fe433fe2f83cbacdf7ce24cf40bf0/src/vs/workbench/contrib/extensions/browser/extensionsWorkbenchService.ts#L2782-L2801

bpasero commented 2 weeks ago

Idea: when open is called we cache URIs that have not been handled and dispatch when registerHandler is called:

https://github.com/microsoft/vscode/blob/7473068e0d7b62bfd4ef4c8f6b86832448ff1d36/src/vs/platform/url/common/urlService.ts#L20-L28