MicrosoftEdge / MicrosoftEdge/WebView2Feedback

Sample Win32_GettingStarted is unusable with Narrator/keyboard-only (missing minimal focus handling)

Open
#2,956 1 comment 0 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

Description

As of writing, the contents of the WebView2 control in the Win32_GettingStarted sample in WebView2Samples are not interactable using keyboard-only and cannot be read at all using Narrator. I tested this against the sample as of commit fc1269e, as well as the same sample with the current-as-of-writing version of the Microsoft.Web.WebView2 package (1.0.1418.22).

I don't expect the "Getting Started" sample to demonstrate robust cross-control keyboard interactions like the more detailed samples, but it should have sufficient keyboard and screen reader support to provide a comparable experience as a sample to keyboard-only users and to screen reader users.

Version

SDK: 1.0.1418.22
Runtime: Stable 107.0.1418.35
Framework: Win32
OS: Win11, 22H2 22621.674

Repro steps:
  1. Clone the WebView2Samples repo and open /GettingStartedGuides/Win32_GettingStarted/WebView2GettingStarted.sln in Visual Studio
  2. Start Narrator
  3. Build the project (in either debug or release mode) and run without debugger attached

Expected:

  • I should be able to use tab/etc to manipulate the resulting dialog/page, without using a mouse, both at initial launch and after deactivating/reactivating the sample's window
  • Narrator should be able to announce the dialog/page when navigated with a keyboard
  • Narrator should be able to announce web controls on the page when clicking on them with a mouse

Observed:

  • Keyboard controls do not get processed by the WebView2 unless/until the user first clicks inside the WebView2
  • Narrator does not announce anything by default, in response to keyboard controls, or when the window receives focus
  • If I click within the initial alert dialog, Narrator can announce the dialog, but once the dialog is dismissed, Narrator never announces the page, even if I click within the page and move keyboard focus around the page
Analysis

I think the root cause of this is that the sample does not include any provision for moving focus into the WebView2 control. I tested two candidate options for minimal sample updates that both resulted in more reasonable keyboard/Narrator behavior:

  1. Update the "main message loop" section at the bottom of WinMain to include an IsDialogMessage check such that the WebView handles the necessary window activation/tab keyboard events on its own:
        if (!IsDialogMessage(GetAncestor(msg.hwnd, GA_ROOT), &msg)) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
  1. Update WndProc to explicitly invoke webviewcontroller->MoveFocus in response to WM_ACTIVATE events:
case WM_ACTIVATE:
        if (webviewController != nullptr) {
            webviewController->MoveFocus(COREWEBVIEW2_MOVE_FOCUS_REASON_PROGRAMMATIC);
        }
        break;

I think both of these are simple enough to be reasonable inclusions in the "Getting Started" sample. I think the latter is a marginally better screen reader experience for an app that truly is an empty wrapper around the webview and has no other focusable component, but I think the former is probably a better starting point for most readers of the sample in practice, so I'd recommend the former for the purposes of the "Getting Started" sample.

Additional context

This issue was originally filed as https://github.com/MicrosoftEdge/WebView2Samples/issues/156 - I've moved it here per @champnic's offline request

AB#42188981

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

Open GettingStartedGuides/Win32_GettingStarted/WebView2GettingStarted.sln and inspect the main message loop at the bottom of WinMain and focus handling in WndProc. Reproduce with Narrator and keyboard-only input, then verify that the sample receives keyboard focus and Narrator announces the dialog and WebView2 page without requiring a mouse click.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
accessibility, desktop
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.