Skip to content

fix: use documentReady instead of documentComplete in HUD methods#4911

Open
xiaolongnk wants to merge 2 commits into
philc:masterfrom
xiaolongnk:fix/copy-paste-on-loading-page
Open

fix: use documentReady instead of documentComplete in HUD methods#4911
xiaolongnk wants to merge 2 commits into
philc:masterfrom
xiaolongnk:fix/copy-paste-on-loading-page

Conversation

@xiaolongnk

@xiaolongnk xiaolongnk commented Jun 12, 2026

Copy link
Copy Markdown

Problem

On pages whose load event is delayed (slow external resources, network stalls,
or intentionally hung requests), pressing yy to copy the URL silently does
nothing: the URL is never written to the clipboard and the "Yanked" feedback
HUD never appears.

Root cause: HUD.show(), HUD.showFindMode(), HUD.copyToClipboard(), and
HUD.pasteFromClipboard() all call await DomUtils.documentComplete(), which
waits for the load event. If that event is delayed, all HUD operations are
blocked for the same duration.

Fix

Replace documentComplete() (waits for load) with documentReady() (waits
for DOMContentLoaded) in all four methods.

documentReady() already handles all readyState cases correctly: it resolves
immediately when document.readyState !== \"loading\" and only adds a
DOMContentLoaded listener when the page is still in the loading state.
The HUD is a chrome-extension:// iframe overlay with its own independent
lifecycle — it does not depend on the host page's external resources finishing.

showClipboardUnavailableMessage is intentionally left on documentComplete()
since it is only emitted after a clipboard operation has already been attempted.

Testing

  1. Open a page that stalls at the load event (e.g. one with a slow/hanging
    external resource, or use DevTools to throttle network after DOMContentLoaded).
  2. Press yy — before this fix the HUD would stay silent until the page fully
    loaded; after the fix the "Yanked" notification appears immediately and the
    URL is in the clipboard.
  3. Verify yy still works normally on fully-loaded pages.

…ations

copyToClipboard and pasteFromClipboard were awaiting documentComplete()
(the page load event) before constructing the HUD iframe. This caused
yy / copy commands to silently defer on still-loading pages until all
resources finished loading.

documentReady() (DOMContentLoaded) is sufficient to inject the HUD
iframe into the DOM and is what the init() path itself already uses.
This makes copy/paste work immediately when the DOM is available,
regardless of whether the page has fully loaded.
show(), showFindMode(), copyToClipboard(), and pasteFromClipboard() all
waited for the load event (documentComplete) before initializing the HUD
iframe. On a page whose load event is delayed (slow external resources,
never-completing requests), pressing yy would silently do nothing: neither
the URL was copied nor the 'Yanked' feedback appeared.

documentReady() (DOMContentLoaded) is sufficient — the HUD is a
chrome-extension iframe overlay independent of the page's resource load.
showClipboardUnavailableMessage is left on documentComplete since it is
only shown after a copy attempt already completed.
@xiaolongnk xiaolongnk changed the title fix: use documentReady instead of documentComplete for clipboard operations fix: use documentReady instead of documentComplete in HUD methods Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant