Skip to content
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

input cannot focus when switching webview #84216

Closed
roguexiaohuihui opened this issue Nov 8, 2019 · 6 comments
Closed

input cannot focus when switching webview #84216

roguexiaohuihui opened this issue Nov 8, 2019 · 6 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug *duplicate Issue identified as a duplicate of another issue(s) help wanted Issues identified as good community contribution opportunities webview Webview issues
Milestone

Comments

@roguexiaohuihui
Copy link

Issue Type: Bug
I created a webview with just an input tag in it, and I just asked input.focus()

1、The first time you open the webview you can focus properly
image
2、Switch to another document or webview
image

3、So let's go back to the first step, the webview,the focus is gone,just click the mouse down the webview and the focus will work

VS Code version: Code 1.39.0
OS version: Windows10

@mjbvz
Copy link
Collaborator

mjbvz commented Nov 9, 2019

I can't repo in the current insiders builds (1.41). Please share the example extension

@mjbvz mjbvz added info-needed Issue requires more information from poster webview Webview issues labels Nov 9, 2019
@roguexiaohuihui
Copy link
Author

roguexiaohuihui commented Nov 11, 2019

I can't repo in the current insiders builds (1.41). Please share the example extension

I created a simple demo, modified with webview official instance, please help to look at this problem:
https://github.com/roguexiaohuihui/input-focus

@roguexiaohuihui
Copy link
Author

when switching webview, the plug-in transmits a signal to webview through message and actively asks the input of webview to focus again. Instead of the input being focused after the mouse click on the screen

@roguexiaohuihui
Copy link
Author

@mjbvz I hope you can take a look at this problem when you are free

@mjbvz mjbvz added this to the May 2020 milestone Apr 15, 2020
@mjbvz mjbvz modified the milestones: May 2020, June 2020 Jun 1, 2020
@mjbvz mjbvz removed the info-needed Issue requires more information from poster label Jun 29, 2020
@mjbvz mjbvz modified the milestones: June 2020, Backlog Jun 29, 2020
@mjbvz mjbvz added the help wanted Issues identified as good community contribution opportunities label Jun 29, 2020
@mjbvz mjbvz added the bug Issue identified by VS Code Team member as probable bug label Nov 3, 2020
@mjbvz
Copy link
Collaborator

mjbvz commented Nov 10, 2020

There are are few different issues here:

  • The example extension calls this._update(); which reload the webview every time the focus changes.

  • However even if you fix that, the bug still exists.

  • I then pushed a fix for this issue (2815e73), but that fix only work with iframe based webveiews

  • It is not fixed for normal electron based webviews. The root problem is that we see the following sequence of actions when switching focus:

    • The extension's focus message is received by the extension's JS
    • This focuses the input element
    • Our host.onMessage('focus', () => { event handler is then invoked
    • At this point, the document.activeElement is now pointing to the wrong element (it's not on the input element anymore).

Since this works fine with iframe based webviews, I assume there is some weird electron specific behavior going on here. I can't track down who is setting the focus here between the extension code running and host.onMessage running

I'm going to close this issue since we have not seen many other reports of it. Hopefully it will be fully fixed on desktop VS Code by #83188

@mjbvz mjbvz closed this as completed Nov 10, 2020
@mjbvz mjbvz added *out-of-scope Posted issue is not in scope of VS Code *duplicate Issue identified as a duplicate of another issue(s) and removed *out-of-scope Posted issue is not in scope of VS Code labels Nov 10, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Dec 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug *duplicate Issue identified as a duplicate of another issue(s) help wanted Issues identified as good community contribution opportunities webview Webview issues
Projects
None yet
Development

No branches or pull requests

2 participants