oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1// Attachments in WebKit, as on an iPhone (390x844, touch), in a page that
2// carries production's Content-Security-Policy: a picked photo's chip
3// preview loads, paste attaches, the sent thumbnail loads, and the pill's
4// focus edge is measured at rest and focused. Prints one JSON object.
5import { createRequire } from "node:module";
6const require = createRequire(import.meta.url);
7const { webkit } = require(process.env.EQUIPO_PLAYWRIGHT_CORE);
8const cfg = JSON.parse(process.env.EQUIPO_ATTACH);
9
10const loaded = sel => {
11 const i = document.querySelector(sel);
12 return !!i && i.complete && i.naturalWidth > 0;
13};
14const out = {};
15const browser = await webkit.launch();
16try {
17 for (const scheme of ["dark", "light"]) {
18 const ctx = await browser.newContext({ viewport: { width: 390, height: 844 }, deviceScaleFactor: 2, hasTouch: true, isMobile: true, colorScheme: scheme });
19 await ctx.addCookies([{ name: cfg.cookie.name, value: cfg.cookie.value, url: cfg.base }]);
20 const page = await ctx.newPage();
21 const blocked = [];
22 page.on("console", m => { if (/Refused to load|img-src/i.test(m.text())) blocked.push(m.text()); });
23 await page.goto(cfg.base + "/conversation");
24 await page.waitForFunction(() => !!document.querySelector("#composer[data-enhanced]") && !!window.EquipoAttach);
25 const edge = () => getComputedStyle(document.querySelector("[equipo-pill]")).borderTopColor;
26 // Past the first paint's transitions (the edge and the arrow's fade).
27 await page.waitForTimeout(500);
28 const res = { rest: await page.evaluate(edge) };
29 if (cfg.art) await page.screenshot({ path: `${cfg.art}/composer-focus-rest-${scheme}-390.png` });
30 await page.focus("#chat-body");
31 await page.waitForTimeout(500);
32 res.focused = await page.evaluate(edge);
33 res.outline = await page.evaluate(() => getComputedStyle(document.querySelector("#chat-body")).outlineStyle);
34 if (cfg.art) await page.screenshot({ path: `${cfg.art}/composer-focus-focused-${scheme}-390.png` });
35
36 await page.setInputFiles('[data-picker="image"]', cfg.photo);
37 await page.waitForFunction(() => document.querySelector('[equipo-chip][data-state="ready"]'), null, { timeout: 15000 });
38 res.chip = await page.evaluate(() => {
39 const i = document.querySelector('[equipo-chip][data-state="ready"] [equipo-chip-thumb] img');
40 return { src: i ? i.src.slice(0, 15) : "", width: i ? i.naturalWidth : 0, complete: !!i && i.complete };
41 });
42 if (cfg.art) await page.screenshot({ path: `${cfg.art}/composer-after-chip-webkit-${scheme}-390.png` });
43 // Paste, as a long-press paste delivers it: an image item.
44 res.paste = await page.evaluate(async (b64) => {
45 const bytes = Uint8Array.from(atob(b64), c => c.charCodeAt(0));
46 const d = new DataTransfer();
47 d.items.add(new File([bytes], "pasted.png", { type: "image/png" }));
48 const e = new ClipboardEvent("paste", { clipboardData: d, bubbles: true, cancelable: true });
49 document.querySelector("#chat-body").dispatchEvent(e);
50 return { supported: !!e.clipboardData && e.clipboardData.items.length > 0, taken: e.defaultPrevented };
51 }, cfg.small);
52 if (res.paste.taken) await page.waitForFunction(() => document.querySelectorAll('[equipo-chip][data-state="ready"]').length === 2, null, { timeout: 15000 });
53 await page.tap("[equipo-send]");
54 await page.waitForFunction(() => {
55 const own = [...document.querySelectorAll('[equipo-message="own"]')].pop();
56 const i = own && own.querySelector("[equipo-file-thumb] img");
57 return !!i && i.complete && i.naturalWidth > 0 && own.dataset.message;
58 }, null, { timeout: 15000 });
59 res.sent = await page.evaluate(() => {
60 const s = [...document.querySelectorAll('[equipo-message="own"]')].pop().querySelector("[equipo-file-thumb] img").src;
61 return s.startsWith("data:") ? s.slice(0, 15) : new URL(s).pathname;
62 });
63 await page.reload();
64 await page.waitForFunction(() => {
65 const own = [...document.querySelectorAll('[equipo-message="own"]')].pop();
66 const i = own && own.querySelector("[equipo-file-thumb] img");
67 return !!i && i.complete && i.naturalWidth > 0;
68 }, null, { timeout: 15000 });
69 res.server = await page.evaluate(() => new URL([...document.querySelectorAll('[equipo-message="own"]')].pop().querySelector("[equipo-file-thumb] img").src).pathname);
70 if (cfg.art) await page.screenshot({ path: `${cfg.art}/composer-after-feed-webkit-${scheme}-390.png` });
71 res.blocked = blocked;
72 out[scheme] = res;
73 await ctx.close();
74 }
75} finally {
76 await browser.close();
77}
78process.stdout.write(JSON.stringify(out));
79