Skip to content

Trusted domain dialog in web doesn't return focus to previously clicked element when canceled. #170442

Open

Description

@alexr00

This can be trivially reproduced with the GitHub Pull Requests and Issues extension:

  1. Open a pull request on insiders.vscode.dev
  2. In the pull request description, leave a comment with a link to an external domain.
  3. If you've trusted the workspace, set "workbench.trustedDomains.promptInTrustedWorkspace": true
  4. Tab to the link that you made in step 2.
  5. Enter.
  6. In the resulting trusted domain dialog, tab to cancel and cancel.
  7. 🐛 Focus is not restored (this works property on desktop with the native dialog).

Activity

  1. added
    accessibilityKeyboard, mouse, ARIA, vision, screen readers (non-specific) issues
    webIssues related to running VSCode in the web
    on Jan 3, 2023
  2. alexr00 commented on Jan 3, 2023

    @alexr00
    MemberAuthor

    Discovered by the accessibility testing team in microsoft/vscode-pull-request-github#4242

  3. fsteffi commented on Jan 9, 2023

    @fsteffi

    GitHubTags:#A11ySev3;#A11yTCS;#A11yMAS;#DesktopWeb;#Visual Studio Code Client;#WCAG2.4.3;#BM-VisualStudioCode-Win32-Nov2021;

    primary bug:microsoft/vscode-pull-request-github#4242

  4. sbatten commented on Mar 6, 2023

    @sbatten
    Member

    Alex Ross (@alexr00) I'm not sure what I can do on my side. The custom dialog takes the active element before showing and restores it after the dialog is dismissed. In this case, the active element is the iframe for the webview. I think the webview content provider may need to hand focus coming back to the iframe and decide if it should restore focus to the previously active element.

  5. alexr00 commented on Mar 7, 2023

    @alexr00
    MemberAuthor

    SteVen Batten (@sbatten) I assumed that it was fixable by the custom dialog since the issue doesn't happen with the native dialog (and since it is something that will affect all extensions with webviews). Does this need to be fixed by individual extensions?

  6. sbatten commented on Mar 7, 2023

    @sbatten
    Member

    The native dialog doesn't have this issue because it doesn't truly steal focus, its a separate window. In custom dialogs we try our best to restore focus to mimic the behaviour of a native dialog but since the focused element is inside a webview, we need a webview specific solution. After chatting with Matt Bierner (@mjbvz) we propose that the PR extension handle this when the iframe is refocused. I'm not sure if the PR extension keeps some internal focus state to handle tab navigation. However, if there is a general webview solution, we can pull that up. At the dialog level it is impossible for me to properly restore focus to a specific element inside the iframe unfortunately.

  7. removed this from the March 2023 milestone on Mar 20, 2023
  8. 1 remaining item

  9. isidorn commented on Mar 24, 2023

    @isidorn

    Thanks for starting this discussion, and a friendly reminder that we have to tackle this in April for compliance reasons.

    Scott O'Hara (@scottaohara) what do you think? Somewhat similar to our previous webview focus discussion? If the custom dialog returns the focus to the WebView (outer element) would that be enough to reduce severity to 3? Otherwise VS Code can not pass focus back to the exact element as SteVen Batten (@sbatten) explained above.

  10. sbatten commented on Mar 27, 2023

    @sbatten
    Member

    We are already passing focus back to the outer webview at the dialog layer.

  11. isidorn commented on Mar 27, 2023

    @isidorn

    Thanks. Let's see what Scott O'Hara (@scottaohara) says.

  12. scottaohara commented on Mar 27, 2023

    @scottaohara
    Member

    i imagine that'll be the best you can do, assuming these would be cross-origin iframes.... moving focus to the iframe of the webview and then letting the extension teams reset focus back to the last focusable element once focus is re-detected back in the iframe. based on the linked issue, as long as that is a common representation of this issue, it does seem like it'd be fine as a sev3, so long as focus was moved back to the iframe/iframe's container, and not to the browser chrome.

  13. alexr00 commented on Mar 28, 2023

    @alexr00
    MemberAuthor

    I've verified that focus does return to the iframe, but sometimes tabbing from the iframe takes me to the browser chrome. It actually appears to exactly alternate:

    1. Try to repro
    2. See that focus is on the iframe
    3. Tab
    4. Focus is on browser chrome
    5. Try to repro
    6. See that focus is on the iframe
    7. Tab
    8. Focus is inside the webview.

    Matt Bierner (@mjbvz) do you know why tabbing from the outer iframe might do this?

  14. sbatten commented on Apr 10, 2023

    @sbatten
    Member

    Matt Bierner (@mjbvz) do you have any idea why that might be the case?

  15. sbatten commented on Apr 10, 2023

    @sbatten
    Member

    Isidor Nikolic (@isidorn) Scott O'Hara (@scottaohara) how do we get this bumped down to sev3 as discussed?

  16. scottaohara commented on Apr 10, 2023

    @scottaohara
    Member

    fsteffi should be able to help here.

  17. fsteffi commented on Apr 11, 2023

    @fsteffi

    hi SteVen Batten (@sbatten) severity has been reduced

  18. mjbvz commented on Apr 20, 2023

    @mjbvz
    Contributor

    SteVen Batten (@sbatten) Alex Ross (@alexr00) Possibly because the webview is structurally and the end of the dom (outside of the normal workbench dom). We need to do this so that the webview can be moved around without being recreated and destroyed. Not sure why it only sometimes happens though

  19. Mana-swi commented on Aug 14, 2026

    @Mana-swi

    #a11ydb-focus-lost-on-action;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

accessibilityKeyboard, mouse, ARIA, vision, screen readers (non-specific) issuesbugIssue identified by VS Code Team member as probable bugwebIssues related to running VSCode in the web

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions