Skip to content

Commit

Permalink
better doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmood committed Jul 18, 2023
1 parent 2269341 commit d07e353
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func (b *Browser) PageFromTarget(targetID proto.TargetTargetID) (*Page, error) {
return page, nil
}

// EachEvent is similar to Page.EachEvent, but catches events of the entire browser.
// EachEvent is similar to [Page.EachEvent], but catches events of the entire browser.
func (b *Browser) EachEvent(callbacks ...interface{}) (wait func()) {
return b.eachEvent("", callbacks...)
}
Expand Down
4 changes: 2 additions & 2 deletions element.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,12 +696,12 @@ func (el *Element) Call(ctx context.Context, sessionID, methodName string, param
return el.page.Call(ctx, sessionID, methodName, params)
}

// Eval is a shortcut for Element.Evaluate with AwaitPromise, ByValue and AutoExp set to true.
// Eval is a shortcut for [Element.Evaluate] with AwaitPromise, ByValue and AutoExp set to true.
func (el *Element) Eval(js string, params ...interface{}) (*proto.RuntimeRemoteObject, error) {
return el.Evaluate(Eval(js, params...).ByPromise())
}

// Evaluate is just a shortcut of Page.Evaluate with This set to current element.
// Evaluate is just a shortcut of [Page.Evaluate] with This set to current element.
func (el *Element) Evaluate(opts *EvalOptions) (*proto.RuntimeRemoteObject, error) {
return el.page.Context(el.ctx).Evaluate(opts.This(el.Object))
}
Expand Down
2 changes: 1 addition & 1 deletion examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func Example_disable_headless_to_debug() {
// Context will be recursively passed to all sub-methods.
// For example, methods like Page.Context(ctx) will return a clone of the page with the ctx,
// all the methods of the returned page will use the ctx if they have IO blocking operations.
// Page.Timeout or Page.WithCancel is just a shortcut for Page.Context.
// [Page.Timeout] or [Page.WithCancel] is just a shortcut for Page.Context.
// Of course, Browser or Element works the same way.
func Example_context_and_timeout() {
page := rod.New().MustConnect().MustPage("https://github.com")
Expand Down
4 changes: 2 additions & 2 deletions input.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func (m *Mouse) Up(button proto.InputMouseButton, clickCount int) error {
return nil
}

// Click the button. It's the combination of Mouse.Down and Mouse.Up
// Click the button. It's the combination of [Mouse.Down] and [Mouse.Up]
func (m *Mouse) Click(button proto.InputMouseButton, clickCount int) error {
m.page.browser.trySlowMotion()

Expand All @@ -389,7 +389,7 @@ func (m *Mouse) Click(button proto.InputMouseButton, clickCount int) error {
return m.Up(button, clickCount)
}

// Touch presents a touch device, such as a hand with fingers, each finger is a proto.InputTouchPoint.
// Touch presents a touch device, such as a hand with fingers, each finger is a [proto.InputTouchPoint].
// Touch events is stateless, we use the struct here only as a namespace to make the API style unified.
type Touch struct {
page *Page
Expand Down
2 changes: 1 addition & 1 deletion must.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Their function names are all prefixed with Must.
// A function here is usually a wrapper for the error version with fixed default options to make it easier to use.
//
// For example the source code of `Element.Click` and `Element.MustClick`. `MustClick` has no argument.
// For example the source code of [Element.Click] and [Element.MustClick]. MustClick has no argument.
// But `Click` has a `button` argument to decide which button to click.
// `MustClick` feels like a version of `Click` with some default behaviors.

Expand Down
6 changes: 3 additions & 3 deletions page.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ func (p *Page) WaitNavigation(name proto.PageLifecycleEventName) func() {

// WaitRequestIdle returns a wait function that waits until no request for d duration.
// Be careful, d is not the max wait timeout, it's the least idle time.
// If you want to set a timeout you can use the "Page.Timeout" function.
// If you want to set a timeout you can use the [Page.Timeout] function.
// Use the includes and excludes regexp list to filter the requests by their url.
func (p *Page) WaitRequestIdle(d time.Duration, includes, excludes []string, excludeTypes []proto.NetworkResourceType) func() {
defer p.tryTrace(TraceTypeWait, "request-idle")()
Expand Down Expand Up @@ -649,7 +649,7 @@ func (p *Page) WaitRequestIdle(d time.Duration, includes, excludes []string, exc

// WaitDOMStable waits until the change of the DOM tree is less or equal than diff percent for d duration.
// Be careful, d is not the max wait timeout, it's the least stable time.
// If you want to set a timeout you can use the "Page.Timeout" function.
// If you want to set a timeout you can use the [Page.Timeout] function.
func (p *Page) WaitDOMStable(d time.Duration, diff float64) error {
defer p.tryTrace(TraceTypeWait, "dom-stable")()

Expand Down Expand Up @@ -776,7 +776,7 @@ func (p *Page) Wait(opts *EvalOptions) error {
})
}

// WaitElementsMoreThan Wait until there are more than <num> <selector> elements.
// WaitElementsMoreThan waits until there are more than num elements that match the selector.
func (p *Page) WaitElementsMoreThan(selector string, num int) error {
return p.Wait(Eval(`(s, n) => document.querySelectorAll(s).length > n`, selector, num))
}
Expand Down
6 changes: 3 additions & 3 deletions page_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type EvalOptions struct {
JS string

// JSArgs represents the arguments that will be passed to JS.
// If an argument is *proto.RuntimeRemoteObject type, the corresponding remote object will be used.
// If an argument is *[proto.RuntimeRemoteObject] type, the corresponding remote object will be used.
// Or it will be passed as a plain JSON value.
// When an arg in the args is a *js.Function, the arg will be cached on the page's js context.
// When the arg.Name exists in the page's cache, it reuse the cache without sending the definition to the browser again.
Expand All @@ -41,7 +41,7 @@ type EvalOptions struct {
UserGesture bool
}

// Eval creates a EvalOptions with ByValue set to true.
// Eval creates a [EvalOptions] with ByValue set to true.
func Eval(js string, args ...interface{}) *EvalOptions {
return &EvalOptions{
ByValue: true,
Expand Down Expand Up @@ -113,7 +113,7 @@ func (e *EvalOptions) formatToJSFunc() string {
return fmt.Sprintf(`function() { return (%s).apply(this, arguments) }`, js)
}

// Eval is a shortcut for Page.Evaluate with AwaitPromise, ByValue set to true.
// Eval is a shortcut for [Page.Evaluate] with AwaitPromise, ByValue set to true.
func (p *Page) Eval(js string, args ...interface{}) (*proto.RuntimeRemoteObject, error) {
return p.Evaluate(Eval(js, args...).ByPromise())
}
Expand Down

0 comments on commit d07e353

Please sign in to comment.