Skip to content

feat(ios): expose clipboard get/set in the iOS action space - #2956

Open
zubeyralmaho wants to merge 2 commits into
web-infra-dev:mainfrom
zubeyralmaho:feat/ios-clipboard-action
Open

feat(ios): expose clipboard get/set in the iOS action space#2956
zubeyralmaho wants to merge 2 commits into
web-infra-dev:mainfrom
zubeyralmaho:feat/ios-clipboard-action

Conversation

@zubeyralmaho

Copy link
Copy Markdown

Depends on #2954. That PR adds the underlying IOSDevice.getClipboardText() /
.setClipboardText() methods. Until it merges this PR shows both commits; the
first one is #2954 and is not part of the review here.

What

Registers two iOS-specific actions in IOSDevice.actionSpace():

  • IOSGetClipboard — no params, returns the pasteboard text
    (alias agent.getClipboardText())
  • IOSSetClipboard{ text }, writes plain text to the pasteboard
    (alias agent.setClipboardText())

Why

#2954 adds the device-level pasteboard methods, but nothing wires them into the
action space — so they are reachable only from hand-written code. The planner has
no tool for them, which means a prompt like "copy the invite link and read it
back"
cannot work today.

That is the case the capability exists for. A value behind a native "Copy" action
— a share sheet's "Copy Link", for instance — is rendered nowhere on screen, so it
cannot be located or extracted; and WDA's GET /source returns 500 while a share
sheet (UIActivityViewController) is presented, so the accessibility tree is no
help either. Reading the pasteboard is the only path, and it is only useful to an
agent if the agent can actually choose it.

Design note

Both actions are registered locally in packages/ios/src/device.ts, following the
existing IOSHomeButton / IOSAppSwitcher pattern for iOS-specific actions,
rather than as canonical cross-platform actions in @midscene/core.

A canonical ClipboardGet / ClipboardSet pair would be defensible — three
backends already exist in the repo (iOS via WDA here, Android via dumpsys,
desktop via clipboardy in packages/computer/src/device.ts, currently used only
internally for typeViaClipboard). But that touches core's action registry and is
a naming/schema decision for maintainers, so it is deliberately left out of this
PR. Happy to open an issue for it if there is interest.

Validation

  • npx nx test ios — 13 files, 163 tests passed (2 new, covering dispatch through
    actionSpace() into the WDA client for both directions)
  • npx nx build ios — success
  • pnpm run lint — clean

Add IOSWebDriverClient.getPasteboard()/.setPasteboard(), the low-level
POST .../wda/getPasteboard and .../wda/setPasteboard calls (base64
content, contentType: "plaintext"), and IOSDevice.getClipboardText()/
.setClipboardText() as the public, ergonomic wrapper.

There was previously no way to read a value that an app only exposes
through a native "Copy" action (e.g. a share sheet's "Copy Link" for a
generated invite/meeting link) -- WDA's own GET /source also cannot help
there, since it 500s while a native share sheet (UIActivityViewController)
is presented and its accessibility tree cannot be walked. The pasteboard
is WDA-native and system-wide, so it works regardless.

The request shape (POST + JSON body, not GET + query string) is
cross-checked against the unmerged web-infra-dev#2628, which shipped passing unit
tests against this exact endpoint contract.

Test plan:
- npx nx test ios (151 passed)
- npx nx build ios
Wire IOSDevice.getClipboardText()/.setClipboardText() into actionSpace() as
the IOSGetClipboard and IOSSetClipboard actions, following the existing
IOSHomeButton / IOSAppSwitcher pattern for iOS-specific actions.

Without this the pasteboard methods are reachable only from hand-written
code: the planner has no tool for them, so a prompt like "copy the invite
link and read it back" cannot work. IOSGetClipboard is what makes a value
that exists only behind a native "Copy" action (e.g. a share sheet's "Copy
Link") usable inside a plan, since such a value is rendered nowhere on
screen and cannot be reached by locating or extraction.

Both actions are registered locally rather than as canonical cross-platform
actions in @midscene/core, matching how the other iOS-specific actions are
declared. interfaceAlias also exposes them as agent.getClipboardText() and
agent.setClipboardText().

Test plan:
- npx nx test ios (163 passed)
- npx nx build ios
- pnpm run lint
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