-
Notifications
You must be signed in to change notification settings - Fork 28.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
WebView optionally add "allow-modals" to iframe sandbox options #67109
Comments
Note: By default if enableScripts is false - then dialog like "alert" will work - but when enableScripts is set to true, they won't. See: https://googlechrome.github.io/samples/block-modal-dialogs-sandboxed-iframe/ |
What do you need modals in a webview for? |
In my immediate case they are for confirmation dialog boxes: "Are you sure you want to delete? [Y][N]". These dialog boxes are created by calling: window.confirm("Ok to delete row?") See: https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm FWIW In my case I am displaying a table of JSON data in the webview and the user can add and delete rows... According to the docs they will work when scripts are disabled - but once scripts are enabled, then you also need this new flag... |
Use the VS Code quick input API for this. Webviews can talk to your extension using postMessage. Normal web modal dialogs are less functional and would feel out of place in VS Code |
@mjbvz - is there a way to make postMessage a non async call? Assuming we wanted to hook the window.confirm function:
Note: These confirm dialogs might be buried deep inside third party JS libs... Should I open a new issue to request VSCode to automatically hook the standard dialogs:
|
@mjbvz - Fair point, but is that a strong enough reason for not allowing them? |
No, there is no sync message passing apis for webviews. If you want to force a user response before continuing, try setting You can write an adapter for |
@mjbvz - That means it will be impossible to replace the window confirm/alert/prompt dialogs (at a global level) with a message passing alternative like you suggested (can you elaborate how you would make the alert hook work via a PostMessage). So to recap -
and this is "by design", I assume this means you wouldn't consider a pull request with the capability added? |
The ability to enable "allow-modals" as a sandbox attribute of the webview hosting iframe.
This would be similar to the "enableScripts" options currently available in the WebView options:
Would produce:
The text was updated successfully, but these errors were encountered: