Skip to content

Commit

Permalink
fix retry of nil context
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmood committed Feb 19, 2020
1 parent ff24514 commit 77f29c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions page.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ func (p *Page) EvalE(byValue bool, thisID, js string, jsArgs []interface{}) (res
if p.windowObjectID == "" {
err := p.initJS()
if err != nil {
if isNilContextErr(err) {
return false, nil
}
return true, err
}
}
Expand All @@ -365,8 +368,7 @@ func (p *Page) EvalE(byValue bool, thisID, js string, jsArgs []interface{}) (res
res, err = p.CallE("Runtime.callFunctionOn", params)

if thisID == "" {
cdpErr, ok := err.(*cdp.Error)
if ok && cdpErr.Code == -32000 {
if isNilContextErr(err) {
_ = p.initJS()
return false, nil
}
Expand Down
8 changes: 8 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ func Method(name string) EventFilter {
return name == e.Method
}
}

func isNilContextErr(err error) bool {
if err == nil {
return false
}
cdpErr, ok := err.(*cdp.Error)
return ok && cdpErr.Code == -32000
}

0 comments on commit 77f29c0

Please sign in to comment.