Change:
import { IWebviewService, WebviewElement } from 'vs/workbench/contrib/webview/browser/webview'; import { asWebviewUri } from 'vs/workbench/contrib/webview/common/webviewUri'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; <del> import { dirname } from 'vs/base/common/resources'; </del> <ins> import { dirname, joinPath } from 'vs/base/common/resources'; </ins> import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { Schemas } from 'vs/base/common/network'; <ins> import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs'; import { IFileService } from 'vs/platform/files/common/files'; import { VSBuffer } from 'vs/base/common/buffer'; import { getExtensionForMimeType } from 'vs/base/common/mime'; </ins> export interface WebviewIntialized { __vscode_notebook_message: boolean;

Discussion:
<!-- Do Not Delete This! featurerequesttemplate --<!-- Please read our Rules of Conduct: --<!-- Please search existing issues to avoid creating duplicates. --<!-- Describe the feature you'd like. --Python Notebook implementation has special code to handle click events of links containing an ObjectUrl (href=blob:....). I'm hoping VS Code would handle this natively as these links allow users to save blobs as files. This is generic enough that it need not be something special to the Python implementation. Would benefit anyone using the new VSC API to display HTML that allows saving images. Current Python Notebook implementation: We handle all click events in document If target element === and starts with . Then we get the blob contents and send it to extension On extension side we prompt user to save the file using . /cc
what is the use case for this?
Sure, a user could render a plotly plot and such plots can contain links to save images, and those hrefs have a ref to object urls. This isn't specific to Python extension, any HTML could have markup that allows users to save images . Also, opening such a plot in other notebook viewer, user is able to click such links and save the images. If this isn't address, then VSCode displays an empty page in notebook with an error message (see below). I think this is due to the fact that href results in nativigating the current page to url=blob://. & again, we can address this with a custom renderer, however I believe this is generic enough for VSC to handle. ! !
TIL about the API. Should this also work for URLs?
Good pick. I would say yes. At the end of the day someone could render a link with a download attribute
To do this for blob ULIs, I have to download the contents of the URL in the context of the webview, and pipe it back to vscode to write to a file. Data URLs are easier, I can just open it in a browser. Maybe an experience in vscode would be nicer though. Where are these urls coming from in your case, some 3rd party renderer code or your extension code?
3rd party That's exactly what we have in our python extension when using the webview.

I thought this would be generic enough for VSCode to handle, as others could end up with similar scenarios, at the end of the day it's from a 3rd party package.
Yeah, I think it makes sense for us to handle this as well.
Do you have an example of a notebook that has this button? Is this from ipywidgets?
Also can you link me to the code that handles this in your extension?
No, its plot generated by plotly. Here's the code required to generate such a plot:
I thought this was working on Wednesday, but now I get a CORS error when I fetch any blob URL from the webview code. Did you do anything to handle this? I don't understand why it's working in your webview and not mine. Maybe we are making webview changes right now that might affect this.
U might have to setup the csp (for data and blobs), this here's what we have: