diff --git a/internal/driver/chrome/driver.go b/internal/driver/chrome/driver.go index db51c01..06914bd 100644 --- a/internal/driver/chrome/driver.go +++ b/internal/driver/chrome/driver.go @@ -887,6 +887,30 @@ func (d *Driver) SetLastAction(ctx context.Context, encoded json.RawMessage) err return nil } +// SetLogs installs the entries this step's log fetch returned as state.logs +// inside the page runtime. The page cannot derive them: console output reaches +// the driver over CDP and nothing in the page reads it back. Without this call +// every web state.logs is empty, and since the page's reading of an extractor +// replaces the host's, the default noLogcatErrors then reports green on a run +// whose console was full of errors. +// +// Unguarded for the same reason as SetLastAction: on a page with no setter, +// "the page cannot accept logs" has to fail the run rather than be reported as +// a successful install. +func (d *Driver) SetLogs(ctx context.Context, encoded json.RawMessage) error { + payload := strings.TrimSpace(string(encoded)) + if payload == "" { + payload = "[]" + } + script := fmt.Sprintf(`window.__sanderlingSetLogs__(%s)`, payload) + runCtx, cancel := d.runCtx(ctx) + defer cancel() + if err := chromedp.Run(runCtx, chromedp.Evaluate(script, nil)); err != nil { + return fmt.Errorf("set logs: %w", err) + } + return nil +} + // extractorScript resolves the extractor table once the page is not mid route // transition, giving up on that wait after %d ms. // diff --git a/internal/driver/chrome/driver_test.go b/internal/driver/chrome/driver_test.go index 36ef3fb..a0708a4 100644 --- a/internal/driver/chrome/driver_test.go +++ b/internal/driver/chrome/driver_test.go @@ -860,6 +860,54 @@ func TestSetLastAction_ReportsAPageThatCannotTakeIt(t *testing.T) { } } +// TestSetLogs_ReportsAPageThatCannotTakeThem is the same install on the channel +// the log properties hang off. The driver holding a console error changes +// nothing on web: the page's reading of every extractor replaces the host's, so +// unless the entries are put back into the page, noLogcatErrors counts an empty +// array and stays green through a run full of errors. +func TestSetLogs_ReportsAPageThatCannotTakeThem(t *testing.T) { + const withSetter = `
` + const withoutSetter = `