diff --git a/src/browser/run/runner.test.ts b/src/browser/run/runner.test.ts index d525667e..b5c8a735 100644 --- a/src/browser/run/runner.test.ts +++ b/src/browser/run/runner.test.ts @@ -405,6 +405,14 @@ describe('runBrowserProgram', () => { expect(output.result).toBe('undefined'); }); + it('serializes a program with no explicit return as null', async () => { + const output = await run(` + await page.getByRole('button', { name: 'Save' }).click(); + `); + + expect(output.result).toBeNull(); + }); + it('keeps time, memory, output, redaction, and serialization limits', async () => { await expect(run('while (true) {}', { timeoutMs: 25 })).rejects.toMatchObject({ code: 'BROWSER_RUN_TIMEOUT', diff --git a/src/browser/run/runner.ts b/src/browser/run/runner.ts index 0cd8eb99..a37ccb96 100644 --- a/src/browser/run/runner.ts +++ b/src/browser/run/runner.ts @@ -446,7 +446,7 @@ export async function runBrowserProgram( rejectRun = undefined; } try { - const serialized = JSON.stringify(value); + const serialized = JSON.stringify(value === undefined ? null : value); if (serialized === undefined) throw new TypeError('Result is not JSON serializable.'); return serialized; } catch (cause) {