Skip to content
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
17 changes: 11 additions & 6 deletions internal/browser/chrome_devtools.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@ const devtoolsSeed = `localStorage.setItem('screencast-enabled', 'false');
localStorage.setItem('disable-paused-state-overlay', 'true')`

// DevTools shows the front tab's DevTools in the pane, opening it first when
// the tab has none.
// the tab has none. An error names the step it stopped on: a deadline on a
// macos-latest runner gave nothing else to go on (#1195).
func (p *chromePage) DevTools(ctx context.Context) error {
front := p.tabs.frontTab()
if p.tabs.inspectedBy(front) == nil {
if err := p.openDevTools(ctx, front); err != nil {
return err
}
}
return p.present(func() { p.tabs.inspect(front) })
if err := p.present(func() { p.tabs.inspect(front) }); err != nil {
return fmt.Errorf("show DevTools in the pane: %w", err)
}
return nil
}

// openDevTools loads the browser's own DevTools front-end for t, served on
Expand All @@ -45,17 +49,18 @@ func (p *chromePage) DevTools(ctx context.Context) error {
func (p *chromePage) openDevTools(ctx context.Context, t *tab) error {
d, err := p.newDevTools(ctx)
if err != nil {
return err
return fmt.Errorf("open the DevTools window: %w", err)
}
if !p.tabs.setDevTools(t, d) {
p.closeTarget(d.id)
d.cancel()
return errNoTab
}
front := fmt.Sprintf("%[1]s/devtools/inspector.html?ws=127.0.0.1:%[2]s/devtools/page/%[3]s", devtoolsOrigin(p.port), p.port, t.id)
err = runOn(t.ctx, ctx, watchPauses)
if err == nil {
err = runOn(d.ctx, ctx, loadDevTools(front))
if err = runOn(t.ctx, ctx, watchPauses); err != nil {
err = fmt.Errorf("watch the page's debugger: %w", err)
} else if err = runOn(d.ctx, ctx, loadDevTools(front)); err != nil {
err = fmt.Errorf("load the DevTools front-end: %w", err)
}
if err != nil {
p.closeDevTools(t)
Expand Down
13 changes: 13 additions & 0 deletions internal/browser/chrome_devtools_live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,16 @@ func targetOpen(t *testing.T, p *chromePage, id target.ID) bool {
}
return slices.ContainsFunc(infos, func(i *target.Info) bool { return i.TargetID == id })
}

func TestChromeDevToolsPastItsDeadlineNamesTheStepItWasOn(t *testing.T) {
s, _, _ := devtoolsService(t, "/")
ctx, cancel := context.WithDeadline(context.Background(), time.Now())
defer cancel()
err := s.current("s").page.(*chromePage).DevTools(ctx)
if !errors.Is(err, context.DeadlineExceeded) || !strings.HasPrefix(err.Error(), "open the DevTools window: ") {
t.Fatalf("DevTools = %v, want the step named over context.DeadlineExceeded", err)
}
if d := s.current("s").page.(*chromePage).tabs.shown(); d != nil {
t.Fatal("a DevTools that never opened is shown in the pane")
}
}
Loading