|
| 1 | +--- |
| 2 | +title: "GitHub inline video embedding via programmatic browser upload" |
| 3 | +category: integrations |
| 4 | +date: 2026-03-22 |
| 5 | +tags: |
| 6 | + - github |
| 7 | + - video-embedding |
| 8 | + - agent-browser |
| 9 | + - playwright |
| 10 | + - feature-video |
| 11 | + - pr-description |
| 12 | +related_to: |
| 13 | + - plugins/compound-engineering/skills/feature-video/SKILL.md |
| 14 | + - plugins/compound-engineering/skills/agent-browser/SKILL.md |
| 15 | + - plugins/compound-engineering/skills/agent-browser/references/authentication.md |
| 16 | +--- |
| 17 | + |
| 18 | +# GitHub Native Video Upload for PRs |
| 19 | + |
| 20 | +## Problem |
| 21 | + |
| 22 | +Embedding video demos in GitHub PR descriptions required external storage (R2/rclone) |
| 23 | +or GitHub Release assets. Release asset URLs render as plain download links, not inline |
| 24 | +video players. Only `user-attachments/assets/` URLs render with GitHub's native inline |
| 25 | +video player -- the same result as pasting a video into the PR editor manually. |
| 26 | + |
| 27 | +The distinction is absolute: |
| 28 | + |
| 29 | +| URL namespace | Rendering | |
| 30 | +|---|---| |
| 31 | +| `github.com/releases/download/...` | Plain download link (bad UX, triggers download on mobile) | |
| 32 | +| `github.com/user-attachments/assets/...` | Native inline `<video>` player with controls | |
| 33 | + |
| 34 | +## Investigation |
| 35 | + |
| 36 | +1. **Public upload API** -- No public API exists. The `/upload/policies/assets` endpoint |
| 37 | + requires browser session cookies and is not exposed via REST or GraphQL. GitHub CLI |
| 38 | + (`gh`) has no support; issues cli/cli#1895, #4228, and #4465 are all closed as |
| 39 | + "not planned". GitHub keeps this private to limit abuse surface (malware hosting, |
| 40 | + spam CDN, DMCA liability). |
| 41 | + |
| 42 | +2. **Release asset approach (Strategy B)** -- URLs render as download links, not video |
| 43 | + players. Clickable GIF previews trigger downloads on mobile. Unacceptable UX. |
| 44 | + |
| 45 | +3. **Claude-in-Chrome JavaScript injection with base64** -- Blocked by CSP/mixed-content |
| 46 | + policy. HTTPS github.com cannot fetch from HTTP localhost. Base64 chunking is possible |
| 47 | + but does not scale for larger videos. |
| 48 | + |
| 49 | +4. **`tonkotsuboy/github-upload-image-to-pr`** -- Open-source reference confirming |
| 50 | + browser automation is the only working approach for producing native URLs. |
| 51 | + |
| 52 | +5. **agent-browser `upload` command** -- Works. Playwright sets files directly on hidden |
| 53 | + file inputs without base64 encoding or fetch requests. CSP is not a factor because |
| 54 | + Playwright's `setInputFiles` operates at the browser engine level, not via JavaScript. |
| 55 | + |
| 56 | +## Working Solution |
| 57 | + |
| 58 | +### Upload flow |
| 59 | + |
| 60 | +```bash |
| 61 | +# Navigate to PR page (authenticated Chrome session) |
| 62 | +agent-browser --engine chrome --session-name github \ |
| 63 | + open "https://github.com/[owner]/[repo]/pull/[number]" |
| 64 | +agent-browser scroll down 5000 |
| 65 | + |
| 66 | +# Upload video via the hidden file input |
| 67 | +agent-browser upload '#fc-new_comment_field' tmp/videos/feature-demo.mp4 |
| 68 | + |
| 69 | +# Wait for GitHub to process the upload (typically 3-5 seconds) |
| 70 | +agent-browser wait 5000 |
| 71 | + |
| 72 | +# Extract the URL GitHub injected into the textarea |
| 73 | +agent-browser eval "document.getElementById('new_comment_field').value" |
| 74 | +# Returns: https://github.com/user-attachments/assets/[uuid] |
| 75 | + |
| 76 | +# Clear the textarea without submitting (upload already persisted server-side) |
| 77 | +agent-browser eval "const ta = document.getElementById('new_comment_field'); \ |
| 78 | + ta.value = ''; ta.dispatchEvent(new Event('input', { bubbles: true }))" |
| 79 | + |
| 80 | +# Embed in PR description (URL on its own line renders as inline video player) |
| 81 | +gh pr edit [number] --body "[body with video URL on its own line]" |
| 82 | +``` |
| 83 | + |
| 84 | +### Key selectors (validated March 2026) |
| 85 | + |
| 86 | +| Selector | Element | Purpose | |
| 87 | +|---|---|---| |
| 88 | +| `#fc-new_comment_field` | Hidden `<input type="file">` | Target for `agent-browser upload`. Accepts `.mp4`, `.mov`, `.webm` and many other types. | |
| 89 | +| `#new_comment_field` | `<textarea>` | GitHub injects the `user-attachments/assets/` URL here after processing the upload. | |
| 90 | + |
| 91 | +GitHub's comment form contains the hidden file input. After Playwright sets the file, |
| 92 | +GitHub uploads it server-side and injects a markdown URL into the textarea. The upload |
| 93 | +is persisted even if the form is never submitted. |
| 94 | + |
| 95 | +## What Was Removed |
| 96 | + |
| 97 | +The following approaches were removed from the feature-video skill: |
| 98 | + |
| 99 | +- R2/rclone setup and configuration |
| 100 | +- Release asset upload flow (`gh release upload`) |
| 101 | +- GIF preview generation (unnecessary with native inline video player) |
| 102 | +- Strategy B fallback logic |
| 103 | + |
| 104 | +Total: approximately 100 lines of SKILL.md content removed. The skill is now simpler |
| 105 | +and has zero external storage dependencies. |
| 106 | + |
| 107 | +## Prevention |
| 108 | + |
| 109 | +### URL validation |
| 110 | + |
| 111 | +After any upload step, confirm the extracted URL contains `user-attachments/assets/` |
| 112 | +before writing it into the PR description. If the URL does not match, the upload failed |
| 113 | +or used the wrong method. |
| 114 | + |
| 115 | +### Upload failure handling |
| 116 | + |
| 117 | +If the textarea is empty after the wait, check: |
| 118 | +1. Session validity (did GitHub redirect to login?) |
| 119 | +2. Wait time (processing can be slow under load -- retry after 3-5 more seconds) |
| 120 | +3. File size (10MB free, 100MB paid accounts) |
| 121 | + |
| 122 | +Do not silently substitute a release asset URL. Report the failure and offer to retry. |
| 123 | + |
| 124 | +### DOM selector fragility |
| 125 | + |
| 126 | +`#fc-new_comment_field` and `#new_comment_field` are GitHub's internal element IDs and |
| 127 | +may change in future UI updates. If the upload stops working, snapshot the PR page and |
| 128 | +inspect the current comment form structure for updated selectors. |
| 129 | + |
| 130 | +### Size limits |
| 131 | + |
| 132 | +- Free accounts: 10MB per file |
| 133 | +- Paid (Pro, Team, Enterprise): 100MB per file |
| 134 | + |
| 135 | +Check file size before attempting upload. Re-encode at lower quality if needed. |
| 136 | + |
| 137 | +## References |
| 138 | + |
| 139 | +- GitHub CLI issues: cli/cli#1895, #4228, #4465 (all closed "not planned") |
| 140 | +- `tonkotsuboy/github-upload-image-to-pr` -- reference implementation |
| 141 | +- GitHub Community Discussions: #29993, #46951, #28219 |
0 commit comments