App: open a chat, the terminal or a diff in a new window
"Open in new window" sits beside Float: the chat pane and chat list row menus, a floating chat window's title bar, the terminal options menu and the diff bar, plus Alt+Shift+Y for the chat with the keyboard (listed in the shortcut help). Once the window opens the item leaves the main window as Float takes a pane out of the tiling. The window is its own app instance at /window/chat/<id>, /window/terminal?tab=<key> or /window/diff/<token>: only that item, named after it, with "Bring back to main window". It has its own connection and writes no shared layout (no open-chat workspace, window store or terminal layout) and posts no notifications, so they stay the main window's. Web opens a popup window (a blocked popup offers a tab); Linux and macOS start a second process with --detached (Flutter's multi-window API is still experimental); Android and iOS hide the action. The capture kit gains a follow step for windows a page opens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -88,6 +88,7 @@ In JSON, a step can also set `wait` (ms), `timeout`, `name`, `ms` and `frames`.
|
||||
| `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`) |
|
||||
| `tabs=name` | write the open tabs (`{url, type}`) to JSON, e.g. to see a link open a new tab |
|
||||
| `follow=/window/chat/` | move the following steps to the page whose URL contains the text (a window the app opened with `window.open`, at its own size, semantics on); `follow=main` returns to the page the kit opened (`examples/detached-chat-window.json`) |
|
||||
| `eval=<js>` | evaluate an expression in the page and log/record its value |
|
||||
| `expect=<js>` | fail the run (status 1) unless the expression is truthy; JSON `name` labels the check |
|
||||
|
||||
|
||||
@@ -88,6 +88,7 @@ export async function openBrowser({ cdp, gpu = false, args = [], chromePath = pr
|
||||
ws.send(JSON.stringify({ id, method, params, ...(session ? { sessionId: session } : {}) }));
|
||||
});
|
||||
let targetId;
|
||||
let main;
|
||||
try {
|
||||
({ targetId } = await raw('Target.createTarget', { url: 'about:blank' }));
|
||||
({ sessionId } = await raw('Target.attachToTarget', { targetId, flatten: true }));
|
||||
@@ -114,6 +115,33 @@ export async function openBrowser({ cdp, gpu = false, args = [], chromePath = pr
|
||||
},
|
||||
/** Brings the kit's own page to the front again (after a scratch page). */
|
||||
front: () => raw('Target.activateTarget', { targetId }),
|
||||
/**
|
||||
* Moves the kit's page session to another page target: the first one
|
||||
* whose URL contains [match] (a window the page opened with
|
||||
* `window.open`), waited for up to [timeout] ms; `main` returns to the
|
||||
* page the kit opened. Resolves to the target's URL.
|
||||
*/
|
||||
follow: async (match, timeout = 10000) => {
|
||||
main ??= { targetId, sessionId };
|
||||
if (match === 'main') {
|
||||
({ targetId, sessionId } = main);
|
||||
await raw('Target.activateTarget', { targetId });
|
||||
return (await raw('Target.getTargets')).targetInfos.find((t) => t.targetId === targetId)?.url;
|
||||
}
|
||||
const end = Date.now() + timeout;
|
||||
for (;;) {
|
||||
const hit = (await raw('Target.getTargets')).targetInfos
|
||||
.find((t) => t.type === 'page' && t.targetId !== main.targetId && t.url.includes(match));
|
||||
if (hit) {
|
||||
targetId = hit.targetId;
|
||||
({ sessionId } = await raw('Target.attachToTarget', { targetId, flatten: true }));
|
||||
await raw('Target.activateTarget', { targetId });
|
||||
return hit.url;
|
||||
}
|
||||
if (Date.now() > end) throw new Error(`no page whose URL contains ${JSON.stringify(match)} within ${timeout} ms`);
|
||||
await new Promise((ok) => setTimeout(ok, 100));
|
||||
}
|
||||
},
|
||||
close: async () => {
|
||||
await raw('Target.closeTarget', { targetId }).catch(() => {});
|
||||
ws.close();
|
||||
|
||||
@@ -28,7 +28,7 @@ options: --script <steps.json> --size WxH (880x1000)
|
||||
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>
|
||||
film=<target> labels=<name> tabs=<name> follow=<url part|main> 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)
|
||||
@@ -246,6 +246,15 @@ try {
|
||||
break;
|
||||
}
|
||||
case 'tabs': await save(file(value || 'tabs', 'json'), JSON.stringify(await browser.targets(), null, 2)); break;
|
||||
case 'follow': {
|
||||
// follow=<url part>: the steps after it act on that window (one the
|
||||
// page opened); follow=main returns to the page the kit opened.
|
||||
const url = await browser.follow(String(value), step.timeout);
|
||||
log(` now on ${url}`);
|
||||
if (value !== 'main') await page.adopt();
|
||||
await delay(step.wait ?? settle);
|
||||
break;
|
||||
}
|
||||
case 'labels': await save(file(value || 'labels', 'json'), JSON.stringify(await page.labels(), null, 2)); break;
|
||||
case 'film': {
|
||||
const what = String(value).startsWith('press:') ? String(value) : describe(parseTarget(value));
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
{ "size": "1400x900", "params": "chats=2",
|
||||
"steps": [
|
||||
{ "open": "/chat/perf-chat-0" },
|
||||
{ "wait": 1500 },
|
||||
{ "shot": "main-before" },
|
||||
{ "click": "More actions" },
|
||||
{ "shot": "pane-menu" },
|
||||
{ "click": "Open in new window (Alt+Shift+Y)", "wait": 1500 },
|
||||
{ "tabs": "tabs" },
|
||||
{ "follow": "/window/chat/", "wait": 2500 },
|
||||
{ "shot": "detached-chat" },
|
||||
{ "eval": "document.title" },
|
||||
{ "expect": "document.title === 'Fixture chat 1 · Pipelines'", "name": "the window is named after its chat" },
|
||||
{ "expect": "location.pathname === '/window/chat/perf-chat-0'", "name": "the window keeps its location" },
|
||||
{ "follow": "main", "wait": 800 },
|
||||
{ "shot": "main-after" },
|
||||
{ "follow": "/window/chat/", "wait": 500 },
|
||||
{ "click": "More actions" },
|
||||
{ "shot": "detached-menu" },
|
||||
{ "click": "Bring back to main window", "wait": 1500 },
|
||||
{ "follow": "main", "wait": 1200 },
|
||||
{ "tabs": "tabs-after-return" },
|
||||
{ "shot": "main-returned" }
|
||||
] }
|
||||
@@ -0,0 +1,13 @@
|
||||
{ "size": "1400x900", "params": "chats=2&terminals=1&terminal=panel",
|
||||
"steps": [
|
||||
{ "open": "/chat/perf-chat-0" },
|
||||
{ "wait": 2000 },
|
||||
{ "click": "Terminal options" },
|
||||
{ "shot": "terminal-menu" },
|
||||
{ "click": "Open in new window", "wait": 1500 },
|
||||
{ "shot": "main-after" },
|
||||
{ "follow": "/window/terminal", "wait": 3000 },
|
||||
{ "shot": "detached-terminal" },
|
||||
{ "eval": "document.title" },
|
||||
{ "expect": "document.title.startsWith('Terminal')", "name": "the window is named after its terminal" }
|
||||
] }
|
||||
@@ -125,6 +125,21 @@ export function flutterPage(browser, log, { touch = false, semantics = true, use
|
||||
if (touch) await enableTouch(send, viewport);
|
||||
await delay(800);
|
||||
},
|
||||
/**
|
||||
* Takes over a page that is already loading (a window the app opened)
|
||||
* at its own size: waits for Flutter and turns semantics on.
|
||||
*/
|
||||
async adopt() {
|
||||
await send('Page.enable');
|
||||
await send('Runtime.enable');
|
||||
// A window followed before already has its semantics tree.
|
||||
const started = "Boolean(document.querySelector('flt-semantics-placeholder, flt-semantics'))";
|
||||
await until(() => evaluate(started), 'Flutter to start', 30000);
|
||||
if (!semantics) return;
|
||||
await evaluate("document.querySelector('flt-semantics-placeholder')?.click()");
|
||||
await until(() => evaluate("document.querySelectorAll('flt-semantics').length > 0"), 'the semantics tree', 15000);
|
||||
await delay(800);
|
||||
},
|
||||
async click(target, timeout) {
|
||||
const point = await locate(target, timeout);
|
||||
await tap(point);
|
||||
|
||||
Reference in New Issue
Block a user