diff --git a/browser.go b/browser.go index b8c1bdc..7b38d0b 100644 --- a/browser.go +++ b/browser.go @@ -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 { diff --git a/chromedp_test.go b/chromedp_test.go index 018ad26..76e9877 100644 --- a/chromedp_test.go +++ b/chromedp_test.go @@ -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 { diff --git a/nav_test.go b/nav_test.go index 9a457c9..4b73dcd 100644 --- a/nav_test.go +++ b/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) }