Skip to content

Commit 755c2b9

Browse files
authored
Some updates to browser update (#91)
## Overview Allows hot loading a profile and view port into an existing browser cc @dprevoznik ## Testing Built + ran against local/staging profile: ```bash ~/kernel/cli ❯❯❯ ./bin/kernel browser create (grab SESSION_ID) ~/kernel/cli ❯❯❯ ./bin/kernel browser update --profile-name $PROFILE $SESSION_ID INFO Updating browser .... SUCCESS Updated browser ``` view port: ``` ~/kernel/cli ❯❯❯ ./bin/kernel browser update --viewport 1440x900 $SESSION_ID INFO Updating browser ... ERROR Viewport_configuration_failed: resize refused: live view or recording/replay active ~/kernel/cli ❯❯❯ ./bin/kernel browser update --viewport 1234x900 $SESSION_ID INFO Updating browser ... ERROR Invalid_viewport: No matching viewport configuration found for dimensions 1234x900. Allowed: 1024x768@60, 1920x1080@25, 2560x1440@10, 1920x1200@25, 1440x900@25, 1200x800@60 ~/kernel/cli ❯❯❯ ./bin/kernel browser update --viewport 1440x900 $SESSION_ID INFO Updating browser ... SUCCESS Updated browser ``` <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds hot profile and viewport management to `browsers update`, plus improved UX and validation. > > - Support loading a profile (`--profile-id` or `--profile-name`) with optional `--save-changes`; build `Profile` param accordingly > - Support changing viewport via `--viewport` (e.g., `1920x1080@25`), parsing width/height/refresh and setting `Viewport` param > - New validations: profile flags mutually exclusive; `--save-changes` requires a profile; forbid `--proxy-id` with `--clear-proxy`; require at least one update flag > - CLI output streamlined to a single "Updating.../Updated" message; command help expanded to list supported operations > - Wire new flags into `runBrowsersUpdate`; add helper `parseViewport` and list of supported sizes > - Script `scripts/go-mod-replace-kernel.sh`: switch replace target to `github.com/kernel/kernel-go-sdk` pointing to `github.com/stainless-sdks/kernel-go` > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit f9eb2bc. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 3067d18 commit 755c2b9

2 files changed

Lines changed: 83 additions & 25 deletions

File tree

cmd/browsers.go

Lines changed: 81 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,14 @@ type BrowsersGetInput struct {
196196
}
197197

198198
type BrowsersUpdateInput struct {
199-
Identifier string
200-
ProxyID string
201-
ClearProxy bool
202-
Output string
199+
Identifier string
200+
ProxyID string
201+
ClearProxy bool
202+
ProfileID string
203+
ProfileName string
204+
ProfileSaveChanges BoolFlag
205+
Viewport string
206+
Output string
203207
}
204208

205209
// BrowsersCmd is a cobra-independent command handler for browsers operations.
@@ -532,32 +536,71 @@ func (b BrowsersCmd) Update(ctx context.Context, in BrowsersUpdateInput) error {
532536
return fmt.Errorf("unsupported --output value: use 'json'")
533537
}
534538

535-
// Validate that at least one update option is provided
536-
if in.ProxyID == "" && !in.ClearProxy {
537-
return fmt.Errorf("must specify --proxy-id or --clear-proxy")
539+
// Validate profile selection: at most one of profile-id or profile-name must be provided
540+
if in.ProfileID != "" && in.ProfileName != "" {
541+
return fmt.Errorf("must specify at most one of --profile-id or --profile-name")
538542
}
539543

540544
// Cannot specify both --proxy-id and --clear-proxy
541545
if in.ProxyID != "" && in.ClearProxy {
542546
return fmt.Errorf("cannot specify both --proxy-id and --clear-proxy")
543547
}
544548

549+
hasProxyChange := in.ProxyID != "" || in.ClearProxy
550+
hasProfileChange := in.ProfileID != "" || in.ProfileName != ""
551+
hasViewportChange := in.Viewport != ""
552+
553+
// Validate --save-changes is only used with a profile
554+
if in.ProfileSaveChanges.Set && !hasProfileChange {
555+
return fmt.Errorf("--save-changes requires --profile-id or --profile-name")
556+
}
557+
558+
// Validate that at least one update option is provided
559+
if !hasProxyChange && !hasProfileChange && !hasViewportChange {
560+
return fmt.Errorf("must specify at least one of: --proxy-id, --clear-proxy, --profile-id, --profile-name, or --viewport")
561+
}
562+
545563
params := kernel.BrowserUpdateParams{}
564+
565+
// Handle proxy changes
546566
if in.ClearProxy {
547-
// Set to empty string to remove proxy
548567
params.ProxyID = kernel.Opt("")
549568
} else if in.ProxyID != "" {
550569
params.ProxyID = kernel.Opt(in.ProxyID)
551570
}
552571

553-
if in.Output != "json" {
554-
if in.ClearProxy {
555-
pterm.Info.Printf("Removing proxy from browser %s...\n", in.Identifier)
556-
} else {
557-
pterm.Info.Printf("Updating browser %s with proxy %s...\n", in.Identifier, in.ProxyID)
572+
// Handle profile changes
573+
if hasProfileChange {
574+
params.Profile = shared.BrowserProfileParam{}
575+
if in.ProfileID != "" {
576+
params.Profile.ID = kernel.Opt(in.ProfileID)
577+
} else if in.ProfileName != "" {
578+
params.Profile.Name = kernel.Opt(in.ProfileName)
579+
}
580+
if in.ProfileSaveChanges.Set {
581+
params.Profile.SaveChanges = kernel.Opt(in.ProfileSaveChanges.Value)
582+
}
583+
}
584+
585+
// Handle viewport changes
586+
if hasViewportChange {
587+
width, height, refreshRate, err := parseViewport(in.Viewport)
588+
if err != nil {
589+
return fmt.Errorf("invalid viewport format: %v", err)
590+
}
591+
params.Viewport = shared.BrowserViewportParam{
592+
Width: width,
593+
Height: height,
594+
}
595+
if refreshRate > 0 {
596+
params.Viewport.RefreshRate = kernel.Opt(refreshRate)
558597
}
559598
}
560599

600+
if in.Output != "json" {
601+
pterm.Info.Printf("Updating browser %s...\n", in.Identifier)
602+
}
603+
561604
browser, err := b.browsers.Update(ctx, in.Identifier, params)
562605
if err != nil {
563606
return util.CleanedUpSdkError{Err: err}
@@ -567,11 +610,7 @@ func (b BrowsersCmd) Update(ctx context.Context, in BrowsersUpdateInput) error {
567610
return util.PrintPrettyJSON(browser)
568611
}
569612

570-
if in.ClearProxy {
571-
pterm.Success.Printf("Removed proxy from browser %s\n", browser.SessionID)
572-
} else {
573-
pterm.Success.Printf("Updated browser %s with proxy %s\n", browser.SessionID, browser.ProxyID)
574-
}
613+
pterm.Success.Printf("Updated browser %s\n", browser.SessionID)
575614
return nil
576615
}
577616

@@ -1990,7 +2029,14 @@ var browsersGetCmd = &cobra.Command{
19902029
var browsersUpdateCmd = &cobra.Command{
19912030
Use: "update <id>",
19922031
Short: "Update a browser session",
1993-
Long: "Update a running browser session. Currently supports changing or removing the proxy.",
2032+
Long: `Update a running browser session.
2033+
2034+
Supported operations:
2035+
- Change or remove proxy (--proxy-id or --clear-proxy)
2036+
- Load a profile into a session that doesn't have one (--profile-id or --profile-name)
2037+
- Change viewport dimensions (--viewport)
2038+
2039+
Note: Profiles can only be loaded into sessions that don't already have a profile.`,
19942040
Args: func(cmd *cobra.Command, args []string) error {
19952041
if len(args) == 0 {
19962042
return fmt.Errorf("missing required argument: browser ID\n\nUsage: kernel browsers update <id> [flags]")
@@ -2020,6 +2066,10 @@ func init() {
20202066
browsersUpdateCmd.Flags().StringP("output", "o", "", "Output format: json for raw API response")
20212067
browsersUpdateCmd.Flags().String("proxy-id", "", "ID of the proxy to use for the browser session")
20222068
browsersUpdateCmd.Flags().Bool("clear-proxy", false, "Remove the proxy from the browser session")
2069+
browsersUpdateCmd.Flags().String("profile-id", "", "Profile ID to load into the browser session (mutually exclusive with --profile-name)")
2070+
browsersUpdateCmd.Flags().String("profile-name", "", "Profile name to load into the browser session (mutually exclusive with --profile-id)")
2071+
browsersUpdateCmd.Flags().Bool("save-changes", false, "If set, save changes back to the profile when the session ends")
2072+
browsersUpdateCmd.Flags().String("viewport", "", "Browser viewport size (e.g., 1920x1080@25). Supported: 2560x1440@10, 1920x1080@25, 1920x1200@25, 1440x900@25, 1024x768@60, 1200x800@60")
20232073

20242074
browsersCmd.AddCommand(browsersListCmd)
20252075
browsersCmd.AddCommand(browsersCreateCmd)
@@ -2457,14 +2507,22 @@ func runBrowsersUpdate(cmd *cobra.Command, args []string) error {
24572507
out, _ := cmd.Flags().GetString("output")
24582508
proxyID, _ := cmd.Flags().GetString("proxy-id")
24592509
clearProxy, _ := cmd.Flags().GetBool("clear-proxy")
2510+
profileID, _ := cmd.Flags().GetString("profile-id")
2511+
profileName, _ := cmd.Flags().GetString("profile-name")
2512+
saveChanges, _ := cmd.Flags().GetBool("save-changes")
2513+
viewport, _ := cmd.Flags().GetString("viewport")
24602514

24612515
svc := client.Browsers
24622516
b := BrowsersCmd{browsers: &svc}
24632517
return b.Update(cmd.Context(), BrowsersUpdateInput{
2464-
Identifier: args[0],
2465-
ProxyID: proxyID,
2466-
ClearProxy: clearProxy,
2467-
Output: out,
2518+
Identifier: args[0],
2519+
ProxyID: proxyID,
2520+
ClearProxy: clearProxy,
2521+
ProfileID: profileID,
2522+
ProfileName: profileName,
2523+
ProfileSaveChanges: BoolFlag{Set: cmd.Flags().Changed("save-changes"), Value: saveChanges},
2524+
Viewport: viewport,
2525+
Output: out,
24682526
})
24692527
}
24702528

scripts/go-mod-replace-kernel.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ fi
6262

6363
# Remove any existing replace directive for the SDK (ignore error if it doesn't exist)
6464
# Then add the new replace directive pointing at the desired commit
65-
go mod edit -dropreplace=github.com/onkernel/kernel-go-sdk 2>/dev/null || true
66-
go mod edit -replace=github.com/onkernel/kernel-go-sdk=github.com/stainless-sdks/kernel-go@"$gomod_version"
65+
go mod edit -dropreplace=github.com/kernel/kernel-go-sdk 2>/dev/null || true
66+
go mod edit -replace=github.com/kernel/kernel-go-sdk=github.com/stainless-sdks/kernel-go@"$gomod_version"
6767
go mod tidy
6868

6969
echo "go.mod updated to use github.com/stainless-sdks/kernel-go @ $gomod_version"

0 commit comments

Comments
 (0)