Skip to content

Avoid the clipboard when hidden Monaco models can be verified - #754

Merged
leeguooooo merged 3 commits into
leeguooooo:mainfrom
euvoor:fix/monaco-clipboard-free-model
Oct 27, 2026
Merged

leeguooooo merged 3 commits into
leeguooooo:mainfrom
euvoor:fix/monaco-clipboard-free-model

Conversation

@euvoor

@euvoor euvoor commented Oct 26, 2026 •

Copy link
Copy Markdown

What and why

Hidden Monaco APIs currently send fill and get value through the shared system clipboard. This adds avoidable clipboard ownership and restoration risks when the editor's public model API is still retained in its handler module scopes.

Resolve that API through bounded CDP descriptor inspection, match its editor to the exact DOM root, then use native select-all/insert-text and verify the same live model. get value reads the model directly. This path reports engine: monaco-native, never accesses the Clipboard API, and refuses changed models, lost focus and mismatched readback without retrying through the clipboard.

If discovery finds no usable API before input, the existing clipboard fallback remains. This is a measured mitigation for #747, not a claim of atomic clipboard restoration or compatibility with every Monaco bundle. Native clipboard formats, context loss and the fallback's separate compare/write operations retain their documented limitations. The existing global Monaco API path is unchanged.

Stealth mode

  • Nothing here is visible to the pages chrome-use drives beyond the requested focus and native input.

No added globals, DOM properties, attributes, styles, listeners or network requests. Discovery reads existing handler descriptors and skips global scopes; read-only public model access uses the existing rich-editor main-world exception. Private handles belong to a CDP object group released on ordinary exits. Input uses CDP and the existing per-process humanize cadence. There is no synthetic copy/paste or event fallback in the new path.

Tests

All execution uses disposable GitHub-hosted runners and fresh fixture profiles, retaining the Chrome sandbox for headed acceptance. No local browser, user clipboard or authenticated profile was used.

  • Hosted production acceptance: 24 fills and 24 reads across launch/relay, original/minified Monaco 0.57.0 bundles, two independent editors and Unicode multiline/300-line/empty values. Exact model values, the untouched other editor, focus, clipboard bytes and page globals verified. Nonempty trusted events, no copy/paste and zero Clipboard API calls.
  • Wrapped-handler fixtures exercise the unchanged clipboard fallback; existing backup/focus/restore/input/concurrent-write controls pass alongside real Lexical and ProseMirror acceptance.
  • Three protocol tests and ten new payload tests cover exact identity, unavailable/ambiguous APIs, changed/disposed models, focus refusal, input mismatch and object-group cleanup. All passed, along with the sixteen existing clipboard payload tests, formatting, compilation and screenshot/relay regressions.
  • The production branch is rebased on df898066. Additional hosted controls verified refusal after real model swaps, lost focus and rejected input, and preserved concurrent clipboard writes in both modes. The first additional run failed in fixture cleanup when it tried to restore an automatically disposed model. The corrected rerun passed all 36 checks, including all eight live focus/model/input/concurrent-write controls and all 24 fill/read cases. Tested combined source a04cb180, with production Monaco source matching this PR; binary SHA-256 5dd2a48076101c8b0af657227b0eaee373b930a9d9d85ef3f5397b67a8388d8b. All upstream CI checks pass at cd91dd94. The same run reproduced the remaining fallback restore race: a real clipboard write between comparison and restoration is overwritten despite successful editor readback. This is evidence of the limitation, not a safety pass; the proposed residual contract remains open.

Docs

  • Help, README (EN/ZH), core command references and command/interaction docs (ZH/EN) updated.
  • Changelog entries remain part of the maintainer's release preparation.

Part of #747. Please retain that tracker for the residual clipboard/platform contract rather than treating this PR as resolving every limitation.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fd0df1a4-798a-4989-b124-5609e7fd3421
Commits

Reviewing files that changed from the base of the PR and between df89806 and cd91dd9.

Files selected for processing: 16
  • .github/workflows/ci.yml
  • README.md
  • README.zh.md
  • cli/src/native/element.rs
  • cli/src/native/interaction.rs
  • cli/src/native/mod.rs
  • cli/src/native/monaco_model.js
  • cli/src/native/monaco_model.rs
  • cli/src/native/monaco_model_tests.rs
  • cli/src/output.rs
  • docs/commands.html
  • docs/en/commands.html
  • docs/en/interacting.html
  • docs/interacting.html
  • scripts/monaco-model.test.js
  • skill-data/core/references/commands.md

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Walkthrough

Adds clipboard-free Monaco model access for fill and value reads when a matching editor API is available. The implementation verifies model identity and readback, and retains clipboard fallback when discovery finds no usable model before input.

Changes: Monaco native model access

Layer / File(s) Summary
Model discovery and operations
cli/src/native/monaco_model*, scripts/monaco-model.test.js, .github/workflows/ci.yml
Adds bounded CDP discovery and exact-editor matching. Native model reads and writes validate focus and readback. Tests cover matching, cleanup, and failure cases; CI now runs the helper tests.
Fill and read integration
cli/src/native/interaction.rs, cli/src/native/element.rs, cli/src/native/mod.rs, cli/src/output.rs, README*, docs/*, skill-data/core/references/commands.md
fill tries native model access before clipboard fallback. Value reads use the same native access path before falling back to clipboard. Help and documentation describe these paths and their failure behavior.

Priority: Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant fill as fill
  participant access as monaco_model::access
  participant model as Monaco model
  participant fallback as Clipboard fallback
  fill->>access: Request native fill for target editor
  access->>model: Focus, insert text, read and verify
  alt Model found and verified
    model-->>fill: Return verified value
  else No usable model found before input
    access-->>fill: Return no model
    fill->>fallback: Use existing clipboard path
  end
Loading

Possibly related issues

  • leeguooooo/chrome-use#747 — Adds the requested clipboard-free Monaco path, but retains the clipboard fallback and its concurrency limitations.
  • leeguooooo/chrome-use#745 — Adds editor API detection for Monaco fill; the reported Ace editor case is not covered.

Suggested reviewers: leeguooooo

Merge Risk: Minimal · up to cd91d

The native Monaco path and its clipboard fallback have no established issue requiring a change before merge. Discovery failures remain visible errors rather than triggering another action.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 21.05% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 8 files. (8 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title states the main change: fill and get value on Monaco editors avoid the shared clipboard when a hidden Monaco model API can be verified. The changeset matches this. It adds a CDP-based native…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the required template. It explains the change and motivation, addresses stealth behavior and gating, lists comprehensive tests and environments, and confirms documentation upda…
Full details: Title check

Explanation

The title states the main change: fill and get value on Monaco editors avoid the shared clipboard when a hidden Monaco model API can be verified. The changeset matches this. It adds a CDP-based native input path, reads models directly, and keeps the clipboard only as a fallback.

Full details: Description check

Explanation

The description follows the required template. It explains the change and motivation, addresses stealth behavior and gating, lists comprehensive tests and environments, and confirms documentation updates. Changelog entries are explicitly deferred to release preparation, which is acceptable for this change.

Full details: Docstring Coverage

Explanation

Docstring coverage is 21.05% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 8 files. (8 skipped: 8 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

2 participants