48 lines
2.2 KiB
Markdown
48 lines
2.2 KiB
Markdown
---
|
|
name: browser-screenshot-disk-and-cookies
|
|
description: Save omp managed-browser screenshots to real files (tab.screenshot path is silently ignored) and reset the shared Chromium cookie jar between persona captures.
|
|
---
|
|
|
|
# Screenshots to disk with the omp `browser` eval helper
|
|
|
|
## Traps (both cost a full re-capture to discover)
|
|
1. `tab.screenshot({ path })` **ignores `path` silently** — the option is not in
|
|
its schema (`{selector, fullPage, silent, annotate, format, quality, ifChanged, threshold}`).
|
|
The image attaches inline to the tool result and **nothing is written to disk**;
|
|
`ls` shows an empty dir. Inline images may also be dropped from transcript
|
|
archives later, so "attached to chat" is not "saved".
|
|
2. The shared managed Chromium keeps **cookies across tabs and turns** (profile
|
|
persists after `tab.close()`). A second capture script that expects the
|
|
anonymous view lands signed-in and `waitForSelector("testid/…")` fails fast.
|
|
|
|
## Procedure
|
|
Write files via `tab.run`, which exposes the raw Puppeteer `page` — its
|
|
`screenshot({path})` does write:
|
|
|
|
```js
|
|
const dir = "/tmp/<session-dir>";
|
|
const tab = await browser.open({ name: "caps", url });
|
|
const shot = (file) =>
|
|
tab.run(async ({ page }, f) => { await page.screenshot({ path: f }); return f; },
|
|
{ args: [`${dir}/${file}.png`] });
|
|
|
|
await tab.clearCookies(); // ALWAYS before an anonymous capture
|
|
await tab.goto(url);
|
|
await tab.waitForSelector("testid/first-state");
|
|
await shot("1-anonymous");
|
|
// ...drive states with direct helpers: click/fill("testid/<id>", ...) ...
|
|
await shot("2-next-state");
|
|
await tab.close();
|
|
```
|
|
|
|
Verify with `ls -la <dir> && file <dir>/*.png` — do not trust silent success.
|
|
|
|
## Notes
|
|
- Selectors accept `testid/<id>` handler; prefer it over CSS on `[data-testid]`.
|
|
- `tab.run(fn, { args })`: functions receive `{tab, page, browser, wait, assert}`
|
|
first, then each arg; a bare code string runs in an **isolated runtime, not the
|
|
page** — `document` is undefined there. Use direct helpers or `tab.evaluate`
|
|
(page-global expression; top-level `return` invalid) for page access.
|
|
- Byte-identical PNG sizes between two frames = same view; fine as proof of a
|
|
round-trip (state A → B → A).
|