vscode: Extension Activation on web is not fired for each local folder opened

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

  • VS Code Version: web
  • OS Version: MacOS Big Sur / MSEdge and Safari

Steps to Reproduce:

Maybe. I’m missing something, but it seems the extension activation in web extensions works a bit different compared to desktop.

I mean, in desktop, the regular activate function is fired every time a workspace is opened, respecting of course what you defined in activationEvents. which in my case, is * yet. In web (http://vscode.dev to be more precise), it seems the extension is activated only once when you navigate to http://vscode.dev. And no matter how many local folders you open, the activate function is not called anymore.

I’m using the side load approach to test my extension in web, and noticed this behavior because I use workspaceFolders while in the activation event to manage some data used on my extension. In web, this is returning undefined, even after I opened some local folder.

I didn’t find any documentation nor any issue that points to this behavior, so I wonder I’m doing something wrong.

On the other hand, I could see the onDidChangeWorkspaceFolders being fired when you open a different folder, but based on API Docs, this event should be fired only when you add/remove some folder from a workspace.

Also, I’m not sure another issue is being caused by the side load approach (just like debugging extensions does) but the activationEvents is not being respected on web. I changed my extension to workspaceContains:somefile and it was activated even on an empty workspace.

Thank you

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (10 by maintainers)

Most upvoted comments

Yeah…as I said, maybe I’m mistaken. In this case, I probably am 😆

To clarify: we only force an empty MR workspace onto you for when you open vscode.dev / insiders.vscode.dev. Once you go to a remote, that changes.

In other words, in web, without a server, the empty window experience is that empty MR workspace where you can open local folders in if the browser supports that. And when you do, immediately the first folder will change and thus most likely restart the extension host.

On desktop, when you open a folder, the window reloads into that folder.

So yeah, there is a difference.

Forgot to mention: when you open vscode.dev we immediately bring you into a multi root workspace that is empty. The reason is that MR workspaces are the only ones that allow to add and remove folders without reload and that is required for accessing local files. The MR workspace is a bit special in that it uses an in-memory fs provider, but that should not have any impact here.

@alexdima as for restarting extension host when the first folder changes, please chime in to https://github.com/microsoft/vscode/issues/69335 which discusses that and the consequences. I think that issue is currently not seeing any progress.

Specifically there are calls to restart the extension host that are probably also going to restart the web worker (you would have to tell):

https://github.com/microsoft/vscode/blob/ef70f99af7c90bb37f6dbb797c36de76a51ba73b/src/vs/workbench/contrib/relauncher/browser/relauncher.contribution.ts#L153

https://github.com/microsoft/vscode/blob/99ef89977578a3b799f95fedf697590f7280a4ee/src/vs/workbench/services/workspaces/electron-sandbox/workspaceEditingService.ts#L184

That is when:

  • entering a workspace (because that changes the workspace ID and thus storage location for extensions)
  • changing the first folder (because that changes workspace.rootPath)

In web, this is returning undefined, even after I opened some local folder.

@alefragnani can you isolate this in a small sample to look at?