Skip to content
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

allow setting panic func for browsers #433

Merged
merged 3 commits into from
Jun 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type Browser struct {
// BrowserContextID is the id for incognito window
BrowserContextID proto.BrowserBrowserContextID

e func(args ...interface{})

ctx context.Context

sleeper func() utils.Sleeper
Expand All @@ -60,7 +62,7 @@ type Browser struct {
// DefaultDevice is set to devices.LaptopWithMDPIScreen.Landescape() . You can use
// NoDefaultDevice to disable it.
func New() *Browser {
return &Browser{
return (&Browser{
ctx: context.Background(),
sleeper: DefaultSleeper,
slowMotion: defaults.Slow,
Expand All @@ -70,7 +72,7 @@ func New() *Browser {
defaultDevice: devices.LaptopWithMDPIScreen.Landescape(),
targetsLock: &sync.Mutex{},
states: &sync.Map{},
}
}).WithPanic(utils.Panic)
}

// Incognito creates a new incognito browser
Expand Down Expand Up @@ -248,6 +250,7 @@ func (b *Browser) Call(ctx context.Context, sessionID, methodName string, params
// PageFromSession is used for low-level debugging
func (b *Browser) PageFromSession(sessionID proto.TargetSessionID) *Page {
return &Page{
e: b.e,
ctx: b.ctx,
sleeper: b.sleeper,
browser: b,
Expand All @@ -274,6 +277,7 @@ func (b *Browser) PageFromTarget(targetID proto.TargetTargetID) (*Page, error) {
}

page = &Page{
e: b.e,
ctx: b.ctx,
sleeper: b.sleeper,
browser: b,
Expand Down
2 changes: 2 additions & 0 deletions element.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ var _ proto.Sessionable = &Element{}
type Element struct {
Object *proto.RuntimeRemoteObject

e func(args ...interface{})

ctx context.Context

sleeper func() utils.Sleeper
Expand Down
4 changes: 4 additions & 0 deletions hijack.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ func (r *HijackRouter) new(ctx context.Context, e *proto.FetchRequestPaused) *Hi
},
},
OnError: func(err error) {},

browser: r.browser,
}
}

Expand Down Expand Up @@ -208,6 +210,8 @@ type Hijack struct {

// CustomState is used to store things for this context
CustomState interface{}

browser *Browser
}

// ContinueRequest without hijacking. The RequestID will be set by the router, you don't have to set it.
Expand Down
5 changes: 4 additions & 1 deletion lib/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ func MultiLogger(list ...Logger) Log {
})
}

// Panic is the same as the built-in panic
var Panic = func(v interface{}) { panic(v) }

// E if the last arg is error, panic it
func E(args ...interface{}) []interface{} {
err, ok := args[len(args)-1].(error)
if ok {
panic(err)
Panic(err)
}
return args
}
Expand Down
Loading