get rid of all exceptions
We hadn't noticed a few uncaught exceptions being received from the browser, because the events were ignored. Start printing them via the error logger. The ones we were getting were caused by testAllocate running Navigate actions when the path argument was empty. Navigating to "testdata/" causes JS exceptions, as it's not a valid page. Instead, leave the new target pointing at a blank document.
This commit is contained in:
parent
c109f6ebfd
commit
7c1a9fbf3e
|
@ -14,6 +14,7 @@ import (
|
|||
|
||||
"github.com/chromedp/cdproto"
|
||||
"github.com/chromedp/cdproto/cdp"
|
||||
"github.com/chromedp/cdproto/runtime"
|
||||
"github.com/chromedp/cdproto/target"
|
||||
"github.com/mailru/easyjson"
|
||||
)
|
||||
|
@ -203,6 +204,14 @@ func (b *Browser) run(ctx context.Context) {
|
|||
// these events?
|
||||
continue
|
||||
}
|
||||
if msg.Method == cdproto.EventRuntimeExceptionThrown {
|
||||
ev := new(runtime.EventExceptionThrown)
|
||||
if err := json.Unmarshal(msg.Params, ev); err != nil {
|
||||
b.errf("%s", err)
|
||||
continue
|
||||
}
|
||||
b.errf("%+v\n", ev.ExceptionDetails)
|
||||
}
|
||||
|
||||
page, ok := b.pages[sessionID]
|
||||
if !ok {
|
||||
|
|
|
@ -23,8 +23,11 @@ var (
|
|||
func testAllocate(t *testing.T, path string) (_ context.Context, cancel func()) {
|
||||
ctx, cancel := NewContext(allocCtx)
|
||||
|
||||
if err := Run(ctx, Navigate(testdataDir+"/"+path)); err != nil {
|
||||
t.Fatal(err)
|
||||
// Only navigate if we want a path, otherwise leave the blank page.
|
||||
if path != "" {
|
||||
if err := Run(ctx, Navigate(testdataDir+"/"+path)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
//if err := WithLogf(t.Logf)(c.c); err != nil {
|
||||
|
|
12
nav_test.go
12
nav_test.go
|
@ -56,14 +56,14 @@ func TestNavigationEntries(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(entries) != 2 {
|
||||
t.Errorf("expected to have 2 navigation entry: got %d", len(entries))
|
||||
if len(entries) != 1 {
|
||||
t.Errorf("expected to have 1 navigation entry: got %d", len(entries))
|
||||
}
|
||||
if index != 1 {
|
||||
t.Errorf("expected navigation index is 1, got: %d", index)
|
||||
if index != 0 {
|
||||
t.Errorf("expected navigation index is 0, got: %d", index)
|
||||
}
|
||||
|
||||
expIdx, expEntries := 2, 3
|
||||
expIdx, expEntries := 1, 2
|
||||
for i, url := range tests {
|
||||
if err := Run(ctx, Navigate(testdataDir+"/"+url)); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -77,7 +77,7 @@ func TestNavigationEntries(t *testing.T) {
|
|||
if len(entries) != expEntries {
|
||||
t.Errorf("test %d expected to have %d navigation entry: got %d", i, expEntries, len(entries))
|
||||
}
|
||||
if want := int64(i + 2); index != want {
|
||||
if want := int64(i + 1); index != want {
|
||||
t.Errorf("test %d expected navigation index is %d, got: %d", i, want, index)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user