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:
2026-11-29 19:06:58 +00:00
parent 3d739c3bfc
commit 18807b8ac2
14 changed files with 714 additions and 26 deletions
+46 -2
View File
@@ -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)}`);