Clipboard on http: copy and paste work without the Clipboard API
Over plain http on a tailnet address the page is not a secure context and
navigator.clipboard is undefined, so the web engine refused every copy.
ClipboardReportingMessenger now answers clipboard calls through the
browser's legacy clipboard when the API is missing (web only, conditional
import): copy uses execCommand('copy') with a one-shot copy-event listener
(no focus or selection change); a paste key's Clipboard.getData takes the
browser's own paste event, the key reported not-handled so the browser
still fires it. A Paste button/menu says to use Ctrl+V or the https address.
Secure pages keep the engine path. Capture kit: --insecure and clipboard=.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -45,6 +45,11 @@ assistive technology: only point targets (`x,y`) work, and the web's text input
|
||||
is Flutter's own hidden field, which reports IME composition (with semantics on,
|
||||
a text field's input is its semantics element, which does not).
|
||||
|
||||
`--insecure true` opens the build at `http://pipelines-insecure.test:<port>`
|
||||
(Chrome maps that name to the loopback server), so the page is not a secure
|
||||
context and has no Clipboard API, as the app over plain http on a LAN or
|
||||
tailnet address (`examples/clipboard-insecure-*.json`).
|
||||
|
||||
`--user-agent '<ua>'` overrides the browser's user agent before loading, so an
|
||||
Android phone's (with `--touch true`) makes Flutter's `defaultTargetPlatform`
|
||||
Android, for touch-only UI such as the terminal's key row.
|
||||
@@ -74,6 +79,7 @@ In JSON, a step can also set `wait` (ms), `timeout`, `name`, `ms` and `frames`.
|
||||
| `wait=ms` | sleep |
|
||||
| `keys=[...]` | raw key events (JSON `Input.dispatchKeyEvent` params, each with an optional `after` ms), e.g. modifier flags without their key events as a compositor's injected shortcut sends them (`examples/clipboard-*.json`) |
|
||||
| `grant=clipboard` | let the page read and write the clipboard (`navigator.clipboard` in `eval`) |
|
||||
| `clipboard=read[:label]` / `clipboard=write:<text>` | read or write the browser's clipboard from a scratch page on the loopback origin (a secure context), then bring the page back; JSON `expect` fails the run unless the read text matches. Works for an `--insecure` page, which has no `navigator.clipboard` |
|
||||
| `files=a.ttf[,b.ttf]` | answer the next file chooser the page opens with these files (paths relative to the working directory); put it before the click that opens the picker |
|
||||
| `swipe=<target>>dx,dy` | one-finger touch swipe (needs `--touch true`, which emulates a touch screen once semantics is on) |
|
||||
| `pinch=<target>>scale` | two-finger touch pinch, spreading (>1) or closing (<1) (needs `--touch true`) |
|
||||
|
||||
@@ -11,7 +11,7 @@ import { setTimeout as delay } from 'node:timers/promises';
|
||||
const CALL_TIMEOUT_MS = 30000;
|
||||
const DEFAULT_CHROME ='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
|
||||
|
||||
async function launch(chromePath, gpu) {
|
||||
async function launch(chromePath, gpu, args = []) {
|
||||
const profile = await mkdtemp(join(tmpdir(), 'pipelines-capture-chrome-'));
|
||||
const chrome = spawn(chromePath, [
|
||||
'--headless=new', '--no-first-run', '--no-default-browser-check',
|
||||
@@ -21,7 +21,7 @@ async function launch(chromePath, gpu) {
|
||||
...(gpu ? [process.platform === 'darwin' ? '--use-angle=metal' : '--use-angle=vulkan',
|
||||
...(process.platform === 'darwin' ? [] : ['--enable-features=Vulkan']),
|
||||
'--enable-gpu-rasterization', '--ignore-gpu-blocklist'] : ['--disable-gpu']),
|
||||
'--hide-scrollbars', '--mute-audio',
|
||||
'--hide-scrollbars', '--mute-audio', ...args,
|
||||
'--remote-debugging-port=0', `--user-data-dir=${profile}`, 'about:blank',
|
||||
], { stdio: ['ignore', 'ignore', 'pipe'] });
|
||||
let stderr = '';
|
||||
@@ -55,8 +55,8 @@ async function attach(cdp) {
|
||||
* talks to the page session; `on(method, fn)` subscribes to its events and
|
||||
* returns the unsubscribe function; `newPage()` opens a scratch page.
|
||||
*/
|
||||
export async function openBrowser({ cdp, gpu = false, chromePath = process.env.CHROME_PATH ?? DEFAULT_CHROME } = {}) {
|
||||
const { ws: endpoint, cleanup } = cdp ? await attach(cdp) : await launch(chromePath, gpu);
|
||||
export async function openBrowser({ cdp, gpu = false, args = [], chromePath = process.env.CHROME_PATH ?? DEFAULT_CHROME } = {}) {
|
||||
const { ws: endpoint, cleanup } = cdp ? await attach(cdp) : await launch(chromePath, gpu, args);
|
||||
const ws = new WebSocket(endpoint);
|
||||
try {
|
||||
await new Promise((ok, fail) => { ws.onopen = ok; ws.onerror = () => fail(new Error(`Cannot open ${endpoint}`)); });
|
||||
@@ -107,9 +107,12 @@ export async function openBrowser({ cdp, gpu = false, chromePath = process.env.C
|
||||
const { sessionId: sid } = await raw('Target.attachToTarget', { targetId: page.targetId, flatten: true });
|
||||
return {
|
||||
send: (method, params) => raw(method, params, sid),
|
||||
targetId: page.targetId,
|
||||
close: () => raw('Target.closeTarget', { targetId: page.targetId }).catch(() => {}),
|
||||
};
|
||||
},
|
||||
/** Brings the kit's own page to the front again (after a scratch page). */
|
||||
front: () => raw('Target.activateTarget', { targetId }),
|
||||
close: async () => {
|
||||
await raw('Target.closeTarget', { targetId }).catch(() => {});
|
||||
ws.close();
|
||||
|
||||
@@ -23,17 +23,22 @@ options: --script <steps.json> --size WxH (880x1000)
|
||||
--touch true (emulate a touch screen: mobile metrics, touch input)
|
||||
--semantics false (leave Flutter semantics off; point targets only)
|
||||
--user-agent <ua> (e.g. an Android phone's, for defaultTargetPlatform)
|
||||
--insecure true (open the build at http://pipelines-insecure.test:<port>,
|
||||
mapped to the loopback server: not a secure context, no Clipboard API)
|
||||
steps: open=<route>[@WxH] wait=<ms> shot=<name> click=<target> waitfor=<target>
|
||||
type=<text> press=<Enter|Escape|Tab|...> scroll=<dy> size=WxH
|
||||
files=<path>[,<path>] (answers the next file chooser)
|
||||
film=<target> labels=<name> tabs=<name> eval=<js> expect=<js> hover=<target>
|
||||
keys=<json events> grant=clipboard
|
||||
clipboard=read|write:<text> (the browser's clipboard, from a scratch
|
||||
page on the loopback origin, so it works for an --insecure page)
|
||||
rightclick=<target> (secondary button: context menus)
|
||||
drag=<target>><dx>,<dy> (JSON: drag, dx, dy, steps, gap, hold)
|
||||
swipe=<target>><dx>,<dy> pinch=<target>><scale> (with --touch true)
|
||||
target: <label> | label:<label> | key:<semantics identifier> | x,y`;
|
||||
|
||||
const opts = { wait: '1000', 'film-ms': '900' };
|
||||
const INSECURE_HOST = 'pipelines-insecure.test';
|
||||
const cliSteps = [];
|
||||
const argv = process.argv.slice(2);
|
||||
for (let i = 0; i < argv.length; i++) {
|
||||
@@ -91,8 +96,15 @@ function routeUrl(step, base) {
|
||||
let page;
|
||||
let exitCode = 0;
|
||||
try {
|
||||
const base = opts.build ? (server = await serveBuild(opts.build)).origin : opts.url;
|
||||
browser = await openBrowser({ cdp: opts.cdp });
|
||||
const loopback = opts.build ? (server = await serveBuild(opts.build)).origin : opts.url;
|
||||
// A hostname that is not localhost makes the page an insecure context, as
|
||||
// the app is over plain http on a LAN or tailnet address.
|
||||
const insecure = opts.insecure === 'true';
|
||||
const base = insecure ? loopback.replace('127.0.0.1', INSECURE_HOST) : loopback;
|
||||
browser = await openBrowser({
|
||||
cdp: opts.cdp,
|
||||
args: insecure ? [`--host-resolver-rules=MAP ${INSECURE_HOST} 127.0.0.1`] : [],
|
||||
});
|
||||
page = flutterPage(browser, log, { touch: opts.touch === 'true', semantics: opts.semantics !== 'false', userAgent: opts['user-agent'] });
|
||||
for (const step of steps) {
|
||||
const [verb] = Object.keys(step);
|
||||
@@ -146,6 +158,38 @@ try {
|
||||
await browser.sendBrowser('Browser.grantPermissions', { origin, permissions });
|
||||
break;
|
||||
}
|
||||
case 'clipboard': {
|
||||
// Reads (`read`, or `read:<label>`) or writes (`write:<text>`) the
|
||||
// clipboard from a scratch page on the loopback origin, a secure
|
||||
// context, then brings the page under test back to the front.
|
||||
const [mode, ...rest] = String(value).split(':');
|
||||
const arg = rest.join(':');
|
||||
const scratch = await browser.newPage();
|
||||
try {
|
||||
await scratch.send('Page.navigate', { url: new URL('/favicon.png', loopback).href });
|
||||
await delay(300);
|
||||
await browser.sendBrowser('Browser.grantPermissions', {
|
||||
origin: new URL(loopback).origin, permissions: ['clipboardReadWrite', 'clipboardSanitizedWrite'],
|
||||
});
|
||||
await browser.sendBrowser('Target.activateTarget', { targetId: scratch.targetId });
|
||||
const expression = mode === 'write'
|
||||
? `navigator.clipboard.writeText(${JSON.stringify(arg)}).then(() => 'wrote')`
|
||||
: 'navigator.clipboard.readText()';
|
||||
const r = await scratch.send('Runtime.evaluate', { expression, returnByValue: true, awaitPromise: true });
|
||||
if (r.exceptionDetails) throw new Error(`clipboard ${mode}: ${r.exceptionDetails.exception?.description ?? r.exceptionDetails.text}`);
|
||||
const result = r.result.value;
|
||||
log(` clipboard ${mode}${arg ? ' ' + arg : ''} = ${JSON.stringify(result)}`);
|
||||
(report.clipboard ??= []).push({ mode, arg, result });
|
||||
if (step.expect !== undefined && result !== step.expect) {
|
||||
throw new Error(`clipboard ${JSON.stringify(result)}, expected ${JSON.stringify(step.expect)}`);
|
||||
}
|
||||
} finally {
|
||||
await scratch.close();
|
||||
await browser.front();
|
||||
await delay(200);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'scroll': {
|
||||
const at = await page.scroll(Number(value), step.at, { dx: Number(step.dx ?? 0), repeat: Number(step.repeat ?? 1), gap: Number(step.gap ?? 16) });
|
||||
log(` wheel at ${Math.round(at.x)},${Math.round(at.y)}`);
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"params": "chats=2",
|
||||
"steps": [
|
||||
{ "open": "/chat/perf-chat-0@1000x800" },
|
||||
{ "wait": 1500 },
|
||||
{ "expect": "window.isSecureContext === false && navigator.clipboard === undefined", "name": "insecure page without the Clipboard API" },
|
||||
{ "clipboard": "write:SENTINEL" },
|
||||
{ "hover": "700,480" },
|
||||
{ "click": "key:chat-code-copy", "wait": 300 },
|
||||
{ "shot": "c1-code-copied" },
|
||||
{ "clipboard": "read:code-block-copy" },
|
||||
{ "clipboard": "write:SENTINEL" },
|
||||
{ "hover": "700,640" },
|
||||
{ "click": "491,681", "wait": 300 },
|
||||
{ "clipboard": "read:message-copy" },
|
||||
{ "clipboard": "write:[composer-ctrl-v]" },
|
||||
{ "click": "700,747" },
|
||||
{ "keys": [
|
||||
{ "type": "rawKeyDown", "key": "Control", "code": "ControlLeft", "modifiers": 2, "windowsVirtualKeyCode": 17 },
|
||||
{ "type": "rawKeyDown", "key": "v", "code": "KeyV", "modifiers": 2, "windowsVirtualKeyCode": 86 },
|
||||
{ "type": "keyUp", "key": "v", "code": "KeyV", "modifiers": 2, "windowsVirtualKeyCode": 86 },
|
||||
{ "type": "keyUp", "key": "Control", "code": "ControlLeft", "modifiers": 0, "windowsVirtualKeyCode": 17 }
|
||||
], "wait": 800 },
|
||||
{ "shot": "c2-composer-ctrl-v" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"params": "chats=2&terminals=1&terminal=panel",
|
||||
"steps": [
|
||||
{ "open": "/chat/perf-chat-0@1000x800" },
|
||||
{ "wait": 2000 },
|
||||
{ "expect": "window.isSecureContext === false && navigator.clipboard === undefined", "name": "insecure page without the Clipboard API" },
|
||||
{ "clipboard": "write:[ctrl-v]" },
|
||||
{ "click": "500,720" },
|
||||
{ "keys": [
|
||||
{ "type": "rawKeyDown", "key": "Control", "code": "ControlLeft", "modifiers": 2, "windowsVirtualKeyCode": 17 },
|
||||
{ "type": "rawKeyDown", "key": "v", "code": "KeyV", "modifiers": 2, "windowsVirtualKeyCode": 86 },
|
||||
{ "type": "keyUp", "key": "v", "code": "KeyV", "modifiers": 2, "windowsVirtualKeyCode": 86 },
|
||||
{ "type": "keyUp", "key": "Control", "code": "ControlLeft", "modifiers": 0, "windowsVirtualKeyCode": 17 }
|
||||
], "wait": 800 },
|
||||
{ "clipboard": "write:[shift-insert]" },
|
||||
{ "keys": [
|
||||
{ "type": "rawKeyDown", "key": "Shift", "code": "ShiftLeft", "modifiers": 8, "windowsVirtualKeyCode": 16 },
|
||||
{ "type": "rawKeyDown", "key": "Insert", "code": "Insert", "modifiers": 8, "windowsVirtualKeyCode": 45 },
|
||||
{ "type": "keyUp", "key": "Insert", "code": "Insert", "modifiers": 8, "windowsVirtualKeyCode": 45 },
|
||||
{ "type": "keyUp", "key": "Shift", "code": "ShiftLeft", "modifiers": 0, "windowsVirtualKeyCode": 16 }
|
||||
], "wait": 800 },
|
||||
{ "clipboard": "write:[ctrl-shift-v]" },
|
||||
{ "keys": [
|
||||
{ "type": "rawKeyDown", "key": "Control", "code": "ControlLeft", "modifiers": 2, "windowsVirtualKeyCode": 17 },
|
||||
{ "type": "rawKeyDown", "key": "Shift", "code": "ShiftLeft", "modifiers": 10, "windowsVirtualKeyCode": 16 },
|
||||
{ "type": "rawKeyDown", "key": "V", "code": "KeyV", "modifiers": 10, "windowsVirtualKeyCode": 86 },
|
||||
{ "type": "keyUp", "key": "V", "code": "KeyV", "modifiers": 10, "windowsVirtualKeyCode": 86 },
|
||||
{ "type": "keyUp", "key": "Shift", "code": "ShiftLeft", "modifiers": 2, "windowsVirtualKeyCode": 16 },
|
||||
{ "type": "keyUp", "key": "Control", "code": "ControlLeft", "modifiers": 0, "windowsVirtualKeyCode": 17 }
|
||||
], "wait": 800 },
|
||||
{ "shot": "p1-three-paste-keys" },
|
||||
{ "clipboard": "write:SENTINEL" },
|
||||
{ "drag": "96,570", "dx": 200, "dy": 0 },
|
||||
{ "keys": [
|
||||
{ "type": "rawKeyDown", "key": "Control", "code": "ControlLeft", "modifiers": 2, "windowsVirtualKeyCode": 17 },
|
||||
{ "type": "rawKeyDown", "key": "Shift", "code": "ShiftLeft", "modifiers": 10, "windowsVirtualKeyCode": 16 },
|
||||
{ "type": "rawKeyDown", "key": "C", "code": "KeyC", "modifiers": 10, "windowsVirtualKeyCode": 67 },
|
||||
{ "type": "keyUp", "key": "C", "code": "KeyC", "modifiers": 10, "windowsVirtualKeyCode": 67 },
|
||||
{ "type": "keyUp", "key": "Shift", "code": "ShiftLeft", "modifiers": 2, "windowsVirtualKeyCode": 16 },
|
||||
{ "type": "keyUp", "key": "Control", "code": "ControlLeft", "modifiers": 0, "windowsVirtualKeyCode": 17 }
|
||||
], "wait": 600 },
|
||||
{ "clipboard": "read:ctrl-shift-c", "expect": "TestTerminalOverWebsocket" },
|
||||
{ "type": " typed-after-copy" },
|
||||
{ "shot": "p2-copied-then-typed" },
|
||||
{ "rightclick": "500,700" },
|
||||
{ "shot": "p3-context-menu" },
|
||||
{ "press": "Escape" },
|
||||
{ "clipboard": "write:SENTINEL" },
|
||||
{ "rightclick": "500,700" },
|
||||
{ "click": "400,552" },
|
||||
{ "clipboard": "read:menu-copy", "expect": "TestTerminalOverWebsocket" },
|
||||
{ "rightclick": "500,700" },
|
||||
{ "click": "400,600", "wait": 400 },
|
||||
{ "shot": "p4-menu-paste-message" }
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user