Composer: previews under the page's policy, HEIC to JPEG, quieter focus
Paul, staging 8334e25, an iPhone: the chip was an empty square. The page's CSP allows data: images only; the previews were blob: URLs. They are now drawn on a canvas as data: JPEGs. A HEIC photo is converted to JPEG (0.85) before upload, as is any image over 2560 px; paste reads clipboard items (iOS long-press paste). Chips: a 60 px cover-fitted square with a hairline edge, the x a 20 px circle over the corner, a progress bar over the foot. The pill's focus steps 10% with no ring. The test instance sends production's CSP. TestWebKitAttachments (390, dark and light) and TestBrowserComposer assert the previews load; both failed first on 8334e25's scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
36 files changed,
+377
−42
docs/mockups/built/2026-11-08/composer-after-chip-webkit-dark-390.pngbinarydocs/mockups/built/2026-11-08/composer-after-chip-webkit-light-390.pngbinarydocs/mockups/built/2026-11-08/composer-after-chips-1280.pngbinarydocs/mockups/built/2026-11-08/composer-after-chips-390.pngbinarydocs/mockups/built/2026-11-08/composer-after-errors-1280.pngbinarydocs/mockups/built/2026-11-08/composer-after-errors-390.pngbinarydocs/mockups/built/2026-11-08/composer-after-feed-1280.pngbinarydocs/mockups/built/2026-11-08/composer-after-feed-390.pngbinarydocs/mockups/built/2026-11-08/composer-after-feed-webkit-dark-390.pngbinarydocs/mockups/built/2026-11-08/composer-after-feed-webkit-light-390.pngbinarydocs/mockups/built/2026-11-08/composer-after-full-size-1280.pngbinarydocs/mockups/built/2026-11-08/composer-after-full-size-390.pngbinarydocs/mockups/built/2026-11-08/composer-after-lines-dark-1280.pngbinarydocs/mockups/built/2026-11-08/composer-after-lines-dark-390.pngbinarydocs/mockups/built/2026-11-08/composer-after-lines-light-1280.pngbinarydocs/mockups/built/2026-11-08/composer-after-lines-light-390.pngbinarydocs/mockups/built/2026-11-08/composer-after-menu-1280.pngbinarydocs/mockups/built/2026-11-08/composer-after-menu-390.pngbinarydocs/mockups/built/2026-11-08/composer-after-rest-dark-1280.pngbinarydocs/mockups/built/2026-11-08/composer-after-rest-dark-390.pngbinarydocs/mockups/built/2026-11-08/composer-after-rest-light-1280.pngbinarydocs/mockups/built/2026-11-08/composer-after-rest-light-390.pngbinarydocs/mockups/built/2026-11-08/composer-focus-focused-dark-390.pngbinarydocs/mockups/built/2026-11-08/composer-focus-focused-light-390.pngbinarydocs/mockups/built/2026-11-08/composer-focus-rest-dark-390.pngbinarydocs/mockups/built/2026-11-08/composer-focus-rest-light-390.pngbinarydocs/superpowers/plans/COMPOSER-PROGRESS.md+46 −0internal/equipo/static/chat-attach.js+84 −20internal/equipo/static/chat-compose.js+3 −0internal/equipo/static/chat-stream.js+1 −1internal/equipo/static/equipo.css+24 −19internal/headless/browser_attach_test.go+19 −1internal/thintest/attach_webkit_test.go+82 −0internal/thintest/instance.go+19 −1internal/thintest/testdata/attach.mjs+78 −0scripts/runner-reference-allowlist.json+21 −0
CI passed — run details
diff --git a/docs/mockups/built/2026-11-08/composer-after-chip-webkit-dark-390.png b/docs/mockups/built/2026-11-08/composer-after-chip-webkit-dark-390.png| new file mode 100644 |
| index 00000000..94795981 |
| Binary files /dev/null and b/docs/mockups/built/2026-11-08/composer-after-chip-webkit-dark-390.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-after-chip-webkit-light-390.png b/docs/mockups/built/2026-11-08/composer-after-chip-webkit-light-390.png| new file mode 100644 |
| index 00000000..ed654b98 |
| Binary files /dev/null and b/docs/mockups/built/2026-11-08/composer-after-chip-webkit-light-390.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-after-chips-1280.png b/docs/mockups/built/2026-11-08/composer-after-chips-1280.png| index 74119d47..18950c58 100644 |
| Binary files a/docs/mockups/built/2026-11-08/composer-after-chips-1280.png and b/docs/mockups/built/2026-11-08/composer-after-chips-1280.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-after-chips-390.png b/docs/mockups/built/2026-11-08/composer-after-chips-390.png| index 4debb027..f3628c5c 100644 |
| Binary files a/docs/mockups/built/2026-11-08/composer-after-chips-390.png and b/docs/mockups/built/2026-11-08/composer-after-chips-390.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-after-errors-1280.png b/docs/mockups/built/2026-11-08/composer-after-errors-1280.png| index ace862e1..4edc10a5 100644 |
| Binary files a/docs/mockups/built/2026-11-08/composer-after-errors-1280.png and b/docs/mockups/built/2026-11-08/composer-after-errors-1280.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-after-errors-390.png b/docs/mockups/built/2026-11-08/composer-after-errors-390.png| index 8a503661..8771c0b0 100644 |
| Binary files a/docs/mockups/built/2026-11-08/composer-after-errors-390.png and b/docs/mockups/built/2026-11-08/composer-after-errors-390.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-after-feed-1280.png b/docs/mockups/built/2026-11-08/composer-after-feed-1280.png| index a9889c27..9420a0fb 100644 |
| Binary files a/docs/mockups/built/2026-11-08/composer-after-feed-1280.png and b/docs/mockups/built/2026-11-08/composer-after-feed-1280.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-after-feed-390.png b/docs/mockups/built/2026-11-08/composer-after-feed-390.png| index 823313d8..4e4ad0f4 100644 |
| Binary files a/docs/mockups/built/2026-11-08/composer-after-feed-390.png and b/docs/mockups/built/2026-11-08/composer-after-feed-390.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-after-feed-webkit-dark-390.png b/docs/mockups/built/2026-11-08/composer-after-feed-webkit-dark-390.png| new file mode 100644 |
| index 00000000..90003708 |
| Binary files /dev/null and b/docs/mockups/built/2026-11-08/composer-after-feed-webkit-dark-390.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-after-feed-webkit-light-390.png b/docs/mockups/built/2026-11-08/composer-after-feed-webkit-light-390.png| new file mode 100644 |
| index 00000000..86d15c08 |
| Binary files /dev/null and b/docs/mockups/built/2026-11-08/composer-after-feed-webkit-light-390.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-after-full-size-1280.png b/docs/mockups/built/2026-11-08/composer-after-full-size-1280.png| index 6a1bc448..6ed83270 100644 |
| Binary files a/docs/mockups/built/2026-11-08/composer-after-full-size-1280.png and b/docs/mockups/built/2026-11-08/composer-after-full-size-1280.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-after-full-size-390.png b/docs/mockups/built/2026-11-08/composer-after-full-size-390.png| index 88a3c8b2..574f5dbc 100644 |
| Binary files a/docs/mockups/built/2026-11-08/composer-after-full-size-390.png and b/docs/mockups/built/2026-11-08/composer-after-full-size-390.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-after-lines-dark-1280.png b/docs/mockups/built/2026-11-08/composer-after-lines-dark-1280.png| index dec73feb..752bae33 100644 |
| Binary files a/docs/mockups/built/2026-11-08/composer-after-lines-dark-1280.png and b/docs/mockups/built/2026-11-08/composer-after-lines-dark-1280.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-after-lines-dark-390.png b/docs/mockups/built/2026-11-08/composer-after-lines-dark-390.png| index 2768a2ea..8dbd23e9 100644 |
| Binary files a/docs/mockups/built/2026-11-08/composer-after-lines-dark-390.png and b/docs/mockups/built/2026-11-08/composer-after-lines-dark-390.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-after-lines-light-1280.png b/docs/mockups/built/2026-11-08/composer-after-lines-light-1280.png| index b44a6136..2bd8cd9c 100644 |
| Binary files a/docs/mockups/built/2026-11-08/composer-after-lines-light-1280.png and b/docs/mockups/built/2026-11-08/composer-after-lines-light-1280.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-after-lines-light-390.png b/docs/mockups/built/2026-11-08/composer-after-lines-light-390.png| index 2d72d009..daeaf87a 100644 |
| Binary files a/docs/mockups/built/2026-11-08/composer-after-lines-light-390.png and b/docs/mockups/built/2026-11-08/composer-after-lines-light-390.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-after-menu-1280.png b/docs/mockups/built/2026-11-08/composer-after-menu-1280.png| index 0825ead5..edf20071 100644 |
| Binary files a/docs/mockups/built/2026-11-08/composer-after-menu-1280.png and b/docs/mockups/built/2026-11-08/composer-after-menu-1280.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-after-menu-390.png b/docs/mockups/built/2026-11-08/composer-after-menu-390.png| index 43ab5bc2..d2fd2ade 100644 |
| Binary files a/docs/mockups/built/2026-11-08/composer-after-menu-390.png and b/docs/mockups/built/2026-11-08/composer-after-menu-390.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-after-rest-dark-1280.png b/docs/mockups/built/2026-11-08/composer-after-rest-dark-1280.png| index fc5a57a0..2d86fa7f 100644 |
| Binary files a/docs/mockups/built/2026-11-08/composer-after-rest-dark-1280.png and b/docs/mockups/built/2026-11-08/composer-after-rest-dark-1280.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-after-rest-dark-390.png b/docs/mockups/built/2026-11-08/composer-after-rest-dark-390.png| index 912a136e..bdb8b5f3 100644 |
| Binary files a/docs/mockups/built/2026-11-08/composer-after-rest-dark-390.png and b/docs/mockups/built/2026-11-08/composer-after-rest-dark-390.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-after-rest-light-1280.png b/docs/mockups/built/2026-11-08/composer-after-rest-light-1280.png| index f4a62e40..4f7d18af 100644 |
| Binary files a/docs/mockups/built/2026-11-08/composer-after-rest-light-1280.png and b/docs/mockups/built/2026-11-08/composer-after-rest-light-1280.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-after-rest-light-390.png b/docs/mockups/built/2026-11-08/composer-after-rest-light-390.png| index 174da629..ee7bf3de 100644 |
| Binary files a/docs/mockups/built/2026-11-08/composer-after-rest-light-390.png and b/docs/mockups/built/2026-11-08/composer-after-rest-light-390.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-focus-focused-dark-390.png b/docs/mockups/built/2026-11-08/composer-focus-focused-dark-390.png| new file mode 100644 |
| index 00000000..b43d4819 |
| Binary files /dev/null and b/docs/mockups/built/2026-11-08/composer-focus-focused-dark-390.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-focus-focused-light-390.png b/docs/mockups/built/2026-11-08/composer-focus-focused-light-390.png| new file mode 100644 |
| index 00000000..7c81f814 |
| Binary files /dev/null and b/docs/mockups/built/2026-11-08/composer-focus-focused-light-390.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-focus-rest-dark-390.png b/docs/mockups/built/2026-11-08/composer-focus-rest-dark-390.png| new file mode 100644 |
| index 00000000..9df92aa6 |
| Binary files /dev/null and b/docs/mockups/built/2026-11-08/composer-focus-rest-dark-390.png differ |
diff --git a/docs/mockups/built/2026-11-08/composer-focus-rest-light-390.png b/docs/mockups/built/2026-11-08/composer-focus-rest-light-390.png| new file mode 100644 |
| index 00000000..38f300cc |
| Binary files /dev/null and b/docs/mockups/built/2026-11-08/composer-focus-rest-light-390.png differ |
diff --git a/docs/superpowers/plans/COMPOSER-PROGRESS.md b/docs/superpowers/plans/COMPOSER-PROGRESS.md| index d07724cb..8ab0d6dd 100644 |
| --- a/docs/superpowers/plans/COMPOSER-PROGRESS.md |
| +++ b/docs/superpowers/plans/COMPOSER-PROGRESS.md |
| @@ -294,6 +294,52 @@ the runner's own lock and runtime copy, the pinned Codex 0.165.0. One |
| Answer in at most five words.": replied "Red." on codex-1, attempt 1. |
| Claude not tried (limited until 2026-11-10 21:00Z). |
| +## Round: staging 8334e25 (Paul, an iPhone, dark mode) |
| + |
| +"Image preview not quite right": the chip was an empty dark square with |
| +the x inside it. |
| +- Cause: the page's policy (Rastrillo's default CSP) allows `img-src |
| + 'self' data:` only; the chip preview and the sent message's first |
| + thumbnail were `blob:` URLs, refused. The tests missed it because the |
| + test instance served without production's headers. |
| +- Fix: images are decoded on the page (`createImageBitmap`, else a data: |
| + image) and drawn on a canvas; the preview is a 320 px JPEG `data:` URL, |
| + for the chip and the message until the server's preview replaces it. |
| + The policy is unchanged. A HEIC photo is converted to JPEG (0.85) before |
| + upload, as is any image over 2560 px on its longer side (a GIF goes as |
| + it is); the server still refuses HEIC that arrives unconverted (a |
| + browser that cannot decode it). Paste reads clipboard items too, as a |
| + long-press paste on iOS gives them. |
| +- Chips: a 60 px rounded square, the photo cover-fitted, a hairline edge; |
| + the x a 20 px circle over the top-right corner (a 44 px reach); a thin |
| + progress bar over the foot of the thumbnail; files keep icon, cut name |
| + and size. Sent thumbnails sit on their row's foot (a small image beside |
| + a tall one no longer stretches). |
| +- Focus (Paul: "Could be subtler"): the pill's edge steps 10% towards the |
| + text colour with a 2% lift of the field, no ring and no outline (dark |
| + #26282e to about L 0.34; light #e6e6ea to about L 0.85). The + and the |
| + arrow are unchanged. The arrow's first hide on load is instant. |
| +- The test instance now sends production's CSP (`thintest.productionCSP`). |
| +- Tests: `TestWebKitAttachments` (`-tags webkit`, 390 touch, dark and |
| + light, under the policy: the chip's preview loads as a data: image, |
| + paste attaches (WebKit supports the synthetic event; a real long-press |
| + is a device check), the sent thumbnail loads at once and from the |
| + server after a reload, no image refused, the focus edge changes and |
| + there is no outline). `TestBrowserComposer` now asserts the chip's |
| + preview has loaded, its size, the x over the corner, and that a 3000 px |
| + image goes up as `huge.jpg`, 2560 px wide. Both failed first on |
| + 8334e25's scripts under the policy ("the chip's preview did not load"). |
| + `TestWebKitKeyboard` and the thintest browser suite pass under the |
| + policy. |
| +- Shots: `composer-focus-{rest,focused}-{dark,light}-390.png`, |
| + `composer-after-{chip,feed}-webkit-{dark,light}-390.png`, and the |
| + Chromium `composer-after-*` refreshed. |
| +- Seen, not changed here: the policy also refuses older inline `style` |
| + attributes (avatar and monogram hues, meter and spread bar widths, the |
| + sidebar mark's motes), so those render without them on staging today. |
| +- HEIC conversion relies on Safari's own decoder: Linux WebKit cannot |
| + decode HEIC, so it is witnessed only on a device. |
| + |
| ## Staging |
| Not restaged (the controller sequences it). |
diff --git a/internal/equipo/static/chat-attach.js b/internal/equipo/static/chat-attach.js| index 91da2c15..3bb59b8c 100644 |
| --- a/internal/equipo/static/chat-attach.js |
| +++ b/internal/equipo/static/chat-attach.js |
| @@ -91,12 +91,75 @@ |
| function heic(file) { |
| return /hei[cf]/i.test(file.type) || /\.(heic|heif|hif)$/i.test(file.name || ""); |
| } |
| + function imageLike(file) { |
| + return /^image\//.test(file.type) || heic(file); |
| + } |
| + // ── Images, prepared here ──────────────────────────────────────── |
| + // The page's policy allows data: images only (no blob:), so a preview |
| + // is drawn on a canvas and kept as a data: URL. Safari decodes HEIC, so |
| + // a HEIC photo goes up as a JPEG (0.85); so does anything over LONG px |
| + // on its longer side. A GIF goes as it is (it may move). |
| + var LONG = 2560, PREVIEW = 320; |
| + function decode(file) { |
| + function viaImage() { |
| + return new Promise(function (resolve, reject) { |
| + var reader = new FileReader(); |
| + reader.onload = function () { |
| + var img = new Image(); |
| + img.onload = function () { resolve(img); }; |
| + img.onerror = reject; |
| + img.src = reader.result; |
| + }; |
| + reader.onerror = reject; |
| + reader.readAsDataURL(file); |
| + }); |
| + } |
| + if (window.createImageBitmap) return createImageBitmap(file).catch(viaImage); |
| + return viaImage(); |
| + } |
| + function canvasOf(img, edge) { |
| + var w = img.naturalWidth || img.width, h = img.naturalHeight || img.height; |
| + var scale = Math.min(1, edge / Math.max(w, h)); |
| + var c = document.createElement("canvas"); |
| + c.width = Math.max(1, Math.round(w * scale)); |
| + c.height = Math.max(1, Math.round(h * scale)); |
| + var g = c.getContext("2d"); |
| + g.fillStyle = "#fff"; |
| + g.fillRect(0, 0, c.width, c.height); |
| + g.drawImage(img, 0, 0, c.width, c.height); |
| + return c; |
| + } |
| + function prepare(item) { |
| + if (item.kind !== "image") return Promise.resolve(); |
| + return decode(item.file).then(function (img) { |
| + item.preview = canvasOf(img, PREVIEW).toDataURL("image/jpeg", 0.8); |
| + var thumb = document.createElement("img"); |
| + thumb.src = item.preview; |
| + thumb.alt = ""; |
| + item.el.querySelector("[equipo-chip-thumb]").replaceChildren(thumb); |
| + var w = img.naturalWidth || img.width, h = img.naturalHeight || img.height; |
| + if (!heic(item.file) && (item.file.type === "image/gif" || Math.max(w, h) <= LONG)) return; |
| + return new Promise(function (resolve) { |
| + canvasOf(img, LONG).toBlob(function (blob) { |
| + if (blob) { |
| + item.file = blob; |
| + item.name = item.name.replace(/\.[^.]*$/, "") + ".jpg"; |
| + } |
| + if (img.close) img.close(); |
| + resolve(); |
| + }, "image/jpeg", 0.85); |
| + }); |
| + }, function () { |
| + // Not decodable here: the server decides (HEIC elsewhere is refused). |
| + item.kind = item.el.dataset.kind = "file"; |
| + }); |
| + } |
| function chip(file) { |
| var el = template.content.firstElementChild.cloneNode(true); |
| - var image = /^image\//.test(file.type) && !heic(file); |
| var name = file.name || "image"; |
| - var item = { el: el, file: file, name: name, kind: image ? "image" : "file", state: "uploading", done: Promise.resolve() }; |
| + var item = { el: el, file: file, name: name, kind: imageLike(file) ? "image" : "file", state: "uploading", done: Promise.resolve() }; |
| el.dataset.kind = item.kind; |
| + el.dataset.state = "uploading"; |
| el.querySelector("[equipo-chip-name]").textContent = name; |
| el.querySelector("[equipo-chip-note]").textContent = form.dataset.uploading || ""; |
| el.querySelector("[equipo-chip-progress]").setAttribute("aria-label", (form.dataset.uploading || "") + " " + name); |
| @@ -104,18 +167,14 @@ |
| remove.setAttribute("aria-label", (form.dataset.remove || "%s").replace("%s", name)); |
| remove.title = remove.getAttribute("aria-label"); |
| remove.addEventListener("click", function () { drop(item); }); |
| - if (image) { |
| - item.url = URL.createObjectURL(file); |
| - var img = document.createElement("img"); |
| - img.src = item.url; |
| - img.alt = ""; |
| - el.querySelector("[equipo-chip-thumb]").replaceChildren(img); |
| - } |
| chips.append(el); |
| chips.hidden = false; |
| - if (file.size > maxBytes) fail(item, form.dataset.tooLarge); |
| - else if (heic(file)) fail(item, form.dataset.heic); |
| - else upload(item); |
| + item.done = prepare(item).then(function () { |
| + if (item.state === "removed") return; |
| + if (item.file.size > maxBytes) fail(item, form.dataset.tooLarge); |
| + else if (heic(item.file) || (item.kind === "file" && heic(file))) fail(item, form.dataset.heic); |
| + else return upload(item); |
| + }).then(changed); |
| return item; |
| } |
| function fail(item, words) { |
| @@ -130,7 +189,7 @@ |
| bar.style.setProperty("--p", pct + "%"); |
| } |
| function upload(item) { |
| - item.done = new Promise(function (resolve) { |
| + return new Promise(function (resolve) { |
| var x = new XMLHttpRequest(); |
| item.xhr = x; |
| x.open("POST", form.dataset.upload); |
| @@ -158,7 +217,7 @@ |
| } |
| function drop(item) { |
| if (item.xhr && item.state === "uploading") item.xhr.abort(); |
| - if (item.url) URL.revokeObjectURL(item.url); |
| + if (item.state === "uploading") item.state = "removed"; |
| item.el.remove(); |
| items = items.filter(function (i) { return i !== item; }); |
| say(""); |
| @@ -167,9 +226,17 @@ |
| } |
| // ── Paste and drop ─────────────────────────────────────────────── |
| + // A pasted image or file (a long-press paste on iOS gives it as an item). |
| input.addEventListener("paste", function (event) { |
| - var files = event.clipboardData && event.clipboardData.files; |
| - if (files && files.length) { |
| + var data = event.clipboardData, files = []; |
| + if (data && data.files && data.files.length) files = Array.from(data.files); |
| + else if (data && data.items) { |
| + Array.from(data.items).forEach(function (it) { |
| + var f = it.kind === "file" && it.getAsFile(); |
| + if (f) files.push(f); |
| + }); |
| + } |
| + if (files.length) { |
| event.preventDefault(); |
| add(files); |
| } |
| @@ -202,13 +269,10 @@ |
| return items.filter(function (i) { return i.state !== "error"; }).length; |
| }, |
| // take hands the waiting attachments to a send and clears the chips: |
| - // items (with a local preview url for images) and ready, the uploaded |
| + // items (with a data: preview for images) and ready, the uploaded |
| // ones' records once every upload has settled. |
| take: function () { |
| var mine = items.filter(function (i) { return i.state !== "error"; }); |
| - items.forEach(function (i) { |
| - if (i.state === "error" && i.url) URL.revokeObjectURL(i.url); |
| - }); |
| items = []; |
| chips.replaceChildren(); |
| say(""); |
diff --git a/internal/equipo/static/chat-compose.js b/internal/equipo/static/chat-compose.js| index e5594cac..827680c5 100644 |
| --- a/internal/equipo/static/chat-compose.js |
| +++ b/internal/equipo/static/chat-compose.js |
| @@ -17,7 +17,10 @@ |
| var input = form.querySelector("textarea"); |
| // Script decides what can go: words, attachments or both. |
| input.required = false; |
| + // The first hiding of the arrow is instant: no fade on page load. |
| + form.setAttribute("data-instant", ""); |
| form.setAttribute("data-enhanced", ""); |
| + requestAnimationFrame(function () { requestAnimationFrame(function () { form.removeAttribute("data-instant"); }); }); |
| var sized = window.CSS && CSS.supports && CSS.supports("field-sizing", "content"); |
| function grow() { |
| if (sized) return; |
diff --git a/internal/equipo/static/chat-stream.js b/internal/equipo/static/chat-stream.js| index 04743fb1..06a69678 100644 |
| --- a/internal/equipo/static/chat-stream.js |
| +++ b/internal/equipo/static/chat-stream.js |
| @@ -669,7 +669,7 @@ |
| el.querySelector("[equipo-message-body]").textContent = text; |
| el.querySelector("time").textContent = new Date().toTimeString().slice(0, 5); |
| // The attachments show at once, from this device's copies. |
| - if (taken) sentFiles(el, taken.items.map(function (i) { return { kind: i.kind, name: i.name, size: i.file.size, href: i.url || "#", src: i.url }; })); |
| + if (taken) sentFiles(el, taken.items.map(function (i) { return { kind: i.preview ? "image" : "file", name: i.name, size: i.file.size, href: i.preview || "#", src: i.preview }; })); |
| local.add(el); |
| lastSend = Date.now(); |
| place(el); |
diff --git a/internal/equipo/static/equipo.css b/internal/equipo/static/equipo.css| index f30b3977..c3311727 100644 |
| --- a/internal/equipo/static/equipo.css |
| +++ b/internal/equipo/static/equipo.css |
| @@ -992,7 +992,9 @@ a[equipo-source]:hover { color: var(--rst-text); text-decoration: underline; tex |
| #composer[equipo-composer] { display: flex; align-items: flex-end; gap: var(--rst-sp-3); max-width: none; margin: 0; padding: 0; border: 0; background: transparent; cursor: default; } |
| #composer[equipo-composer]:focus-within { border-color: transparent; } |
| #composer[equipo-composer] [equipo-pill] { position: relative; flex: 1; min-inline-size: 0; display: flex; flex-direction: column; border: 1px solid var(--rst-line); border-radius: 1.375rem; background: var(--rst-surface); cursor: text; transition: border-color .15s ease, box-shadow .15s ease; } |
| -#composer[equipo-composer] [equipo-pill]:focus-within { border-color: color-mix(in oklab, var(--rst-line), var(--rst-text) 30%); } |
| +/* Focus is quiet (Paul: "Could be subtler"): the edge steps up a little |
| + from its resting colour and the field lifts faintly; no ring. */ |
| +#composer[equipo-composer] [equipo-pill]:focus-within { border-color: color-mix(in oklab, var(--rst-line), var(--rst-text) 10%); background: color-mix(in oklab, var(--rst-surface), var(--rst-text) 2%); } |
| #composer[equipo-composer][data-dropping] [equipo-pill] { border-color: var(--rst-accent); box-shadow: 0 0 0 3px var(--rst-accent-soft); } |
| #composer[equipo-composer] [equipo-pill-row] { display: flex; align-items: flex-end; min-block-size: 2.75rem; } |
| #composer[equipo-composer] textarea { font: inherit; flex: 1; min-inline-size: 0; box-sizing: content-box; margin: 0; padding: .625rem .25rem .625rem 1.125rem; border: 0; background: transparent; box-shadow: none; resize: none; line-height: 1.5rem; min-block-size: 1.5rem; max-block-size: 9rem; overflow-y: auto; field-sizing: content; color: var(--rst-text); font-size: var(--rst-fs-base); } |
| @@ -1009,6 +1011,7 @@ a[equipo-source]:hover { color: var(--rst-text); text-decoration: underline; tex |
| gentle scale and fade; gone from the tab order while hidden. */ |
| #composer[equipo-composer][data-enhanced] [equipo-send] { opacity: 1; transform: scale(1); visibility: visible; transition: opacity .14s ease-out, transform .18s cubic-bezier(.2, .9, .3, 1.2), visibility 0s; } |
| #composer[equipo-composer][data-enhanced]:not([data-has-content]) [equipo-send] { opacity: 0; transform: scale(.6); visibility: hidden; pointer-events: none; transition: opacity .12s ease-in, transform .12s ease-in, visibility 0s linear .12s; } |
| +#composer[equipo-composer][data-instant] [equipo-send], #composer[equipo-composer][data-instant] [equipo-pill] { transition: none; } |
| /* The +: a 44 px round button and its small menu, above it. */ |
| #composer[equipo-composer] [equipo-adder] { position: relative; flex: none; } |
| #composer[equipo-composer] [equipo-adder][hidden] { display: none; } |
| @@ -1023,31 +1026,33 @@ a[equipo-source]:hover { color: var(--rst-text); text-decoration: underline; tex |
| #composer[equipo-composer] [equipo-add-menu] button:hover, #composer[equipo-composer] [equipo-add-menu] button:focus-visible { background: var(--rst-tint-hover, var(--rst-surface-2)); outline: none; } |
| #composer[equipo-composer] [equipo-add-menu] .icon { inline-size: 1.125rem; block-size: 1.125rem; margin: 0; color: var(--rst-text-muted); } |
| /* Attachments waiting to go: chips above the words, inside the pill. */ |
| -#composer[equipo-composer] [equipo-chips] { display: flex; flex-wrap: wrap; gap: var(--rst-sp-2); margin: 0; padding: var(--rst-sp-2) var(--rst-sp-2) 0; list-style: none; } |
| +#composer[equipo-composer] [equipo-chips] { display: flex; flex-wrap: wrap; gap: var(--rst-sp-3); margin: 0; padding: .75rem .75rem .125rem; list-style: none; } |
| #composer[equipo-composer] [equipo-chips][hidden], #composer[equipo-composer] [equipo-add-note][hidden] { display: none; } |
| -[equipo-chip] { position: relative; flex: none; display: flex; align-items: center; gap: var(--rst-sp-2); block-size: 3.5rem; max-inline-size: min(12.5rem, calc(100% - 4rem)); padding: 0 2.25rem 0 .375rem; border: 1px solid var(--rst-line); border-radius: .875rem; background: var(--rst-surface-2); font-size: var(--rst-fs-xs); overflow: hidden; } |
| -[equipo-chip] [equipo-chip-thumb] { flex: none; display: grid; place-items: center; inline-size: 2.75rem; block-size: 2.75rem; border-radius: .625rem; background: var(--rst-surface); color: var(--rst-text-muted); overflow: hidden; } |
| -[equipo-chip] [equipo-chip-thumb] img { inline-size: 100%; block-size: 100%; object-fit: cover; } |
| +/* A chip: an image is a 60 px rounded square, the photo cover-fitted; a |
| + file is an icon, its name cut short and its size. The x is a 20 px |
| + circle on the chip's top-right corner, over its edge, never over the |
| + picture's middle; upload progress is a thin bar over the foot. */ |
| +[equipo-chip] { position: relative; flex: none; display: flex; align-items: center; gap: var(--rst-sp-2); block-size: 3.75rem; max-inline-size: min(13rem, calc(100% - 1rem)); padding: 0 var(--rst-sp-3) 0 .375rem; border: 1px solid var(--rst-line); border-radius: .75rem; background: var(--rst-surface-2); font-size: var(--rst-fs-xs); box-sizing: border-box; } |
| +[equipo-chip] [equipo-chip-thumb] { flex: none; display: grid; place-items: center; inline-size: 2.75rem; block-size: 2.75rem; border-radius: .5rem; background: var(--rst-surface); color: var(--rst-text-muted); overflow: hidden; } |
| +[equipo-chip] [equipo-chip-thumb] img { display: block; inline-size: 100%; block-size: 100%; object-fit: cover; } |
| [equipo-chip] [equipo-chip-thumb] .icon { inline-size: 1.25rem; block-size: 1.25rem; margin: 0; } |
| [equipo-chip] [equipo-chip-text] { display: grid; min-inline-size: 0; line-height: 1.3; } |
| [equipo-chip] [equipo-chip-name] { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--rst-text); } |
| [equipo-chip] [equipo-chip-note] { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--rst-text-muted); } |
| -/* An image that uploads well is a thumbnail alone. */ |
| -[equipo-chip][data-kind="image"]:not([data-state="error"]) { inline-size: 3.5rem; padding: 0; border-radius: .875rem; } |
| -[equipo-chip][data-kind="image"]:not([data-state="error"]) [equipo-chip-thumb] { inline-size: 100%; block-size: 100%; border-radius: 0; } |
| +[equipo-chip][data-kind="image"]:not([data-state="error"]) { inline-size: 3.75rem; padding: 0; } |
| +[equipo-chip][data-kind="image"]:not([data-state="error"]) [equipo-chip-thumb] { inline-size: 100%; block-size: 100%; border-radius: calc(.75rem - 1px); background: var(--rst-surface-2); } |
| [equipo-chip][data-kind="image"]:not([data-state="error"]) [equipo-chip-text] { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); } |
| -[equipo-chip][data-state="error"] { border-color: color-mix(in oklab, var(--rst-tone-negative-fg) 45%, var(--rst-line)); background: var(--rst-tone-negative-bg); } |
| +[equipo-chip][data-state="error"] { border-color: color-mix(in oklab, var(--rst-tone-negative-fg) 40%, var(--rst-line)); background: var(--rst-tone-negative-bg); block-size: auto; min-block-size: 3.75rem; padding-block: .25rem; } |
| [equipo-chip][data-state="error"] [equipo-chip-note] { color: var(--rst-tone-negative-fg); white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; } |
| -[equipo-chip][data-state="error"] { block-size: auto; min-block-size: 3.5rem; padding-block: .25rem; } |
| -/* Upload progress: a thin bar along the chip's foot. */ |
| -[equipo-chip] [equipo-chip-progress] { position: absolute; inset-inline: .5rem; inset-block-end: .3rem; block-size: 3px; border-radius: 2px; background: color-mix(in oklab, var(--rst-text) 15%, transparent); overflow: hidden; } |
| -[equipo-chip] [equipo-chip-progress] i { display: block; block-size: 100%; inline-size: var(--p, 0%); background: var(--rst-accent); transition: inline-size .2s ease; } |
| +[equipo-chip] [equipo-chip-progress] { position: absolute; inset-inline: .375rem; inset-block-end: .375rem; block-size: 3px; border-radius: 2px; background: color-mix(in oklab, #000 35%, transparent); overflow: hidden; } |
| +[equipo-chip] [equipo-chip-progress] i { display: block; block-size: 100%; inline-size: var(--p, 0%); background: #fff; transition: inline-size .2s ease; } |
| +[equipo-chip][data-kind="file"] [equipo-chip-progress] { background: color-mix(in oklab, var(--rst-text) 12%, transparent); } |
| +[equipo-chip][data-kind="file"] [equipo-chip-progress] i { background: var(--rst-accent); } |
| [equipo-chip]:not([data-state="uploading"]) [equipo-chip-progress] { display: none; } |
| -[equipo-chip][data-state="uploading"] [equipo-chip-thumb] img { opacity: .55; } |
| -/* Remove: a 28 px round x in the chip's corner, a 44 px reach on touch. */ |
| -#composer [equipo-chip] [equipo-chip-remove] { position: absolute; inset-block-start: .25rem; inset-inline-end: .25rem; display: grid; place-items: center; inline-size: 1.5rem; block-size: 1.5rem; margin: 0; padding: 0; border: 0; border-radius: 50%; background: color-mix(in oklab, var(--rst-text) 70%, transparent); color: var(--rst-surface); cursor: pointer; } |
| -#composer [equipo-chip] [equipo-chip-remove]::after { content: ""; position: absolute; inset: -.625rem; } |
| -#composer [equipo-chip] [equipo-chip-remove] .icon { inline-size: .875rem; block-size: .875rem; stroke-width: 3; margin: 0; } |
| +#composer [equipo-chip] [equipo-chip-remove] { position: absolute; inset-block-start: -.5rem; inset-inline-end: -.5rem; z-index: 1; display: grid; place-items: center; inline-size: 1.25rem; block-size: 1.25rem; margin: 0; padding: 0; border: 2px solid var(--rst-surface); border-radius: 50%; background: var(--rst-text-muted); color: var(--rst-surface); cursor: pointer; box-sizing: content-box; } |
| +#composer [equipo-chip] [equipo-chip-remove]:hover { background: var(--rst-text); } |
| +#composer [equipo-chip] [equipo-chip-remove]::after { content: ""; position: absolute; inset: -.75rem; } |
| +#composer [equipo-chip] [equipo-chip-remove] .icon { inline-size: .75rem; block-size: .75rem; stroke-width: 3; margin: 0; } |
| #composer[equipo-composer] [equipo-add-note] { margin: var(--rst-sp-1) var(--rst-sp-4) 0; color: var(--rst-tone-negative-fg); font-size: var(--rst-fs-xs); } |
| /* The task thread's composer: the same pill, its "Asking" line below. */ |
| #composer[equipo-composer]:has([equipo-composer-tools]) { flex-wrap: wrap; } |
| @@ -1060,7 +1065,7 @@ a[equipo-source]:hover { color: var(--rst-text); text-decoration: underline; tex |
| /* Sent attachments, inside the person's own message as it is: a |
| thumbnail (tap for full size) or a file chip, above the words; a |
| message with no words shows no empty bubble. */ |
| -[equipo-message-files] { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--rst-sp-2); margin-block-end: var(--rst-sp-1); } |
| +[equipo-message-files] { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: flex-end; gap: var(--rst-sp-2); margin-block-end: var(--rst-sp-1); } |
| [equipo-message-files][hidden] { display: none; } |
| [equipo-file-thumb] { display: block; line-height: 0; border-radius: calc(2 * var(--rst-radius)); overflow: hidden; border: 1px solid var(--rst-line); background: var(--rst-surface-2); } |
| [equipo-file-thumb] img { display: block; inline-size: auto; block-size: auto; min-inline-size: 4rem; min-block-size: 4rem; max-inline-size: min(16rem, 60vw); max-block-size: 18rem; object-fit: cover; } |
diff --git a/internal/headless/browser_attach_test.go b/internal/headless/browser_attach_test.go| index 3f952538..1e87779d 100644 |
| --- a/internal/headless/browser_attach_test.go |
| +++ b/internal/headless/browser_attach_test.go |
| @@ -53,6 +53,7 @@ func TestBrowserComposer(t *testing.T) { |
| big := write("big.log", bytes.Repeat([]byte("x"), 10<<20+1)) |
| binary := write("tool.bin", []byte{0x4d, 0x5a, 0, 1, 2, 3}) |
| small := base64.StdEncoding.EncodeToString(attachtest.PNG(8, 8)) |
| + huge := write("huge.png", attachtest.PNG(3000, 1500)) |
| shots := os.Getenv("EQUIPO_SCREENSHOTS") |
| for _, tc := range []struct { |
| width, height int64 |
| @@ -157,7 +158,10 @@ func TestBrowserComposer(t *testing.T) { |
| // A picked image: a chip that uploads, then the arrow. |
| pick("image", screen) |
| - p.run(browsertest.Wait(chip("ready") + ` && ` + chip("ready") + `.dataset.kind==='image' && !!` + chip("ready") + `.querySelector('img') && !document.querySelector('[equipo-chips]').hidden`)) |
| + p.run(browsertest.Wait(chip("ready") + ` && ` + chip("ready") + `.dataset.kind==='image' && !document.querySelector('[equipo-chips]').hidden`)) |
| + // The preview has loaded under the page's policy (data:, not blob:), |
| + // fills a 56 to 64 px square, and the x sits over the corner. |
| + p.check(`(()=>{const c=`+chip("ready")+`,i=c.querySelector('[equipo-chip-thumb] img'),r=c.getBoundingClientRect(),x=c.querySelector('[equipo-chip-remove]').getBoundingClientRect();return !!i&&i.src.startsWith('data:image/')&&i.complete&&i.naturalWidth>0&&getComputedStyle(i).objectFit==='cover'&&r.width>=56&&r.width<=64&&Math.abs(r.width-r.height)<1&&x.width>=19&&x.width<=25&&x.right>r.right&&x.top<r.top&&x.left>r.left+r.width/2})()`, at+": the chip's preview did not load, or its size or x is wrong") |
| p.run(browsertest.Wait(sendShown)) |
| p.check(`(()=>{const c=document.querySelector('[equipo-chips]').getBoundingClientRect(),i=document.querySelector('#chat-body').getBoundingClientRect(),p=document.querySelector('[equipo-pill]').getBoundingClientRect();return c.bottom<=i.top+1&&c.top>=p.top&&c.left>=p.left})()`, at+": the chip is not above the words inside the pill") |
| // A file beside it, then removed with its x. |
| @@ -210,6 +214,20 @@ func TestBrowserComposer(t *testing.T) { |
| p.run(browsertest.Wait(`(()=>{const li=[...document.querySelectorAll('[equipo-message="own"]')].find(e=>e.textContent.includes('pasted and dropped'));return !!li&&li.querySelectorAll('[equipo-file-thumb]').length===1&&li.querySelector('[equipo-file-chip] [equipo-file-name]').textContent==='rows.csv'&&getComputedStyle(li.querySelector('[equipo-bubble]')).display!=='none'})()`)) |
| } |
| + if !tc.touch { |
| + // A large image goes up scaled to 2560 px, as a JPEG. |
| + pick("image", huge) |
| + p.run(browsertest.Wait(`document.querySelectorAll('[equipo-chip][data-state="ready"]').length===1`)) |
| + var w int |
| + var media, name string |
| + if err := inst.DB.Writer().QueryRow("SELECT width, media_type, name FROM chat_attachments ORDER BY created_at DESC, rowid DESC LIMIT 1").Scan(&w, &media, &name); err != nil { |
| + t.Fatal(err) |
| + } |
| + if w != 2560 || media != "image/jpeg" || name != "huge.jpg" { |
| + t.Fatalf("the large image went up as %s %s %d px wide", name, media, w) |
| + } |
| + p.check(`(()=>{document.querySelector('[equipo-chip] [equipo-chip-remove]').click();return document.querySelectorAll('[equipo-chip]').length===0})()`, "remove huge") |
| + } |
| // Light and dark: the composer as it rests, and growing to six lines. |
| for _, theme := range []string{"light", "dark"} { |
| p.theme(theme) |
diff --git a/internal/thintest/attach_webkit_test.go b/internal/thintest/attach_webkit_test.go| new file mode 100644 |
| index 00000000..f64f90f0 |
| --- /dev/null |
| +++ b/internal/thintest/attach_webkit_test.go |
| @@ -0,0 +1,82 @@ |
| +//go:build webkit |
| + |
| +package thintest |
| + |
| +import ( |
| + "encoding/base64" |
| + "encoding/json" |
| + "os" |
| + "os/exec" |
| + "path/filepath" |
| + "strings" |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/attach/attachtest" |
| +) |
| + |
| +// TestWebKitAttachments: Paul, staging 8334e25, Safari on an iPhone, dark: |
| +// the chip above the words was an empty dark square. The page's policy |
| +// allows data: images only and the preview was a blob: URL. In WebKit at |
| +// 390 on touch, dark and light, under production's policy: a picked photo |
| +// becomes a chip whose preview has loaded (a data: image); a pasted image |
| +// attaches; the sent thumbnail loads at once and, after a reload, from the |
| +// server's preview; nothing is refused by the policy; and the pill's edge |
| +// steps up only a little on focus, with no outline. Needs |
| +// EQUIPO_PLAYWRIGHT_CORE. EQUIPO_BROWSER_ARTIFACTS saves the shots. |
| +func TestWebKitAttachments(t *testing.T) { |
| + core := os.Getenv("EQUIPO_PLAYWRIGHT_CORE") |
| + if core == "" { |
| + t.Skip("EQUIPO_PLAYWRIGHT_CORE is not set") |
| + } |
| + inst := StartInstance(t) |
| + photo := filepath.Join(t.TempDir(), "IMG_0001.jpg") |
| + if err := os.WriteFile(photo, attachtest.Photo(1200, 900, 6), 0600); err != nil { |
| + t.Fatal(err) |
| + } |
| + c := inst.Cookie() |
| + raw, _ := json.Marshal(map[string]any{"base": inst.URL, "cookie": map[string]string{"name": c.Name, "value": c.Value}, "photo": photo, "small": base64.StdEncoding.EncodeToString(attachtest.PNG(8, 8)), "art": os.Getenv("EQUIPO_BROWSER_ARTIFACTS")}) |
| + cmd := exec.Command("node", "testdata/attach.mjs") |
| + cmd.Env = append(os.Environ(), "EQUIPO_ATTACH="+string(raw)) |
| + cmd.Stderr = os.Stderr |
| + got, err := cmd.Output() |
| + if err != nil { |
| + t.Fatalf("webkit: %v", err) |
| + } |
| + var res map[string]struct { |
| + Rest, Focused, Outline string |
| + Chip struct { |
| + Src string |
| + Width int |
| + Complete bool |
| + } |
| + Paste struct{ Supported, Taken bool } |
| + Sent string |
| + Server string |
| + Blocked []string |
| + } |
| + if err := json.Unmarshal(got, &res); err != nil { |
| + t.Fatalf("webkit output %q: %v", got, err) |
| + } |
| + for _, scheme := range []string{"dark", "light"} { |
| + r := res[scheme] |
| + if !strings.HasPrefix(r.Chip.Src, "data:image/") || r.Chip.Width == 0 || !r.Chip.Complete { |
| + t.Fatalf("%s: the chip's preview did not load: %+v", scheme, r.Chip) |
| + } |
| + if r.Paste.Supported && !r.Paste.Taken { |
| + t.Fatalf("%s: a pasted image was not attached", scheme) |
| + } |
| + if !strings.HasPrefix(r.Sent, "data:image/") && !strings.Contains(r.Sent, "/conversation/") { |
| + t.Fatalf("%s: the sent thumbnail %q", scheme, r.Sent) |
| + } |
| + if !strings.HasPrefix(r.Server, "/conversation/attachments/at_") || !strings.HasSuffix(r.Server, "/preview") { |
| + t.Fatalf("%s: after a reload the thumbnail is %q", scheme, r.Server) |
| + } |
| + if len(r.Blocked) > 0 { |
| + t.Fatalf("%s: the policy refused %v", scheme, r.Blocked) |
| + } |
| + if r.Rest == r.Focused || r.Outline != "none" { |
| + t.Fatalf("%s: focus edge %s to %s, outline %s", scheme, r.Rest, r.Focused, r.Outline) |
| + } |
| + t.Logf("%s: edge %s to %s; paste supported=%v taken=%v", scheme, r.Rest, r.Focused, r.Paste.Supported, r.Paste.Taken) |
| + } |
| +} |
diff --git a/internal/thintest/instance.go b/internal/thintest/instance.go| index c1cae9c0..c316428d 100644 |
| --- a/internal/thintest/instance.go |
| +++ b/internal/thintest/instance.go |
| @@ -92,7 +92,7 @@ func (i *Instance) serve(t testing.TB, l net.Listener) { |
| t.Fatal(err) |
| } |
| i.DB, i.Store = d, s |
| - i.server = &http.Server{Handler: equipo.Mux(router), ReadHeaderTimeout: 5 * time.Second} |
| + i.server = &http.Server{Handler: productionHeaders(equipo.Mux(router)), ReadHeaderTimeout: 5 * time.Second} |
| go i.server.Serve(l) |
| } |
| @@ -284,3 +284,21 @@ func (i *Instance) Get(t testing.TB, path string) string { |
| } |
| return string(raw) |
| } |
| + |
| +// productionCSP is Rastrillo v0.30.1's default Content-Security-Policy, |
| +// which every production response carries (rastrillo.Handler sets it; the |
| +// constant is unexported). Pages here carry it too, so browser tests meet |
| +// what Safari met on staging: a chip preview from a blob: URL is blocked. |
| +const productionCSP = "default-src 'self'; " + |
| + "style-src 'self' 'unsafe-hashes' 'sha256-yJxAE4rjdcckohdlnvecSporPcqS9xOaA4hJxi87LMc='; " + |
| + "img-src 'self' data:; frame-ancestors 'none'; base-uri 'self'; form-action 'self'" |
| + |
| +// productionHeaders sets the policy before the app runs; a handler that |
| +// sets its own (an attachment's) replaces it, as in production. |
| +func productionHeaders(next http.Handler) http.Handler { |
| + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + w.Header().Set("Content-Security-Policy", productionCSP) |
| + w.Header().Set("X-Content-Type-Options", "nosniff") |
| + next.ServeHTTP(w, r) |
| + }) |
| +} |
diff --git a/internal/thintest/testdata/attach.mjs b/internal/thintest/testdata/attach.mjs| new file mode 100644 |
| index 00000000..3b58f7d7 |
| --- /dev/null |
| +++ b/internal/thintest/testdata/attach.mjs |
| @@ -0,0 +1,78 @@ |
| +// Attachments in WebKit, as on an iPhone (390x844, touch), in a page that |
| +// carries production's Content-Security-Policy: a picked photo's chip |
| +// preview loads, paste attaches, the sent thumbnail loads, and the pill's |
| +// focus edge is measured at rest and focused. Prints one JSON object. |
| +import { createRequire } from "node:module"; |
| +const require = createRequire(import.meta.url); |
| +const { webkit } = require(process.env.EQUIPO_PLAYWRIGHT_CORE); |
| +const cfg = JSON.parse(process.env.EQUIPO_ATTACH); |
| + |
| +const loaded = sel => { |
| + const i = document.querySelector(sel); |
| + return !!i && i.complete && i.naturalWidth > 0; |
| +}; |
| +const out = {}; |
| +const browser = await webkit.launch(); |
| +try { |
| + for (const scheme of ["dark", "light"]) { |
| + const ctx = await browser.newContext({ viewport: { width: 390, height: 844 }, deviceScaleFactor: 2, hasTouch: true, isMobile: true, colorScheme: scheme }); |
| + await ctx.addCookies([{ name: cfg.cookie.name, value: cfg.cookie.value, url: cfg.base }]); |
| + const page = await ctx.newPage(); |
| + const blocked = []; |
| + page.on("console", m => { if (/Refused to load|img-src/i.test(m.text())) blocked.push(m.text()); }); |
| + await page.goto(cfg.base + "/conversation"); |
| + await page.waitForFunction(() => !!document.querySelector("#composer[data-enhanced]") && !!window.EquipoAttach); |
| + const edge = () => getComputedStyle(document.querySelector("[equipo-pill]")).borderTopColor; |
| + // Past the first paint's transitions (the edge and the arrow's fade). |
| + await page.waitForTimeout(500); |
| + const res = { rest: await page.evaluate(edge) }; |
| + if (cfg.art) await page.screenshot({ path: `${cfg.art}/composer-focus-rest-${scheme}-390.png` }); |
| + await page.focus("#chat-body"); |
| + await page.waitForTimeout(500); |
| + res.focused = await page.evaluate(edge); |
| + res.outline = await page.evaluate(() => getComputedStyle(document.querySelector("#chat-body")).outlineStyle); |
| + if (cfg.art) await page.screenshot({ path: `${cfg.art}/composer-focus-focused-${scheme}-390.png` }); |
| + |
| + await page.setInputFiles('[data-picker="image"]', cfg.photo); |
| + await page.waitForFunction(() => document.querySelector('[equipo-chip][data-state="ready"]'), null, { timeout: 15000 }); |
| + res.chip = await page.evaluate(() => { |
| + const i = document.querySelector('[equipo-chip][data-state="ready"] [equipo-chip-thumb] img'); |
| + return { src: i ? i.src.slice(0, 15) : "", width: i ? i.naturalWidth : 0, complete: !!i && i.complete }; |
| + }); |
| + if (cfg.art) await page.screenshot({ path: `${cfg.art}/composer-after-chip-webkit-${scheme}-390.png` }); |
| + // Paste, as a long-press paste delivers it: an image item. |
| + res.paste = await page.evaluate(async (b64) => { |
| + const bytes = Uint8Array.from(atob(b64), c => c.charCodeAt(0)); |
| + const d = new DataTransfer(); |
| + d.items.add(new File([bytes], "pasted.png", { type: "image/png" })); |
| + const e = new ClipboardEvent("paste", { clipboardData: d, bubbles: true, cancelable: true }); |
| + document.querySelector("#chat-body").dispatchEvent(e); |
| + return { supported: !!e.clipboardData && e.clipboardData.items.length > 0, taken: e.defaultPrevented }; |
| + }, cfg.small); |
| + if (res.paste.taken) await page.waitForFunction(() => document.querySelectorAll('[equipo-chip][data-state="ready"]').length === 2, null, { timeout: 15000 }); |
| + await page.tap("[equipo-send]"); |
| + await page.waitForFunction(() => { |
| + const own = [...document.querySelectorAll('[equipo-message="own"]')].pop(); |
| + const i = own && own.querySelector("[equipo-file-thumb] img"); |
| + return !!i && i.complete && i.naturalWidth > 0 && own.dataset.message; |
| + }, null, { timeout: 15000 }); |
| + res.sent = await page.evaluate(() => { |
| + const s = [...document.querySelectorAll('[equipo-message="own"]')].pop().querySelector("[equipo-file-thumb] img").src; |
| + return s.startsWith("data:") ? s.slice(0, 15) : new URL(s).pathname; |
| + }); |
| + await page.reload(); |
| + await page.waitForFunction(() => { |
| + const own = [...document.querySelectorAll('[equipo-message="own"]')].pop(); |
| + const i = own && own.querySelector("[equipo-file-thumb] img"); |
| + return !!i && i.complete && i.naturalWidth > 0; |
| + }, null, { timeout: 15000 }); |
| + res.server = await page.evaluate(() => new URL([...document.querySelectorAll('[equipo-message="own"]')].pop().querySelector("[equipo-file-thumb] img").src).pathname); |
| + if (cfg.art) await page.screenshot({ path: `${cfg.art}/composer-after-feed-webkit-${scheme}-390.png` }); |
| + res.blocked = blocked; |
| + out[scheme] = res; |
| + await ctx.close(); |
| + } |
| +} finally { |
| + await browser.close(); |
| +} |
| +process.stdout.write(JSON.stringify(out)); |
diff --git a/scripts/runner-reference-allowlist.json b/scripts/runner-reference-allowlist.json| index 0f2a4565..d7cba776 100644 |
| --- a/scripts/runner-reference-allowlist.json |
| +++ b/scripts/runner-reference-allowlist.json |
| @@ -10743,5 +10743,26 @@ |
| "match": "Node", |
| "count": 1, |
| "reason": "The DOM's cloneNode method copies a page template in the browser; not Node.js." |
| + }, |
| + { |
| + "path": "internal/thintest/attach_webkit_test.go", |
| + "line_sha256": "d6efc08f9a8002b4babb81372e941c55a86d24441d0084888181d2545277e020", |
| + "match": ".mjs", |
| + "count": 1, |
| + "reason": "The WebKit browser test drives Playwright's WebKit through its own driver script with the machine's node; not the old JavaScript runtime." |
| + }, |
| + { |
| + "path": "internal/thintest/attach_webkit_test.go", |
| + "line_sha256": "d6efc08f9a8002b4babb81372e941c55a86d24441d0084888181d2545277e020", |
| + "match": "node", |
| + "count": 1, |
| + "reason": "The WebKit browser test drives Playwright's WebKit through its own driver script with the machine's node; not the old JavaScript runtime." |
| + }, |
| + { |
| + "path": "internal/thintest/testdata/attach.mjs", |
| + "line_sha256": "db1eb2fe86d7c7b6fe41643bf42ea97453ec740d5d62e7867d6e33b9a25aa2f0", |
| + "match": "node", |
| + "count": 1, |
| + "reason": "The WebKit browser test drives Playwright's WebKit through its own driver script with the machine's node; not the old JavaScript runtime." |
| } |
| ] |