-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
[Plan Item] Propose new Webview API #43713
Comments
Initial version of API taken into proposed with #42690 |
Proposed API changes for next iteration:
|
Part of #43713 Adds a new api `onDidChangeActiveEditor` which generalizes `onDidChangeActiveTextEditor` to also detect switches to and from webviews. This API replaces the `Webview.onBecameActive` and `Webview.onBecameInactive` events previously prototyped.
Part of #43713 Second try at refining the webview api. This pass specifically looks at managing webviews. Major changes: - Adds an `id` field to webviews. The id is provided by the extension and identifies the webview. It is used with the new event handling apis - Adds a new `onDidChangeActiveEditor` api. This is similar to `onDidChangeActiveTextEditor` but is also fired when you change webviews. It replaces the old `onFocus` and `onBlur` events on the webview itself - Replaces `createWebview` with `getOrCreateWebview`. This new API uses the id and column together as a key. The idea is that only a single webview of id may exist in a given column - Adds an `onDidCloseWebview` api. This is fired when a webview is closed by the user The motivation for these changes is #27983, which tracks using the same markdown preview for any active markdown files. I believe this case is similar to how other extensions may use the webview.
Deleted the comment, was using localstorage, don't need it as I can persist the webview. |
@mjbvz Do we have an event for when a webview is closed? Currently when using ContentProvider (via With this new api, I have no way of determining whether the WebView has been closed or not and whether we need to create a new WebView for display. |
Can we have API for icon/favicon of the webview? |
Part of #43713 Third try at refining the webview api. This pass reworks #44165. Major changes: - Adds an `id` field to webviews. The id is provided by the extension and identifies the webview. It is used with the new event handling apis. - Adds a new `onDidChangeActiveEditor` api. This is similar to `onDidChangeActiveTextEditor` but is also fired when you change webviews. It replaces the old `onFocus` and `onBlur` events on the webview itself - Adds an `onDispose` event ot webviews. This is fired when a webview is closed by the user - Perist webview state when the editor group changes. This is enabled for all webviews, not just those with keep alive.
@DonJayamanne Just sent out a new proposal that introduces an This PR introduces a different model for webviews. There is now a 1:1 correspondence between webviews and "webview editors". Previously, users could split webview editors, resulting in two different webview editors both backed by the same model. This is no longer possible |
Part of #43713 Third try at refining the webview api. This pass reworks #44165. Major changes: - Adds an `id` field to webviews. The id is provided by the extension and identifies the webview. It is used with the new event handling apis. - Adds a new `onDidChangeActiveEditor` api. This is similar to `onDidChangeActiveTextEditor` but is also fired when you change webviews. It replaces the old `onFocus` and `onBlur` events on the webview itself - Adds an `onDispose` event ot webviews. This is fired when a webview is closed by the user - Perist webview state when the editor group changes. This is enabled for all webviews, not just those with keep alive.
* Webview API prototype 3 Part of #43713 Third try at refining the webview api. This pass reworks #44165. Major changes: - Adds an `id` field to webviews. The id is provided by the extension and identifies the webview. It is used with the new event handling apis. - Adds a new `onDidChangeActiveEditor` api. This is similar to `onDidChangeActiveTextEditor` but is also fired when you change webviews. It replaces the old `onFocus` and `onBlur` events on the webview itself - Adds an `onDispose` event ot webviews. This is fired when a webview is closed by the user - Perist webview state when the editor group changes. This is enabled for all webviews, not just those with keep alive. * Throw error when trying to access disposed webview * Improving webview documentation * Clean up dispose management * Throw if we receive a bad handle * Move more event handling to input * Simplify input updating * Remove extra container property * Fixing md security alert button * Remove extra update container call * Restore syncing of preview to active editor * Fixing posting to webview * Debounce preview updates * Remove previewUri * Enable direct window.postMessage instead of window.parent.postMessage * Fixing scroll position not preserved when updating previews * Revert parent.postMessage change. Old behavior was correct * Properly hide webview container on tab switch * Make sure we only handle scroll events for the correct document * Don't try setting negative scroll * Revert vs code whitespace change
Thanks all for the feedback! A few initial proposed changes for this month:
This is just a first set of proposed tweaks. We'll keep refining the API throughout the month. Let me know if you have any other suggestions or feedback Beyond webview 1.0, I'm also thinking about how the API may be able support a few additional cases:
No commitment on these, but I think it is good to think about how these features would play with the currently proposed API /cc @jrieken |
What percentage of the VSCode userbase uses the latest VSCode version? One thing I'm worried about with switching to the new webview is that users of older vscode versions will no longer be able to use my extension. |
👎 |
Please explain |
As discussed, the WebView is not an editor but a UI-part that happens to be positioned like an editor but it must not be like that. Be prepared for showing web views in the bottom panel or as peek view |
🤞 maybe even in the sidebar as its own activity? 😉 🙏 |
@jrieken Our commitment here is getting a better webview api for editors and I do not think we agreed to support webviews other contexts. I see a few options on updating the API to future proof it for such without blocking the original goal:
export interface Webview {
title: string;
html: string;
readonly onDidReceiveMessage: Event<any>;
postMessage(message: any): Thenable<boolean>;
...
}
export interface WebviewEditor {
readonly viewColumn?: ViewColumn;
readonly webview: Webview;
...
} If we go with something like the third approach, I'd be interested in exploring a webview editor API that is more like interface ContentProvider {
provideContent(uri: Uri, token: CancellationToken): Webview;
}
function registerContentProvider(scheme: string, provider: ContentProvider): Disposable as this would let us implement restoration. |
I don't think agreement is need here but projecting what will happen in the future. The request for webviews everywhere will come (if it's not already there), we can ignore it for a while, and then we'll implement it. Knowing that, we should design for it which means don't plan for deprecation nor duplication.
That's planning for duplication.
I might be missing something but I believe we need
Interesting. It would be similar to the pull model the tree view is using. I have discussed something similar with @sandy081 today because tree views started with the pull model (data provider) and are now mutating into a push model |
Just for reference the request for webviews in other contexts does already exist: #43049 (there are probably other requests as well) and TBH I have a very real need for that support (a webview in at least the sidebar or panel) for a new extension I'm working on. |
* Promote webview Api to stable Fixes #43713 Fixes #28263 * Rename position back to viewColumn and mark viewColumn as deprecated This allows us to more easily re-introduce a `position` property once we have gridlayout * Move dispose methods onto webview itself Also better hide a few 'internal' methods / properties on the panel / webview * Revert "Move dispose methods onto webview itself" This reverts commit 8fab6cc. * Move title onto webview panel * Use _ names for private setters * Remove unused emitter and dispose onMessageEmitter * Preview internal emitters with _
@mjbvz Is there a way to focus a webview when its already visible? The |
This is what |
Yeah today's. It will focus it if it changes viewcolumns but if it is already in col 3 but another tab in col 1 or 2 is focused and I reveal to col 3 it doesn't focus it |
Can you open an new issue. Also are you calling it with the view column: |
Out right now but will do when I get back. Basically. |
Follow up on #41047 which explored improving the webview API. Part of #28263
This iteration we'd like to move the new API to be a fully documented proposed API and also self-host the markdown extension on the new API
The text was updated successfully, but these errors were encountered: