- name
- capture-playwright
- description
- Use when a screenshot or short video needs to be captured with Playwright and saved to local disk, with optional upload through `gh pr create|edit|comment --attach` or `gh issue comment --attach` (upload requires explicit user approval and must target a PR or issue).
# capture-playwright
Generate the artifact with Playwright and save it to local disk. **Do not upload by default.**
## Upload Policy
- **Never upload screenshots or videos that are not attached to a specific PR or issue.** Standalone uploads with no PR/issue target are forbidden.
- **Default is local-only.** Always save artifacts to disk first. Treat that as the finished output unless the user explicitly asks for an upload.
- **Before uploading any image or video, prompt the user for confirmation.** Ask the user to approve the upload, stating the file path and the target PR/issue. No exceptions — even if the workflow calls for it, ask first.
- **NEVER UPLOAD AN IMAGE THAT WAS GENERATED BY POINTING AT A LIVE PREEXISTING kenn-forge APP** This poses risks to leak sensitive information via screenshot
## Workflow
1. Prefer the repo's existing Playwright config and startup flow. Only add a temporary script or spec if no existing path can capture the state; delete temporary capture code afterward.
2. Save artifacts under a temp path like `tmp/` or `artifacts/` unless the user explicitly wants them committed.
3. For screenshots, use Playwright directly:
```js
await page.screenshot({ path: "tmp/capture.png", fullPage: true });
```
4. For video, create a recording context, close it, then resolve the generated file:
```js
const context = await browser.newContext({
recordVideo: { dir: "tmp/video", size: { width: 1440, height: 900 } },
});
const page = await context.newPage();
// ... drive the page ...
await context.close();
const videoPath = await page.video()?.path();
```
5. **Stop here by default.** Report the local artifact path to the user and open the image / video using `open` or `xdg-open` so that user can see the image. Only proceed to upload if the user explicitly requests it.
6. **If the user approves upload**, confirm the repository and target PR or issue, including a PR about to be created. Upload and attach with `--attach`, which requires GitHub CLI 2.99.0 or later. If the upload is refused, keep the local file and report the error.
```bash
gh pr create --repo owner/repo --title "<title>" --body-file pr.md --attach tmp/capture.png
gh pr edit <number> --repo owner/repo --attach tmp/capture.png
gh pr comment <number> --repo owner/repo --body-file comment.md --attach tmp/capture.png
# or for issues:
gh issue comment <number> --repo owner/repo --body-file comment.md --attach tmp/capture.png
```
For screenshot alt text, use `--attach "tmp/capture.png#The rendered view"`.
Files the body doesn't reference are appended to the end of the comment or PR body. Use `` in the body to place a screenshot. Videos render as players and take no alt text.
If video upload is rejected, ask whether a screenshot or a different upload path is preferred.
## Output
Return:
- the local artifact path (always)
- if uploaded: the comment or PR URL printed by `gh` and the target PR/issue
- a brief note if video upload had to fall back to screenshots or another path
Voir sur GitHub