Skip to content

Commit

Permalink
fix comments format
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmood committed Aug 27, 2022
1 parent 3d11895 commit 747e746
Show file tree
Hide file tree
Showing 53 changed files with 91 additions and 45 deletions.
4 changes: 3 additions & 1 deletion browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//go:generate go run ./lib/assets/generate
//go:generate go run ./lib/utils/lint

// Package rod is a high-level driver directly based on DevTools Protocol.
package rod

import (
Expand Down Expand Up @@ -482,7 +483,8 @@ func (b *Browser) SetCookies(cookies []*proto.NetworkCookieParam) error {

// WaitDownload returns a helper to get the next download file.
// The file path will be:
// filepath.Join(dir, info.GUID)
//
// filepath.Join(dir, info.GUID)
func (b *Browser) WaitDownload(dir string) func() (info *proto.PageDownloadWillBegin) {
var oldDownloadBehavior proto.BrowserSetDownloadBehavior
has := b.LoadState("", &oldDownloadBehavior)
Expand Down
7 changes: 3 additions & 4 deletions element.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,9 @@ func (el *Element) Interactable() (pt *proto.Point, err error) {
// A 4-gon is not necessary a rectangle. 4-gons can be apart from each other.
// For example, we use 2 4-gons to describe the shape below:
//
// ____________ ____________
// / ___/ = /___________/ + _________
// /________/ /________/
//
// ____________ ____________
// / ___/ = /___________/ + _________
// /________/ /________/
func (el *Element) Shape() (*proto.DOMGetContentQuadsResult, error) {
return proto.DOMGetContentQuads{ObjectID: el.id()}.Call(el)
}
Expand Down
4 changes: 3 additions & 1 deletion examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,9 @@ func Example_download_file() {
// Shows how to intercept requests and modify
// both the request and the response.
// The entire process of hijacking one request:
// browser --req-> rod ---> server ---> rod --res-> browser
//
// browser --req-> rod ---> server ---> rod --res-> browser
//
// The --req-> and --res-> are the parts that can be modified.
func Example_hijack_requests() {
browser := rod.New().MustConnect()
Expand Down
1 change: 1 addition & 0 deletions fixtures/gen-fonts/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use the google translate to translate "test" into all the languages, print the result into a html page.
// By reviewing the generated pdf we can find out what font is missing for a specific language.

// Package main ...
package main

import (
Expand Down
4 changes: 3 additions & 1 deletion hijack.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ func (b *Browser) HijackRequests() *HijackRouter {
// When use Fetch domain outside the router should be stopped. Enabling hijacking disables page caching,
// but such as 304 Not Modified will still work as expected.
// The entire process of hijacking one request:
// browser --req-> rod ---> server ---> rod --res-> browser
//
// browser --req-> rod ---> server ---> rod --res-> browser
//
// The --req-> and --res-> are the parts that can be modified.
func (p *Page) HijackRequests() *HijackRouter {
return newHijackRouter(p.browser, p).initEvents()
Expand Down
3 changes: 2 additions & 1 deletion input.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ func (ka *KeyActions) Do() (err error) {
}

// Make sure there's at least one release after the presses, such as:
// p1,p2,p1,r1 => p1,p2,p1,r1,r2
//
// p1,p2,p1,r1 => p1,p2,p1,r1,r2
func (ka *KeyActions) balance() []KeyAction {
actions := ka.Actions

Expand Down
1 change: 1 addition & 0 deletions lib/assets/assets.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// generated by "lib/assets/generate"

// Package assets ...
package assets

// MousePointer for rod
Expand Down
1 change: 1 addition & 0 deletions lib/assets/generate/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
7 changes: 3 additions & 4 deletions lib/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,9 @@ func init() {
// If you want to disable the global cli argument flag, set env DISABLE_ROD_FLAG.
// Values are separated by commas, key and value are separated by "=". For example:
//
// go run main.go -rod=show
// go run main.go -rod show,trace,slow=1s,monitor
// go run main.go --rod="slow=1s,dir=path/has /space,monitor=:9223"
//
// go run main.go -rod=show
// go run main.go -rod show,trace,slow=1s,monitor
// go run main.go --rod="slow=1s,dir=path/has /space,monitor=:9223"
func ResetWith(options string) {
Reset()

Expand Down
1 change: 1 addition & 0 deletions lib/devices/device.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package devices ...
package devices

import (
Expand Down
1 change: 1 addition & 0 deletions lib/devices/generate/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/examples/compare-chromedp/click/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/examples/compare-chromedp/cookie/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/examples/compare-chromedp/emulate/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/examples/compare-chromedp/eval/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/examples/compare-chromedp/headers/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/examples/compare-chromedp/keys/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/examples/compare-chromedp/logic/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/examples/compare-chromedp/remote/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/examples/compare-chromedp/screenshot/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
3 changes: 2 additions & 1 deletion lib/examples/compare-chromedp/submit/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand All @@ -8,7 +9,7 @@ import (
"github.com/go-rod/rod/lib/input"
)

//This example demonstrates how to fill out and submit a form.
// This example demonstrates how to fill out and submit a form.
func main() {
page := rod.New().MustConnect().MustPage("https://github.com/search")

Expand Down
1 change: 1 addition & 0 deletions lib/examples/compare-chromedp/text/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/examples/compare-chromedp/upload/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/examples/compare-chromedp/visible/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/examples/connect-browser/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/examples/custom-launch/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/examples/debug-deadlock/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/examples/disable-window-alert/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/examples/e2e-testing/calculator_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import "testing"
Expand Down
1 change: 1 addition & 0 deletions lib/examples/launch-managed/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/examples/stripe/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/examples/translator/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/examples/use-rod-like-chrome-extension/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/input/keyboard.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package input ...
package input

import (
Expand Down
4 changes: 2 additions & 2 deletions lib/js/generate/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand All @@ -11,8 +12,7 @@ import (

func main() {
list := getList()
out := `// generated by "lib/js/generate"` +
"\n\npackage js\n\n"
out := "// Package js generated by \"lib/js/generate\"\npackage js\n\n"

for _, fn := range list.Arr() {
name := fn.Get("name").Str()
Expand Down
3 changes: 1 addition & 2 deletions lib/js/helper.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// generated by "lib/js/generate"

// Package js generated by "lib/js/generate"
package js

// Element ...
Expand Down
1 change: 1 addition & 0 deletions lib/launcher/flags/flags.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package flags ...
package flags

// Flag name of a command line argument of the browser, also known as command line flag or switch.
Expand Down
3 changes: 2 additions & 1 deletion lib/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ func (l *Launcher) WorkingDir(path string) *Launcher {

// Env to launch the browser process. The default value is os.Environ().
// Usually you use it to set the timezone env. Such as:
// Env(append(os.Environ(), "TZ=Asia/Tokyo")...)
//
// Env(append(os.Environ(), "TZ=Asia/Tokyo")...)
func (l *Launcher) Env(env ...string) *Launcher {
return l.Set(flags.Env, env...)
}
Expand Down
13 changes: 6 additions & 7 deletions lib/launcher/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,13 @@ var _ http.Handler = &Manager{}
// pass to the browser when launch it remotely.
// The work flow looks like:
//
// | Machine X | Machine Y |
// | NewManaged("a.com") -|-> http.ListenAndServe("a.com", launcher.NewManager()) --> launch browser |
//
// 1. X send a http request to Y, Y respond default Launcher settings based the OS of Y.
// 2. X start a websocket connect to Y with the Launcher settings
// 3. Y launches a browser with the Launcher settings X
// 4. Y transparently proxy the websocket connect between X and the launched browser
// | Machine X | Machine Y |
// | NewManaged("a.com") -|-> http.ListenAndServe("a.com", launcher.NewManager()) --> launch browser |
//
// 1. X send a http request to Y, Y respond default Launcher settings based the OS of Y.
// 2. X start a websocket connect to Y with the Launcher settings
// 3. Y launches a browser with the Launcher settings X
// 4. Y transparently proxy the websocket connect between X and the launched browser
type Manager struct {
// Logger for key events
Logger utils.Logger
Expand Down
1 change: 1 addition & 0 deletions lib/launcher/revision/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
4 changes: 3 additions & 1 deletion lib/proto/a_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (

// TimeSinceEpoch UTC time in seconds, counted from January 1, 1970.
// To convert a time.Time to TimeSinceEpoch, for example:
// proto.TimeSinceEpoch(time.Now().Unix())
//
// proto.TimeSinceEpoch(time.Now().Unix())
//
// For session cookie, the value should be -1.
type TimeSinceEpoch float64

Expand Down
1 change: 1 addition & 0 deletions lib/proto/generate/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/utils/check-cov/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
3 changes: 2 additions & 1 deletion lib/utils/docker/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// The .github/workflows/docker.yml uses it as an github action
// and run it like this:
// DOCKER_TOKEN=$TOKEN go run ./lib/utils/docker $GITHUB_REF
//
// DOCKER_TOKEN=$TOKEN go run ./lib/utils/docker $GITHUB_REF
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/utils/get-browser/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/utils/lint/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/utils/rename/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/utils/setup/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import (
Expand Down
1 change: 1 addition & 0 deletions lib/utils/simple-check/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package main ...
package main

import "github.com/go-rod/rod/lib/utils"
Expand Down
1 change: 1 addition & 0 deletions lib/utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package utils ...
package utils

import (
Expand Down
20 changes: 9 additions & 11 deletions page.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,10 @@ func (p *Page) Close() error {
// Because modal dialog will block js, usually you have to trigger the dialog in another goroutine.
// For example:
//
// wait, handle := page.MustHandleDialog()
// go page.MustElement("button").MustClick()
// wait()
// handle(true, "")
//
// wait, handle := page.MustHandleDialog()
// go page.MustElement("button").MustClick()
// wait()
// handle(true, "")
func (p *Page) HandleDialog() (
wait func() *proto.PageJavascriptDialogOpening,
handle func(*proto.PageHandleJavaScriptDialog) error,
Expand Down Expand Up @@ -474,19 +473,18 @@ func (p *Page) WaitOpen() func() (*Page, error) {
// EachEvent of the specified event types, if any callback returns true the wait function will resolve,
// The type of each callback is (? means optional):
//
// func(proto.Event, proto.TargetSessionID?) bool?
// func(proto.Event, proto.TargetSessionID?) bool?
//
// You can listen to multiple event types at the same time like:
//
// browser.EachEvent(func(a *proto.A) {}, func(b *proto.B) {})
// browser.EachEvent(func(a *proto.A) {}, func(b *proto.B) {})
//
// Such as subscribe the events to know when the navigation is complete or when the page is rendered.
// Here's an example to dismiss all dialogs/alerts on the page:
//
// go page.EachEvent(func(e *proto.PageJavascriptDialogOpening) {
// _ = proto.PageHandleJavaScriptDialog{ Accept: false, PromptText: ""}.Call(page)
// })()
//
// go page.EachEvent(func(e *proto.PageJavascriptDialogOpening) {
// _ = proto.PageHandleJavaScriptDialog{ Accept: false, PromptText: ""}.Call(page)
// })()
func (p *Page) EachEvent(callbacks ...interface{}) (wait func()) {
return p.browser.Context(p.ctx).eachEvent(p.SessionID, callbacks...)
}
Expand Down

0 comments on commit 747e746

Please sign in to comment.