-
Notifications
You must be signed in to change notification settings - Fork 5
browser profiles CLI commands #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rgarcia
merged 7 commits into
main
from
raf/kernel-229-feature-request-api-to-save-browser-contexts-profiles
Sep 4, 2025
+652
−39
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
db940e8
profiles cmd
rgarcia 1f6c225
udpates
rgarcia 8d8e66e
Merge branch 'main' into raf/kernel-229-feature-request-api-to-save-b…
rgarcia a628a82
kernel sdk 0.11
rgarcia c2a89a6
use Get() + notfound check
rgarcia d0080c1
Merge branch 'main' into raf/kernel-229-feature-request-api-to-save-b…
rgarcia 7ef42ee
fix test
rgarcia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,8 +14,8 @@ | |
| "github.com/onkernel/cli/pkg/util" | ||
| "github.com/onkernel/kernel-go-sdk" | ||
| "github.com/onkernel/kernel-go-sdk/option" | ||
| "github.com/onkernel/kernel-go-sdk/packages/ssestream" | ||
|
Check failure on line 17 in cmd/browsers.go
|
||
| "github.com/onkernel/kernel-go-sdk/shared" | ||
|
Check failure on line 18 in cmd/browsers.go
|
||
| "github.com/pterm/pterm" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
@@ -76,10 +76,13 @@ | |
|
|
||
| // Inputs for each command | ||
| type BrowsersCreateInput struct { | ||
| PersistenceID string | ||
| TimeoutSeconds int | ||
| Stealth BoolFlag | ||
| Headless BoolFlag | ||
| PersistenceID string | ||
| TimeoutSeconds int | ||
| Stealth BoolFlag | ||
| Headless BoolFlag | ||
| ProfileID string | ||
| ProfileName string | ||
| ProfileSaveChanges BoolFlag | ||
| } | ||
|
|
||
| type BrowsersDeleteInput struct { | ||
|
|
@@ -115,7 +118,7 @@ | |
|
|
||
| // Prepare table data | ||
| tableData := pterm.TableData{ | ||
| {"Browser ID", "Created At", "Persistent ID", "CDP WS URL", "Live View URL"}, | ||
| {"Browser ID", "Created At", "Persistent ID", "Profile", "CDP WS URL", "Live View URL"}, | ||
| } | ||
|
|
||
| for _, browser := range *browsers { | ||
|
|
@@ -124,10 +127,18 @@ | |
| persistentID = browser.Persistence.ID | ||
| } | ||
|
|
||
| profile := "-" | ||
| if browser.Profile.Name != "" { | ||
| profile = browser.Profile.Name | ||
| } else if browser.Profile.ID != "" { | ||
| profile = browser.Profile.ID | ||
| } | ||
|
|
||
| tableData = append(tableData, []string{ | ||
| browser.SessionID, | ||
| browser.CreatedAt.Format("2006-01-02 15:04:05"), | ||
| util.FormatLocal(browser.CreatedAt), | ||
| persistentID, | ||
| profile, | ||
| truncateURL(browser.CdpWsURL, 50), | ||
| truncateURL(browser.BrowserLiveViewURL, 50), | ||
| }) | ||
|
|
@@ -153,6 +164,21 @@ | |
| params.Headless = kernel.Opt(in.Headless.Value) | ||
| } | ||
|
|
||
| // Validate profile selection: at most one of profile-id or profile-name must be provided | ||
| if in.ProfileID != "" && in.ProfileName != "" { | ||
| pterm.Error.Println("must specify at most one of --profile-id or --profile-name") | ||
| return nil | ||
| } else if in.ProfileID != "" || in.ProfileName != "" { | ||
| params.Profile = kernel.BrowserNewParamsProfile{ | ||
| SaveChanges: kernel.Opt(in.ProfileSaveChanges.Value), | ||
| } | ||
| if in.ProfileID != "" { | ||
| params.Profile.ID = kernel.Opt(in.ProfileID) | ||
| } else if in.ProfileName != "" { | ||
| params.Profile.Name = kernel.Opt(in.ProfileName) | ||
| } | ||
| } | ||
|
|
||
| browser, err := b.browsers.New(ctx, params) | ||
| if err != nil { | ||
| return util.CleanedUpSdkError{Err: err} | ||
|
|
@@ -169,6 +195,13 @@ | |
| if browser.Persistence.ID != "" { | ||
| tableData = append(tableData, []string{"Persistent ID", browser.Persistence.ID}) | ||
| } | ||
| if browser.Profile.ID != "" || browser.Profile.Name != "" { | ||
| profVal := browser.Profile.Name | ||
| if profVal == "" { | ||
| profVal = browser.Profile.ID | ||
| } | ||
| tableData = append(tableData, []string{"Profile", profVal}) | ||
| } | ||
Sayan- marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| printTableNoPad(tableData, true) | ||
| return nil | ||
|
|
@@ -337,7 +370,7 @@ | |
| defer stream.Close() | ||
| for stream.Next() { | ||
| ev := stream.Current() | ||
| pterm.Println(fmt.Sprintf("[%s] %s", ev.Timestamp.Format("2006-01-02 15:04:05"), ev.Message)) | ||
| pterm.Println(fmt.Sprintf("[%s] %s", util.FormatLocal(ev.Timestamp), ev.Message)) | ||
| } | ||
| if err := stream.Err(); err != nil { | ||
| return util.CleanedUpSdkError{Err: err} | ||
|
|
@@ -386,7 +419,7 @@ | |
| } | ||
| rows := pterm.TableData{{"Replay ID", "Started At", "Finished At", "View URL"}} | ||
| for _, r := range *items { | ||
| rows = append(rows, []string{r.ReplayID, r.StartedAt.Format("2006-01-02 15:04:05"), r.FinishedAt.Format("2006-01-02 15:04:05"), truncateURL(r.ReplayViewURL, 60)}) | ||
| rows = append(rows, []string{r.ReplayID, util.FormatLocal(r.StartedAt), util.FormatLocal(r.FinishedAt), truncateURL(r.ReplayViewURL, 60)}) | ||
| } | ||
| printTableNoPad(rows, true) | ||
| return nil | ||
|
|
@@ -412,7 +445,7 @@ | |
| if err != nil { | ||
| return util.CleanedUpSdkError{Err: err} | ||
| } | ||
| rows := pterm.TableData{{"Property", "Value"}, {"Replay ID", res.ReplayID}, {"View URL", res.ReplayViewURL}, {"Started At", res.StartedAt.Format("2006-01-02 15:04:05")}} | ||
| rows := pterm.TableData{{"Property", "Value"}, {"Replay ID", res.ReplayID}, {"View URL", res.ReplayViewURL}, {"Started At", util.FormatLocal(res.StartedAt)}} | ||
| printTableNoPad(rows, true) | ||
| return nil | ||
| } | ||
|
|
@@ -597,7 +630,7 @@ | |
| if err != nil { | ||
| return util.CleanedUpSdkError{Err: err} | ||
| } | ||
| rows := pterm.TableData{{"Property", "Value"}, {"Process ID", res.ProcessID}, {"PID", fmt.Sprintf("%d", res.Pid)}, {"Started At", res.StartedAt.Format("2006-01-02 15:04:05")}} | ||
| rows := pterm.TableData{{"Property", "Value"}, {"Process ID", res.ProcessID}, {"PID", fmt.Sprintf("%d", res.Pid)}, {"Started At", util.FormatLocal(res.StartedAt)}} | ||
| printTableNoPad(rows, true) | ||
| return nil | ||
| } | ||
|
|
@@ -900,7 +933,7 @@ | |
| if err != nil { | ||
| return util.CleanedUpSdkError{Err: err} | ||
| } | ||
| rows := pterm.TableData{{"Property", "Value"}, {"Path", res.Path}, {"Name", res.Name}, {"Mode", res.Mode}, {"IsDir", fmt.Sprintf("%t", res.IsDir)}, {"SizeBytes", fmt.Sprintf("%d", res.SizeBytes)}, {"ModTime", res.ModTime.Format("2006-01-02 15:04:05")}} | ||
| rows := pterm.TableData{{"Property", "Value"}, {"Path", res.Path}, {"Name", res.Name}, {"Mode", res.Mode}, {"IsDir", fmt.Sprintf("%t", res.IsDir)}, {"SizeBytes", fmt.Sprintf("%d", res.SizeBytes)}, {"ModTime", util.FormatLocal(res.ModTime)}} | ||
| printTableNoPad(rows, true) | ||
| return nil | ||
| } | ||
|
|
@@ -928,7 +961,7 @@ | |
| } | ||
| rows := pterm.TableData{{"Mode", "Size", "ModTime", "Name", "Path"}} | ||
| for _, f := range *res { | ||
| rows = append(rows, []string{f.Mode, fmt.Sprintf("%d", f.SizeBytes), f.ModTime.Format("2006-01-02 15:04:05"), f.Name, f.Path}) | ||
| rows = append(rows, []string{f.Mode, fmt.Sprintf("%d", f.SizeBytes), util.FormatLocal(f.ModTime), f.Name, f.Path}) | ||
| } | ||
| printTableNoPad(rows, true) | ||
| return nil | ||
|
|
@@ -1297,6 +1330,9 @@ | |
| browsersCreateCmd.Flags().BoolP("stealth", "s", false, "Launch browser in stealth mode to avoid detection") | ||
| browsersCreateCmd.Flags().BoolP("headless", "H", false, "Launch browser without GUI access") | ||
| browsersCreateCmd.Flags().IntP("timeout", "t", 60, "Timeout in seconds for the browser session") | ||
| browsersCreateCmd.Flags().String("profile-id", "", "Profile ID to load into the browser session (mutually exclusive with --profile-name)") | ||
| browsersCreateCmd.Flags().String("profile-name", "", "Profile name to load into the browser session (mutually exclusive with --profile-id)") | ||
| browsersCreateCmd.Flags().Bool("save-changes", false, "If set, save changes back to the profile when the session ends") | ||
|
|
||
| // Add flags for delete command | ||
| browsersDeleteCmd.Flags().BoolP("yes", "y", false, "Skip confirmation prompt") | ||
|
|
@@ -1319,12 +1355,18 @@ | |
| stealthVal, _ := cmd.Flags().GetBool("stealth") | ||
| headlessVal, _ := cmd.Flags().GetBool("headless") | ||
| timeout, _ := cmd.Flags().GetInt("timeout") | ||
| profileID, _ := cmd.Flags().GetString("profile-id") | ||
| profileName, _ := cmd.Flags().GetString("profile-name") | ||
| saveChanges, _ := cmd.Flags().GetBool("save-changes") | ||
|
|
||
| in := BrowsersCreateInput{ | ||
| PersistenceID: persistenceID, | ||
| TimeoutSeconds: timeout, | ||
| Stealth: BoolFlag{Set: cmd.Flags().Changed("stealth"), Value: stealthVal}, | ||
| Headless: BoolFlag{Set: cmd.Flags().Changed("headless"), Value: headlessVal}, | ||
| PersistenceID: persistenceID, | ||
| TimeoutSeconds: timeout, | ||
| Stealth: BoolFlag{Set: cmd.Flags().Changed("stealth"), Value: stealthVal}, | ||
| Headless: BoolFlag{Set: cmd.Flags().Changed("headless"), Value: headlessVal}, | ||
| ProfileID: profileID, | ||
| ProfileName: profileName, | ||
| ProfileSaveChanges: BoolFlag{Set: cmd.Flags().Changed("save-changes"), Value: saveChanges}, | ||
| } | ||
|
|
||
| svc := client.Browsers | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.