Skip to content

Commit 5e06560

Browse files
committed
Add start_url to browser update CLI
1 parent 2242ce5 commit 5e06560

5 files changed

Lines changed: 52 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ Commands with JSON output support:
252252
- `--proxy-mode direct|default` - Change egress mode: `direct` for no proxy regardless of stealth, `default` to restore the browser default after using a selected proxy. Changing the proxy does not change stealth or CAPTCHA solver behavior.
253253
- `--clear-proxy` - Drop the selected proxy and restore the browser default (same as `--proxy-mode=default`)
254254
- `--disable-default-proxy` - Connect directly instead of through the default stealth proxy (same as `--proxy-mode=direct`); use `--disable-default-proxy=false` to restore the default
255+
- `--start-url <url>` - Navigate the browser to a URL after applying the update
255256
- `--output json`, `-o json` - Output raw JSON object
256257
- `kernel browsers curl <id> <url>` - Make HTTP requests through a browser session's Chrome network stack
257258
- `-X, --request <method>` - HTTP method (default: GET; defaults to POST when `--data` is set)

‎cmd/browsers.go‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ type BrowsersUpdateInput struct {
413413
ProfileID string
414414
ProfileName string
415415
ProfileSaveChanges BoolFlag
416+
StartURL string
416417
Viewport string
417418
Force bool
418419
Telemetry string
@@ -897,6 +898,9 @@ func (b BrowsersCmd) Update(ctx context.Context, in BrowsersUpdateInput) error {
897898
if err := validateJSONOutput(in.Output); err != nil {
898899
return err
899900
}
901+
if err := validateStartURLFlag(in.StartURL); err != nil {
902+
return err
903+
}
900904

901905
// Validate profile selection: at most one of profile-id or profile-name must be provided
902906
if in.ProfileID != "" && in.ProfileName != "" {
@@ -938,6 +942,7 @@ func (b BrowsersCmd) Update(ctx context.Context, in BrowsersUpdateInput) error {
938942

939943
hasProxyChange := proxySel.set()
940944
hasProfileChange := in.ProfileID != "" || in.ProfileName != ""
945+
hasStartURLChange := in.StartURL != ""
941946
hasViewportChange := in.Viewport != ""
942947
// By this point a set name is guaranteed non-empty (the guard above rejects --name "").
943948
hasNameChange := in.SetName || in.ClearName
@@ -954,8 +959,8 @@ func (b BrowsersCmd) Update(ctx context.Context, in BrowsersUpdateInput) error {
954959
}
955960

956961
// Validate that at least one update option is provided
957-
if !hasProxyChange && !hasProfileChange && !hasViewportChange && in.Telemetry == "" && !hasNameChange && !hasTagsChange {
958-
return fmt.Errorf("must specify at least one of: --proxy-id, --proxy-name, --proxy-mode, --clear-proxy, --disable-default-proxy, --profile-id, --profile-name, --viewport, --telemetry, --name, --clear-name, --tag, or --clear-tags")
962+
if !hasProxyChange && !hasProfileChange && !hasStartURLChange && !hasViewportChange && in.Telemetry == "" && !hasNameChange && !hasTagsChange {
963+
return fmt.Errorf("must specify at least one of: --proxy-id, --proxy-name, --proxy-mode, --clear-proxy, --disable-default-proxy, --profile-id, --profile-name, --start-url, --viewport, --telemetry, --name, --clear-name, --tag, or --clear-tags")
959964
}
960965

961966
params := kernel.BrowserUpdateParams{}
@@ -997,6 +1002,10 @@ func (b BrowsersCmd) Update(ctx context.Context, in BrowsersUpdateInput) error {
9971002
}
9981003
}
9991004

1005+
if hasStartURLChange {
1006+
params.StartURL = kernel.Opt(in.StartURL)
1007+
}
1008+
10001009
// Handle telemetry changes
10011010
if in.Telemetry != "" {
10021011
t, err := buildUpdateTelemetryParam(in.Telemetry)
@@ -2644,6 +2653,7 @@ Supported operations:
26442653
- Select a proxy by ID or name (--proxy-id or --proxy-name)
26452654
- Change proxy egress mode (--proxy-mode=direct or --proxy-mode=default)
26462655
- Load a profile into a session that doesn't have one (--profile-id or --profile-name)
2656+
- Navigate to a URL after the update (--start-url)
26472657
- Change viewport dimensions (--viewport)
26482658
- Force viewport resize during active live view or recording (--force with --viewport)
26492659
- Rename or clear the session name (--name or --clear-name)
@@ -2692,6 +2702,7 @@ func init() {
26922702
browsersUpdateCmd.Flags().String("profile-id", "", "Profile ID to load into the browser session (mutually exclusive with --profile-name)")
26932703
browsersUpdateCmd.Flags().String("profile-name", "", "Profile name to load into the browser session (mutually exclusive with --profile-id)")
26942704
browsersUpdateCmd.Flags().Bool("save-changes", false, "If set, save changes back to the profile when the session ends")
2705+
browsersUpdateCmd.Flags().String("start-url", "", "URL to navigate the browser to after applying this update")
26952706
browsersUpdateCmd.Flags().String("viewport", "", "Browser viewport size (e.g., 1920x1080@25). Supported: 2560x1440@10, 1920x1080@25, 1920x1200@25, 1440x900@25, 1024x768@60, 1200x800@60, 1280x800@60")
26962707
browsersUpdateCmd.Flags().Bool("force", false, "Force viewport resize even when a live view or recording/replay is active")
26972708
browsersUpdateCmd.Flags().String("telemetry", "", "Update telemetry: --telemetry=all (reset to default set), --telemetry=off (disable), or --telemetry=console,network (merge those categories into the current selection)")
@@ -3311,6 +3322,7 @@ func runBrowsersUpdate(cmd *cobra.Command, args []string) error {
33113322
profileID, _ := cmd.Flags().GetString("profile-id")
33123323
profileName, _ := cmd.Flags().GetString("profile-name")
33133324
saveChanges, _ := cmd.Flags().GetBool("save-changes")
3325+
startURL, _ := cmd.Flags().GetString("start-url")
33143326
viewport, _ := cmd.Flags().GetString("viewport")
33153327
force, _ := cmd.Flags().GetBool("force")
33163328
telemetry, _ := cmd.Flags().GetString("telemetry")
@@ -3331,6 +3343,7 @@ func runBrowsersUpdate(cmd *cobra.Command, args []string) error {
33313343
ProfileID: profileID,
33323344
ProfileName: profileName,
33333345
ProfileSaveChanges: BoolFlag{Set: cmd.Flags().Changed("save-changes"), Value: saveChanges},
3346+
StartURL: startURL,
33343347
Viewport: viewport,
33353348
Force: force,
33363349
Telemetry: telemetry,

‎cmd/browsers_test.go‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,6 +2408,39 @@ func captureUpdateParams(t *testing.T) (*FakeBrowsersService, *kernel.BrowserUpd
24082408
return fake, captured
24092409
}
24102410

2411+
func TestBrowsersUpdate_WithStartURL_ForwardsParam(t *testing.T) {
2412+
setupStdoutCapture(t)
2413+
fake, captured := captureUpdateParams(t)
2414+
b := BrowsersCmd{browsers: fake}
2415+
2416+
err := b.Update(context.Background(), BrowsersUpdateInput{
2417+
Identifier: "session123",
2418+
StartURL: "https://example.com/checkout",
2419+
})
2420+
2421+
require.NoError(t, err)
2422+
assert.True(t, captured.StartURL.Valid())
2423+
assert.Equal(t, "https://example.com/checkout", captured.StartURL.Value)
2424+
}
2425+
2426+
func TestBrowsersUpdate_RejectsStartURLFlagToken(t *testing.T) {
2427+
called := false
2428+
fake := &FakeBrowsersService{UpdateFunc: func(ctx context.Context, id string, body kernel.BrowserUpdateParams, opts ...option.RequestOption) (*kernel.BrowserUpdateResponse, error) {
2429+
called = true
2430+
return &kernel.BrowserUpdateResponse{}, nil
2431+
}}
2432+
b := BrowsersCmd{browsers: fake}
2433+
2434+
err := b.Update(context.Background(), BrowsersUpdateInput{
2435+
Identifier: "session123",
2436+
StartURL: "--viewport",
2437+
})
2438+
2439+
require.Error(t, err)
2440+
assert.Contains(t, err.Error(), "--start-url requires a URL value")
2441+
assert.False(t, called)
2442+
}
2443+
24112444
func TestBrowsersUpdate_WithName_ForwardsParam(t *testing.T) {
24122445
setupStdoutCapture(t)
24132446
fake, captured := captureUpdateParams(t)

‎go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/charmbracelet/lipgloss/v2 v2.0.0-beta.1
1010
github.com/golang-jwt/jwt/v5 v5.2.2
1111
github.com/joho/godotenv v1.5.1
12-
github.com/kernel/kernel-go-sdk v0.105.0
12+
github.com/kernel/kernel-go-sdk v0.106.0
1313
github.com/klauspost/compress v1.18.5
1414
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
1515
github.com/pterm/pterm v0.12.80

‎go.sum‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
6666
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
6767
github.com/kernel/kernel-go-sdk v0.105.0 h1:xKCFrduHuKTD6ceytLkMHUDRafnZaJcc8WUPSXGGILw=
6868
github.com/kernel/kernel-go-sdk v0.105.0/go.mod h1:EeZzSuHZVeHKxKCPUzxou2bovNGhXaz0RXrSqKNf1AQ=
69+
github.com/kernel/kernel-go-sdk v0.106.0 h1:w5+MEk6hdkwVOltLrS+6bvEaRBq8y8FUcfdfibzMH7k=
70+
github.com/kernel/kernel-go-sdk v0.106.0/go.mod h1:EeZzSuHZVeHKxKCPUzxou2bovNGhXaz0RXrSqKNf1AQ=
6971
github.com/klauspost/compress v1.18.5 h1:/h1gH5Ce+VWNLSWqPzOVn6XBO+vJbCNGvjoaGBFW2IE=
7072
github.com/klauspost/compress v1.18.5/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
7173
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=

0 commit comments

Comments
 (0)