Context
Learn about the browser context that exposes the clipboard API
Overview
Theclipboard object reads from and writes to the browser clipboard for the active page or an explicit page. Use it to seed text before pasting into focused fields, inspect copied text, or perform keyboard-driven copy, cut, and paste actions.
Access the clipboard through your Stagehand context:
context.activePage(). Pass a page option when you need to use a specific tab.
Browser clipboard access requires page focus. When you pass a
page argument, Stagehand uses that page for clipboard access, brings it to the front when possible, and makes it the context’s active page before running the operation.Methods
writeText()
Write text to the browser clipboard.The text to write to the clipboard.
Optional page targeting.
readText()
Read text from the browser clipboard.Optional page targeting. Defaults to the active page.
Promise<string> - The current clipboard text.
clear()
Clear the browser clipboard by writing an empty string.Optional page targeting. Defaults to the active page.
paste()
Paste the current clipboard text into the focused element.Optional page targeting and keyboard shortcut configuration.
paste() uses a keyboard shortcut, so the destination element must be focused before calling it.copy()
Copy the selected content from the focused page.Optional page targeting. Defaults to the active page.
copy() sends ControlOrMeta+C, so it copies whatever the page currently has selected.cut()
Cut the selected content from the focused page and place it on the clipboard.Optional page targeting. Defaults to the active page.
cut() sends ControlOrMeta+X, so it cuts whatever the page currently has selected.Code Examples
- Paste Text
- Copy Selection
- Specific Page
Behavior
readText(),writeText(), andclear()grant browser clipboard permissions for the page origin when possible.paste(),copy(), andcut()use keyboard shortcuts and depend on focus and selection state in the target page.

