Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NotebookController asWebviewUri does not work for notebooks #121981

Closed
roblourens opened this issue Apr 23, 2021 · 18 comments
Closed

NotebookController asWebviewUri does not work for notebooks #121981

roblourens opened this issue Apr 23, 2021 · 18 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority notebook verified Verification succeeded
Milestone

Comments

@roblourens
Copy link
Member

roblourens commented Apr 23, 2021

Run a remote-ssh notebook that does something like this:

let remoteUri = controller.asWebviewUri(vscode.Uri.file('/datadrive/vscode-notebook-testbed/img.png'));
task.appendOutput(new vscode.NotebookCellOutput([ new vscode.NotebookCellOutputItem('text/html', `<html><img src=${remoteUri!.toString()} /></html>`) ]));

I get a uri https://0.vscode-webview-test.com/vscode-resource/file///datadrive/vscode-notebook-testbed/img.png, and it 404s

cc @mjbvz @rebornix @jrieken @DonJayamanne

@roblourens roblourens added bug Issue identified by VS Code Team member as probable bug notebook labels Apr 23, 2021
@roblourens roblourens added this to the April 2021 milestone Apr 23, 2021
@roblourens roblourens self-assigned this Apr 23, 2021
@roblourens
Copy link
Member Author

roblourens commented Apr 23, 2021

Problem 1 - asWebviewUri needs the webview ID here:

return asWebviewUri(that._initData.environment, String(handle), uri);

Which makes me wonder whether NotebookController is the right place for this function now, since it's not tied to one editor. Or it needs to take a NotebookDocument from the extension too.

Problem 2
If I fix that, it fails here because extensionLocation is undefined:

if (resource.scheme === Schemas.file && extensionLocation?.scheme === Schemas.vscodeRemote) {

I don't know what to do about that because this webview is not associated with one extension. Maybe instead of extensionLocation it should use the root that was selected by if (containsResource(root, requestUri)) { which will be a remote URI

@jrieken
Copy link
Member

jrieken commented Apr 23, 2021

Which makes me wonder whether NotebookController is the right place for this function now, since it's not tied to one editor. Or it needs to take a NotebookDocument from the extension too.

Does the ID have a meaning? Does it matches against some implicit webview id that notebook editors assign? I only reviewed how the internal asWebviewUri function looks and then went with the simple approach - using the controller handle instead of the cumbersome editor id. I might have missed the crucial part here... Tho, the selected controller is likely playing into this as well, e.g when I have two controllers with each having preloads then I should likely reload the webview when switching controllers

@mjbvz
Copy link
Collaborator

mjbvz commented Apr 23, 2021

@jrieken Yes the id in asWebviewUri must be the same id that the webview itself uses

For webview panels, we create the webview id on the extension host side and then send this over to the main process before creating the webview. The confusing part is that the id we create on the extension host side is also used as the handle

For notebooks, I'm not sure if this same model will work or not since a notebookController can talk about multiple different notebook instances, correct?

@roblourens
Copy link
Member Author

Talked to Matt offline, here's a summary

  • Problem 1, the webview URI needs the webview ID
    • This ID is put into the URI domain, and the per-webview service worker checks it when deciding to handle a request -
      if (requestUrl.origin === resourceOrigin && requestUrl.pathname.startsWith(resourceRoot + '/')) {
    • This is a problem when you would have the same notebook content in two split editors. Might just hack around it for notebooks for now but eventually we need to understand whether there are bad implications in security, caching, something else in not using this ID
  • Problem 2
    • I will add an option for the notebook to set that tells the webview to assume the resource will be remote in a remote window
    • A real fix will involve having this information, like the real remote URI in the uri returned from asWebviewUri. Which is not how we normally do things but this is not content that the uri transformer can find

@roblourens roblourens changed the title NotebookController asWebviewUri does not work in remote NotebookController asWebviewUri does not work for notebooks Apr 24, 2021
@roblourens
Copy link
Member Author

roblourens commented Apr 24, 2021

Hey @mjbvz if you get a chance you could look at d5210de. I went with adding a flag for the notebook service worker to ignore the first part of the domain for requests it's intercepting. I think this is ok for now. I really don't like what the extension has to do to pass the editor to asWebviewUri. Will merge before Monday's build.

@DonJayamanne there should be nothing you have to do for this to work.

@DonJayamanne
Copy link
Contributor

ere should be nothing you have to do for this to work.

Great, I'm also mostly done with adding support for Widgets with the new notebook controller changes.
Thanks guys.

@roblourens
Copy link
Member Author

@DonJayamanne if you want to test it, there's a windows build here, you could test with local or desktop remote at least, https://az764295.vo.msecnd.net/insider/d5210de428a4ed692c52cc598573833ec8c60040/VSCode-win32-x64-1.56.0-insider.zip lmk if you need a different platform

@DonJayamanne
Copy link
Contributor

I'll need a mac build, thanks

@roblourens
Copy link
Member Author

@DonJayamanne
Copy link
Contributor

Brilliant, works now, Please feel free to close this issue.

@roblourens
Copy link
Member Author

Will keep it for the real fixes

@DonJayamanne
Copy link
Contributor

Thanks, I've published the insider version of the Juypter exension to marketplace as well.

@DonJayamanne
Copy link
Contributor

Will test on codespaces on monday.

@jrieken
Copy link
Member

jrieken commented Apr 26, 2021

@roblourens I am very much in favour of not requiring the editor-id/instance when calling asWebviewUri. I think it makes the API much harder to work with because you are now in the business of tracking editors. The id is arbitrary but it needs to used symmetrically when creating the web view. I believe using the controller id makes sense because controllers define preloads and when changing controllers we should also reload the webview - at least when the old controller uses preloads that are different from the "new" preloads. Thinking about it: maybe a hash of the preloads is the best id...

@jrieken
Copy link
Member

jrieken commented Apr 26, 2021

related unload discussion: #120747

@roblourens roblourens modified the milestones: May 2021, April 2021 Apr 26, 2021
@roblourens roblourens added the important Issue identified as high-priority label Apr 26, 2021
@roblourens
Copy link
Member Author

Opened #122221 (nice issue number) to continue

@rebornix rebornix added the verified Verification succeeded label Apr 30, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jun 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority notebook verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

7 participants
@roblourens @rebornix @jrieken @DonJayamanne @mjbvz and others