MicrosoftEdge / MicrosoftEdge/WebView2Feedback

How to focus WebView2 in TabControl

Open
#686 4 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug priority-low tracked
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

I've an application with tabs and in each tab there can be a WebView2 instance. In the WebView2 component of the active tab any random html input element can be currently focused. When i switch between tabs in the TabControl as a user I expect the focus to return to the html element that was previously focused for that tab.

I've made a quick example to show my problem:
https://github.com/frankdekker/WebView2RequestFocusExample

image

  1. Place the cursor in the input field of the search engine
  2. Switch to the second tab
  3. Switch back to the first tab
  4. I expect the WebView2 to be focused and my cursor be active in the input field

In MainWindow.xaml.cs you can see I request focus to the WebView2 of that tab.

I'm not quite sure what I should do differently. How should I get the WebView2 focused again?

Thanks in advance. Loving WebView2 so far :)

AB#30938153

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked WebView2RequestFocusExample, especially MainWindow.xaml.cs and its TabControl selection or focus handling. Reproduce the four listed steps, then inspect the WebView2 focus lifecycle and relevant WebView2 API documentation. Done means the active tab reliably restores the previously focused HTML input, with the behavior demonstrated by the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.