microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.05k stars 28.8k forks source link

Copy & Paste support for Simple Browser #182011

Open gogobd opened 1 year ago

gogobd commented 1 year ago

It's not possible to copy from or paste to the integrated Simple Browser. This feature might be very simple to implement and would bring a lot of benefit with it.

weartist commented 1 year ago

I'll try to fix this

ericzhucode commented 1 year ago

What do you mean by integrated Simple Browser? Do you mean customized webview?

gogobd commented 1 year ago

The thing that comes up when I press F1 and type "Simple"

Screenshot 2023-06-03 at 10 57 25
ericzhucode commented 1 year ago

The thing that comes up when I press F1 and type "Simple"

Screenshot 2023-06-03 at 10 57 25

Just on my side, I can copy from & paste to the website opened by Simple Browser command. (with version 1.78) Can you give us a sample url which is not functioning as expected?

weartist commented 1 year ago

My side can also copy, need an example of the bad case

gogobd commented 1 year ago

I was trying to have "https://doc.sccode.org/" ope alongside with my code.

weartist commented 1 year ago

I was trying to have "https://doc.sccode.org/" ope alongside with my code.

thanks, I'll try to fix it

weartist commented 1 year ago

@gogobd @mjbvz It seems that this problem was caused by the iframe. We cannot listen to events inside the iframe. It seems that this is currently an unsolvable problem TAT?

gogobd commented 1 year ago

I wonder where the event would get lost, it copy & paste from a separate browser works fine.

ArchieAtkinson commented 1 year ago

I can provide an additional example that just lead me to this thread: https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/init.html

gjsjohnmurray commented 1 year ago

@gogobd @mjbvz It seems that this problem was caused by the iframe. We cannot listen to events inside the iframe. It seems that this is currently an unsolvable problem TAT?

So maybe related to #182642

gogobd commented 1 year ago

I wonder why this isn't handled by the "outside" OS

dtinth commented 1 year ago

This is happening on my Mac.

To reproduce:

  1. Command Palette > Simple Browser > Show > https://example.org
  2. Highlight the text "Example Domain"
  3. Attempt to copy it

    • Right click
      • Expected - Show a context menu with "Copy" item
      • Actual — Nothing happens
    • Press Cmd+C
      • Expected — The text is copied
      • Actual — Nothing happens
    • Menu bar > Edit > Copy
      • Expected — The text is copied
      • Actual — Nothing happens, although the menu item not disabled.
Version: 1.81.1 (Universal)
Commit: 6c3e3dba23e8fadc360aed75ce363ba185c49794
Date: 2023-08-09T22:20:33.924Z
Electron: 22.3.18
ElectronBuildId: 22689846
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Darwin arm64 22.5.0
gogobd commented 1 year ago

Thanks for confirming!

dtinth commented 1 year ago

From further testing, it appears that Simple Browser running inside VS Code for the Web does not suffer from this problem (I can copy text from the page inside the Simple Browser just fine).

Therefore, this issue seems to only affect Electron-based builds.

gogobd commented 11 months ago

I tried again with VSC (macOS)

Version: 1.83.0 Commit: e7e037083ff4455cf320e344325dacb480062c3c Date: 2023-10-03T16:13:10.518Z (1 wk ago) Electron: 25.8.4 ElectronBuildId: 24154031 Chromium: 114.0.5735.289 Node.js: 18.15.0 V8: 11.4.183.29-electron.0 OS: Darwin arm64 22.5.0

and the Problem still exists...

gogobd commented 10 months ago

Any news on this?

gogobd commented 8 months ago

Has there been any progress?

noPounch commented 6 months ago

Also facing this issue on mac, bumping for exposure. I have to inspect the html to copy

ankitaabad commented 6 months ago

I am also facing the same issue not working with https://mantine.dev Any progress on this?

gogobd commented 6 months ago

I just tried this again after quite some time and the issue is still there. Now I have Version: 1.87.2 (Universal) Commit: 863d2581ecda6849923a2118d93a088b0745d9d6

gogobd commented 6 months ago

I'm particularly interested in being able t copy from https://doc.sccode.org/ and that still doesn't work. I also noticed that I can't get a context menu either when I right-click in the Simple Browser window (sometimes keyboard-shortcut ⌘-C does not work while selecting "copy" from a context menu does). Unfortunately there's no workaround, still.

jmcphers commented 4 months ago

I poked around a little in the code for for this one.

graph TD
vscode --> c[overlay webview container] --> i2[webview iframe/index.html] --> i3[viewer iframe] --> i4[content iframe - different origin]
i3 -- click --> ch[click handler] -- did-context-menu postmessage --> i2

The iframe that loads the Simple Browser (the "content iframe" above) is literally three iframes deep in the stack. Context menus work in ordinary webviews (two iframes deep) because of an event handler that generates window messages.

However, the content iframe (where the Simple Browser loads URLs) doesn't have event handlers attached. This isn't an oversight; it's a result of security policy. You can't listen in on events generated from frames with a different origin.

So there's probably not going to be a simple fix here. One approach would be to put some sort of event-absorbing glass over the webview so we can intercept events before they reach it. Another would be to add in a proxy layer that injects key/mouse event handlers into the HTML that's loaded in the Simple Browser, such that those events get forwarded out as window messages that can be handled in the same way as they are one layer up.

qiyx2019 commented 3 weeks ago

you can try this code in your iframe

document.addEventListener('keydown', function (event) {
        if ((event.metaKey || event.ctrlKey) && event.key === 'v') {
          document.execCommand('paste');
        }
      });