fix(webview): increase focus retry count for copyImage - #328569
Open
RITHIKKUMARAN wants to merge 1 commit into
Open
fix(webview): increase focus retry count for copyImage#328569RITHIKKUMARAN wants to merge 1 commit into
RITHIKKUMARAN wants to merge 1 commit into
Conversation
Author
|
@microsoft-github-policy-service agree |
RITHIKKUMARAN
force-pushed
the
fix/webview-clipboard
branch
from
August 2, 2026 17:54
afc7d83 to
47a4a9d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #199981
Description
This PR addresses the long-standing issue where users are unable to copy images to their system clipboard via the right-click context menu inside webviews (such as Markdown Previews and Notebook outputs).
Root Cause:
When the VS Code custom context menu is invoked via a right-click, the webview
iframeloses document focus. Becausenavigator.clipboard.write()strictly requires an active, focused document, it fails with aNotAllowedErrorif invoked while the context menu still holds focus. The existing code attempted to wait for focus to return, but the retry limit was set to only5retries at very short intervals (100-250ms total), which is frequently insufficient for the UI to return focus to the webview.Proposed Changes:
retriesparameter inwebviewPreloads.ts(Notebooks) from 5 to 50.retriesparameter inpreview-src/index.ts(Markdown) from 5 to 50.This gives the webview up to 1 - 2.5 seconds to regain focus before executing the clipboard write operation, completely mitigating the timing race condition without introducing any blocking delays.
How to test