Skip to content

Commit d1c8979

Browse files
committed
add pkg examples
1 parent eda242f commit d1c8979

6 files changed

Lines changed: 1 addition & 89 deletions

File tree

browser/browser.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ type Browser struct {
2121
tabs []tabEntry
2222
activeTab int
2323

24-
// Phase 7
2524
trace *traceState
2625
profiling bool
2726
recording *recordState
2827

29-
// Phase 8.3: Global options
3028
downloadPath string
3129
screenshotDir string
3230
screenshotFormat string
@@ -57,7 +55,6 @@ func New(opts Options) (*Browser, error) {
5755
allocOpts = append(allocOpts, chromedp.UserDataDir(opts.Profile))
5856
}
5957

60-
// Phase 8.3: Global options
6158
if opts.UserAgent != "" {
6259
allocOpts = append(allocOpts, chromedp.UserAgent(opts.UserAgent))
6360
}

browser/options.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ type Options struct {
1919
// (cookies + localStorage) to import when creating the browser.
2020
StatePath string
2121

22-
// Phase 8.3: Global options
2322
UserAgent string // custom User-Agent string
2423
Proxy string // proxy server URL (e.g. "http://proxy:8080" or "socks5://proxy:1080")
2524
ProxyBypass string // comma-separated hosts to bypass proxy

cmd/root.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ var rootFlags struct {
2222
statePath string
2323
config string
2424

25-
// Phase 8.3: Global options
2625
userAgent string
2726
proxy string
2827
proxyBypass string
@@ -62,7 +61,6 @@ func init() {
6261
rootCmd.PersistentFlags().StringVar(&rootFlags.statePath, "state", "", "JSON file to load saved browser state (cookies + localStorage)")
6362
rootCmd.PersistentFlags().StringVar(&rootFlags.config, "config", "", "path to config file (default: auto-detect)")
6463

65-
// Phase 8.3: Global options
6664
rootCmd.PersistentFlags().StringVar(&rootFlags.userAgent, "user-agent", "", "custom User-Agent string")
6765
rootCmd.PersistentFlags().StringVar(&rootFlags.proxy, "proxy", "", "proxy server URL (e.g. http://proxy:8080)")
6866
rootCmd.PersistentFlags().StringVar(&rootFlags.proxyBypass, "proxy-bypass", "", "comma-separated hosts to bypass proxy")
@@ -230,7 +228,6 @@ func applyConfigFile(path string) error {
230228
rootFlags.contentBoundaries = *cfg.ContentBoundaries
231229
}
232230

233-
// Phase 8.3: Apply new global options from config
234231
if cfg.UserAgent != "" && !rootCmd.PersistentFlags().Lookup("user-agent").Changed {
235232
rootFlags.userAgent = cfg.UserAgent
236233
}

internal/session/config.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ type Options struct {
1818
Profile string
1919
StatePath string
2020

21-
// Phase 8.3: Global options
2221
UserAgent string
2322
Proxy string
2423
ProxyBypass string
@@ -30,7 +29,6 @@ type Options struct {
3029
ScreenshotDir string
3130
ScreenshotFormat string
3231

33-
// Phase 8.4: Confirmation
3432
ConfirmActions []string
3533
}
3634

@@ -49,14 +47,12 @@ type Request struct {
4947
WaitDuration time.Duration `json:"waitDuration,omitempty"`
5048
SnapshotOptions browser.SnapshotOptions `json:"snapshotOptions,omitempty"`
5149

52-
// Phase 3: Screenshot/PDF/Eval/Find
5350
FilePath string `json:"filePath,omitempty"`
5451
ScreenshotArgs ScreenshotArgs `json:"screenshotArgs,omitempty"`
5552
PDFArgs PDFArgs `json:"pdfArgs,omitempty"`
5653
Role string `json:"role,omitempty"`
5754
N int `json:"n,omitempty"`
5855

59-
// Phase 4: Drag/Upload/Download/Mouse
6056
DstID int `json:"dstId,omitempty"`
6157
Files []string `json:"files,omitempty"`
6258
SaveDir string `json:"saveDir,omitempty"`
@@ -66,7 +62,6 @@ type Request struct {
6662
DeltaY float64 `json:"deltaY,omitempty"`
6763
MouseBtn string `json:"mouseBtn,omitempty"`
6864

69-
// Phase 5: Tab/Network/Storage
7065
TabIndex int `json:"tabIndex,omitempty"`
7166
Pattern string `json:"pattern,omitempty"`
7267
RouteAction string `json:"routeAction,omitempty"`
@@ -75,7 +70,6 @@ type Request struct {
7570
StorageKey string `json:"storageKey,omitempty"`
7671
StorageVal string `json:"storageVal,omitempty"`
7772

78-
// Phase 6: Settings/Debug/Clipboard
7973
Width int `json:"width,omitempty"`
8074
Height int `json:"height,omitempty"`
8175
DeviceName string `json:"deviceName,omitempty"`
@@ -90,7 +84,6 @@ type Request struct {
9084
ClipboardText string `json:"clipboardText,omitempty"`
9185
ConsoleLevel string `json:"consoleLevel,omitempty"`
9286

93-
// Phase 7: Advanced features
9487
Target string `json:"target,omitempty"` // connect target (port or ws URL)
9588
BaselineFile string `json:"baselineFile,omitempty"` // diff baseline file path
9689
OutputFile string `json:"outputFile,omitempty"` // output file path for diff/trace/profiler/record
@@ -100,7 +93,6 @@ type Request struct {
10093
Categories string `json:"categories,omitempty"` // trace categories
10194
StatePath string `json:"statePath,omitempty"` // state import/export path
10295

103-
// Phase 8: Missing commands/flags
10496
NewTab bool `json:"newTab,omitempty"` // click with new tab
10597
Exact bool `json:"exact,omitempty"` // exact matching for find
10698
Scale float64 `json:"scale,omitempty"` // viewport scale factor
@@ -133,22 +125,18 @@ type Response struct {
133125
Box *browser.BoxResult `json:"box,omitempty"`
134126
FilePath string `json:"filePath,omitempty"`
135127

136-
// Phase 5
137128
Tabs []browser.TabInfo `json:"tabs,omitempty"`
138129
Cookies []browser.CookieInfo `json:"cookies,omitempty"`
139130
Requests []browser.NetworkRequest `json:"requests,omitempty"`
140131
StorageItems map[string]string `json:"storageItems,omitempty"`
141132

142-
// Phase 6
143133
ConsoleMessages []browser.ConsoleMessage `json:"consoleMessages,omitempty"`
144134
PageErrors []browser.PageError `json:"pageErrors,omitempty"`
145135

146-
// Phase 7
147136
DiffResult *browser.DiffSnapshotResult `json:"diffResult,omitempty"`
148137
ScreenshotDiff *browser.DiffScreenshotResult `json:"screenshotDiff,omitempty"`
149138
DiffURLResult *browser.DiffURLResult `json:"diffURLResult,omitempty"`
150139

151-
// Phase 8.4: Confirmation
152140
ConfirmationRequired bool `json:"confirmationRequired,omitempty"`
153141
ConfirmID string `json:"confirmId,omitempty"`
154142
}

internal/session/daemon.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,13 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
175175
}
176176
return true, nil
177177

178-
// Phase 2: Navigation
179178
case "back":
180179
err = b.Back()
181180
case "forward":
182181
err = b.Forward()
183182
case "reload":
184183
err = b.Reload()
185184

186-
// Phase 2: Information retrieval
187185
case "get.title":
188186
var text string
189187
text, err = b.GetTitle()
@@ -267,7 +265,6 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
267265
resp.Text = text
268266
}
269267

270-
// Phase 2: State queries
271268
case "is.visible":
272269
if req.ID <= 0 {
273270
err = fmt.Errorf("id must be positive")
@@ -299,7 +296,6 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
299296
resp.BoolResult = &v
300297
}
301298

302-
// Phase 2: Wait commands
303299
case "wait":
304300
err = b.Wait(req.WaitDuration)
305301
case "wait.selector":
@@ -329,7 +325,6 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
329325
}
330326
err = b.WaitFunc(req.Expression)
331327

332-
// Phase 3: Screenshot
333328
case "screenshot":
334329
if req.FilePath == "" {
335330
err = fmt.Errorf("file path is required")
@@ -349,7 +344,6 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
349344
})
350345
}
351346

352-
// Phase 3: PDF
353347
case "pdf":
354348
if req.FilePath == "" {
355349
err = fmt.Errorf("file path is required")
@@ -360,7 +354,6 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
360354
PrintBG: req.PDFArgs.PrintBG,
361355
})
362356

363-
// Phase 3: Eval
364357
case "eval":
365358
if req.Expression == "" {
366359
err = fmt.Errorf("expression is required")
@@ -372,7 +365,6 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
372365
resp.Text = result
373366
}
374367

375-
// Phase 3: Find
376368
case "find.role":
377369
var result *browser.FindResults
378370
var findOpts []browser.FindOption
@@ -432,7 +424,6 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
432424
resp.Text = result.Text
433425
}
434426

435-
// Phase 4: Drag
436427
case "drag":
437428
if req.ID <= 0 {
438429
err = fmt.Errorf("source id must be positive")
@@ -444,7 +435,6 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
444435
}
445436
err = b.Drag(req.ID, req.DstID)
446437

447-
// Phase 4: Upload
448438
case "upload":
449439
if req.ID <= 0 {
450440
err = fmt.Errorf("id must be positive")
@@ -456,7 +446,6 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
456446
}
457447
err = b.Upload(req.ID, req.Files...)
458448

459-
// Phase 4: Download
460449
case "download":
461450
if req.ID <= 0 {
462451
err = fmt.Errorf("id must be positive")
@@ -472,7 +461,6 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
472461
resp.FilePath = path
473462
}
474463

475-
// Phase 4: Mouse operations
476464
case "mouse.move":
477465
err = b.MouseMove(req.X, req.Y)
478466
case "mouse.down":
@@ -496,7 +484,6 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
496484
}
497485
err = b.MouseClick(req.X, req.Y, opts)
498486

499-
// Phase 5: Tab management
500487
case "tab.list":
501488
var tabs []browser.TabInfo
502489
tabs, err = b.TabList()
@@ -510,7 +497,6 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
510497
case "tab.switch":
511498
err = b.TabSwitch(req.TabIndex)
512499

513-
// Phase 5: Network
514500
case "network.route":
515501
action := browser.RouteBlock
516502
if req.RouteAction == "continue" {
@@ -530,7 +516,6 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
530516
case "network.clear-requests":
531517
b.NetworkClearRequests()
532518

533-
// Phase 5: Cookies
534519
case "cookies.get":
535520
var cookies []browser.CookieInfo
536521
cookies, err = b.CookiesGet()
@@ -544,7 +529,6 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
544529
case "cookies.clear":
545530
err = b.CookiesClear()
546531

547-
// Phase 5: Storage
548532
case "storage.get":
549533
var val string
550534
val, err = b.StorageGet(req.StorageType, req.StorageKey)
@@ -564,7 +548,6 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
564548
resp.StorageItems = items
565549
}
566550

567-
// Phase 6: Settings
568551
case "set.viewport":
569552
if req.Width <= 0 || req.Height <= 0 {
570553
err = fmt.Errorf("width and height must be positive")
@@ -608,7 +591,6 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
608591
}
609592
err = b.SetColorScheme(req.ColorScheme)
610593

611-
// Phase 6: Console/Debug
612594
case "console.start":
613595
err = b.ConsoleStart()
614596
case "console.messages":
@@ -640,7 +622,6 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
640622
case "devtools":
641623
err = b.OpenDevTools()
642624

643-
// Phase 6: Clipboard
644625
case "clipboard.read":
645626
var text string
646627
text, err = b.ClipboardRead()
@@ -650,7 +631,6 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
650631
case "clipboard.write":
651632
err = b.ClipboardWrite(req.ClipboardText)
652633

653-
// Phase 7: Diff
654634
case "diff.snapshot":
655635
var result *browser.DiffSnapshotResult
656636
result, err = b.DiffSnapshot(browser.DiffSnapshotOptions{
@@ -696,7 +676,6 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
696676
}
697677
}
698678

699-
// Phase 7: Trace
700679
case "trace.start":
701680
if req.Categories != "" {
702681
err = b.TraceStart(req.Categories)
@@ -706,13 +685,11 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
706685
case "trace.stop":
707686
err = b.TraceStop(req.OutputFile)
708687

709-
// Phase 7: Profiler
710688
case "profiler.start":
711689
err = b.ProfilerStart()
712690
case "profiler.stop":
713691
err = b.ProfilerStop(req.OutputFile)
714692

715-
// Phase 7: Record
716693
case "record.start":
717694
err = b.RecordStart(req.OutputFile)
718695
case "record.stop":
@@ -722,7 +699,6 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
722699
resp.IntResult = frameCount
723700
}
724701

725-
// Phase 7: State export/import
726702
case "state.export":
727703
if req.StatePath == "" {
728704
err = fmt.Errorf("state file path is required")
@@ -736,7 +712,6 @@ func handleConn(conn net.Conn, b *browser.Browser, sessionName string, confirmSt
736712
}
737713
err = b.ImportState(req.StatePath)
738714

739-
// Phase 8: Missing commands
740715
case "keyboard.inserttext":
741716
if req.Text == "" {
742717
err = fmt.Errorf("text is required")

0 commit comments

Comments
 (0)