-
Notifications
You must be signed in to change notification settings - Fork 29.3k
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
macOS: some commands no longer work inside iframe inside webview #65452
Comments
I ran into this problem and thought it was the reason for the plugin at first. |
While this seems to work fine for e.g. markdown preview it does not seem to work for an extension that allows to live preview. Steps:
|
Since we've unblocked the github pr extension and most other users of the webview api, I'm not going to try fixing this for iframe extensions in iteration |
You can try out |
Do we have any workarounds? Similar issue with PlatformIO IDE => platformio/platformio-vscode-ide#606 |
@mjbvz Copy Paste for me (VS Code Insiders - latest version) doesn't work on any of the extension pages within the app. Example trying to copy configuration settings inside of a page that is describing the extension. The keybindings never even register. |
Fix it please! |
@mjbvz could you explain what should be done from the extension side to make it work? I've just downloaded the latest insiders build and it does not work for me:
I opened PIO Home, selected some library example and pressed Cmd+C and a buffer is empty. What is more, the right-click context menu is empty too. These source code of how do we initialize WebView => https://github.com/platformio/platformio-vscode-ide/blob/develop/src/home.js#L47 Thanks! |
@mjbvz can you point me to the code change / commit that fixed the issue? |
@mjbvz could you reopen this issue? |
Is it not working? |
Yes, it does not work. Re-tested again with
|
Please provide repo steps and an example extension that demonstrates this issue |
Could you install https://marketplace.visualstudio.com/items?itemName=platformio.platformio-ide ? It will open PIO Home, then try to copy something from it. |
Confirmed that platformIO still doesn't work @ivankravets Your extension uses an iframe inside a webview to display all of its content. This is why the commands still don't work for PlatformIO but work fine in other webview based extensions. Since this scenario is important to you but not terribly common (or recommended) for webview extensions more broadly, please look into contributing a PR I've update the issue title to make it more clear what is still blocked. |
Thanks that checked it. So, is this issue on our side? Do you have any hints on how to resolve this issue? |
@ivankravets The more I think the problem, the more it seems like something that individual extensions need to workaround. To explain, here's how events such as
However, once you add an iframe inside of a webview, we run into the same problem all over again:
To make matters worse, since the iframes used by most extension (including PlatformIO) are served up in a different origin from the webview itself, there is no way that I'm aware of for VS Code webview's to automatically add keypress listeners into these iframe. This is a dom security limitation and I'm not sure if there is any reasonable workaround. Given that I tried and failed to fix keyboard events for PlatformIO with changes in VS Code itself, I think you should try adding a workaround in your extension itself. Specifically, try adding code into your iframe that rebroadcasts keyboard events up to the webview so it can send then back to VS Code: document.addEventListener('keydown', e => {
window.parent.dispatchEvent(new KeyboardEvent('keydown', e));
}) I tested this and it works in a simple extension |
But for some reason, menu items work (edit -> paste). And since they work, it’s probably possible to somehow use the hotkey. |
@arduinotech I don't see undo and redo working, even using the menus. And remember that we also want keyboard shortcuts for VS Code specific action to work when you are in a webview, such as opening the command palette. These work fine for normal webviews, but not when you are focused on an iframe inside a webview If someone has any ideas of how to workaround this, please let me know (ideally the workaround should also work in browsers but that may be a stretch) |
I have tried rebroadcasting keyboard events on the pdf viewer of LaTeX Workshop. It works well. Because the source of the iframe is In the frame, we call:
In the parent webview, we call:
|
@mjbvz is it possible to pass HTTP link to WebView via Will this resolve the issue without any hooks? |
we have to dispatch keyboard events in the parent window. See microsoft/vscode#65452 Close James-Yu#1406.
@ivankravets Not currently. One reason is that we need to control aspects of the webview's content, such as setting the vscode css variables and the post message scripts The ideal fix would be not to use an iframe inside the webview at all. Then other webview features, such as link handling, should also work as expected |
we have to dispatch keyboard events in the parent window. See microsoft/vscode#65452 Close James-Yu#1406.
I'm closing this issue because, as I explained, I don't think we can workaround it on the VS Code side. Using iframes in webviews is not ideal, but if your extension absolutely need to use them, make sure to rebroadcast the events as described above |
With 8a58c3e some commands no longer work when inside a webview, for example:
The text was updated successfully, but these errors were encountered: