@@ -99,9 +99,11 @@ type BrowserComputerService interface {
9999 GetMousePosition (ctx context.Context , id string , opts ... option.RequestOption ) (res * kernel.BrowserComputerGetMousePositionResponse , err error )
100100 MoveMouse (ctx context.Context , id string , body kernel.BrowserComputerMoveMouseParams , opts ... option.RequestOption ) (err error )
101101 PressKey (ctx context.Context , id string , body kernel.BrowserComputerPressKeyParams , opts ... option.RequestOption ) (err error )
102+ ReadClipboard (ctx context.Context , id string , opts ... option.RequestOption ) (res * kernel.BrowserComputerReadClipboardResponse , err error )
102103 Scroll (ctx context.Context , id string , body kernel.BrowserComputerScrollParams , opts ... option.RequestOption ) (err error )
103104 SetCursorVisibility (ctx context.Context , id string , body kernel.BrowserComputerSetCursorVisibilityParams , opts ... option.RequestOption ) (res * kernel.BrowserComputerSetCursorVisibilityResponse , err error )
104105 TypeText (ctx context.Context , id string , body kernel.BrowserComputerTypeTextParams , opts ... option.RequestOption ) (err error )
106+ WriteClipboard (ctx context.Context , id string , body kernel.BrowserComputerWriteClipboardParams , opts ... option.RequestOption ) (err error )
105107}
106108
107109// BoolFlag captures whether a boolean flag was set explicitly and its value.
@@ -784,6 +786,16 @@ type BrowsersComputerBatchInput struct {
784786 ActionsJSON string
785787}
786788
789+ type BrowsersComputerReadClipboardInput struct {
790+ Identifier string
791+ Output string
792+ }
793+
794+ type BrowsersComputerWriteClipboardInput struct {
795+ Identifier string
796+ Text string
797+ }
798+
787799func (b BrowsersCmd ) ComputerClickMouse (ctx context.Context , in BrowsersComputerClickMouseInput ) error {
788800 if b .computer == nil {
789801 pterm .Error .Println ("computer service not available" )
@@ -1063,6 +1075,47 @@ func (b BrowsersCmd) ComputerBatch(ctx context.Context, in BrowsersComputerBatch
10631075 return nil
10641076}
10651077
1078+ func (b BrowsersCmd ) ComputerReadClipboard (ctx context.Context , in BrowsersComputerReadClipboardInput ) error {
1079+ if in .Output != "" && in .Output != "json" {
1080+ return fmt .Errorf ("unsupported --output value: use 'json'" )
1081+ }
1082+ if b .computer == nil {
1083+ pterm .Error .Println ("computer service not available" )
1084+ return nil
1085+ }
1086+ br , err := b .browsers .Get (ctx , in .Identifier , kernel.BrowserGetParams {})
1087+ if err != nil {
1088+ return util.CleanedUpSdkError {Err : err }
1089+ }
1090+ res , err := b .computer .ReadClipboard (ctx , br .SessionID )
1091+ if err != nil {
1092+ return util.CleanedUpSdkError {Err : err }
1093+ }
1094+ if in .Output == "json" {
1095+ enc := json .NewEncoder (os .Stdout )
1096+ enc .SetIndent ("" , " " )
1097+ return enc .Encode (res )
1098+ }
1099+ fmt .Println (res .Text )
1100+ return nil
1101+ }
1102+
1103+ func (b BrowsersCmd ) ComputerWriteClipboard (ctx context.Context , in BrowsersComputerWriteClipboardInput ) error {
1104+ if b .computer == nil {
1105+ pterm .Error .Println ("computer service not available" )
1106+ return nil
1107+ }
1108+ br , err := b .browsers .Get (ctx , in .Identifier , kernel.BrowserGetParams {})
1109+ if err != nil {
1110+ return util.CleanedUpSdkError {Err : err }
1111+ }
1112+ if err := b .computer .WriteClipboard (ctx , br .SessionID , kernel.BrowserComputerWriteClipboardParams {Text : in .Text }); err != nil {
1113+ return util.CleanedUpSdkError {Err : err }
1114+ }
1115+ pterm .Success .Println ("Text written to clipboard" )
1116+ return nil
1117+ }
1118+
10661119// Replays
10671120type BrowsersReplaysListInput struct {
10681121 Identifier string
@@ -2415,7 +2468,16 @@ func init() {
24152468 computerBatch .Flags ().String ("actions" , "" , "JSON object with actions array (e.g., {\" actions\" :[{\" type\" :\" click_mouse\" ,...}]})" )
24162469 _ = computerBatch .MarkFlagRequired ("actions" )
24172470
2418- computerRoot .AddCommand (computerClick , computerMove , computerScreenshot , computerType , computerPressKey , computerScroll , computerDrag , computerSetCursor , computerGetMousePosition , computerBatch )
2471+ // computer read-clipboard
2472+ computerReadClipboard := & cobra.Command {Use : "read-clipboard <id>" , Short : "Read text from the browser clipboard" , Args : cobra .ExactArgs (1 ), RunE : runBrowsersComputerReadClipboard }
2473+ computerReadClipboard .Flags ().StringP ("output" , "o" , "" , "Output format: json for raw API response" )
2474+
2475+ // computer write-clipboard
2476+ computerWriteClipboard := & cobra.Command {Use : "write-clipboard <id>" , Short : "Write text to the browser clipboard" , Args : cobra .ExactArgs (1 ), RunE : runBrowsersComputerWriteClipboard }
2477+ computerWriteClipboard .Flags ().String ("text" , "" , "Text to write to the clipboard" )
2478+ _ = computerWriteClipboard .MarkFlagRequired ("text" )
2479+
2480+ computerRoot .AddCommand (computerClick , computerMove , computerScreenshot , computerType , computerPressKey , computerScroll , computerDrag , computerSetCursor , computerGetMousePosition , computerBatch , computerReadClipboard , computerWriteClipboard )
24192481 browsersCmd .AddCommand (computerRoot )
24202482
24212483 // playwright
@@ -3159,6 +3221,24 @@ func runBrowsersComputerBatch(cmd *cobra.Command, args []string) error {
31593221 return b .ComputerBatch (cmd .Context (), BrowsersComputerBatchInput {Identifier : args [0 ], ActionsJSON : actionsJSON })
31603222}
31613223
3224+ func runBrowsersComputerReadClipboard (cmd * cobra.Command , args []string ) error {
3225+ client := getKernelClient (cmd )
3226+ svc := client .Browsers
3227+ output , _ := cmd .Flags ().GetString ("output" )
3228+
3229+ b := BrowsersCmd {browsers : & svc , computer : & svc .Computer }
3230+ return b .ComputerReadClipboard (cmd .Context (), BrowsersComputerReadClipboardInput {Identifier : args [0 ], Output : output })
3231+ }
3232+
3233+ func runBrowsersComputerWriteClipboard (cmd * cobra.Command , args []string ) error {
3234+ client := getKernelClient (cmd )
3235+ svc := client .Browsers
3236+ text , _ := cmd .Flags ().GetString ("text" )
3237+
3238+ b := BrowsersCmd {browsers : & svc , computer : & svc .Computer }
3239+ return b .ComputerWriteClipboard (cmd .Context (), BrowsersComputerWriteClipboardInput {Identifier : args [0 ], Text : text })
3240+ }
3241+
31623242func truncateURL (url string , maxLen int ) string {
31633243 if len (url ) <= maxLen {
31643244 return url
0 commit comments