Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

fix: map BrowserView host windows so pin Escape reaches the page

Rachb279fcb6056d
diff --git a/apps/native/electron/browser-visual.cjs b/apps/native/electron/browser-visual.cjs
index c78a4b5e..96a9418b 100644
--- a/apps/native/electron/browser-visual.cjs
+++ b/apps/native/electron/browser-visual.cjs
@@ -21,25 +21,30 @@ async function runBrowserVisuals({ win: fixtureWindow, origin, output }) {
const pin = (event, value) => { if (event.sender === browser.tabs.get('browser-test')?.view?.webContents) { wc.focus(); wc.send('browser-event', { type: 'pin', chat: 'browser-test', pin: value }); } };
const cancelled = event => { if (event.sender === browser.tabs.get('browser-test')?.view?.webContents) wc.send('browser-event', { type: 'pick-cancelled', chat: 'browser-test' }); };
ipcMain.on('browser-pin', pin); ipcMain.on('browser-pick-cancelled', cancelled);
- const wait = async fn => { for (let i = 0; i < 100; i++) { if (await fn()) return; await sleep(50); } throw Error('Browser visual timed out'); };
+ const wait = async (fn, what) => { for (let i = 0; i < 100; i++) { if (await fn()) return; await sleep(50); } throw Error(`Browser visual timed out: ${what}`); };
try {
fixtureWindow.hide();
+ presentWindow(win, undefined, { mapped: true });
await win.loadURL(`${origin}/visual-tests/browser?url=${encodeURIComponent(url)}`);
- await wait(() => js(`!!document.querySelector('[aria-pressed="false"]:not(:disabled)')`));
- await wait(() => browser.tabs.get('browser-test')?.view?.webContents.getURL() === url);
+ await wait(() => js(`!!document.querySelector('[aria-pressed="false"]:not(:disabled)')`), 'pin control');
+ await wait(() => browser.tabs.get('browser-test')?.view?.webContents.getURL() === url, 'fixture URL');
const page = browser.tabs.get('browser-test').view.webContents;
- await wait(async () => !page.isLoading());
+ const picking = () => page.executeJavaScript(`!![...document.querySelectorAll('div')].some(el => el.textContent === 'Click an element to pin · Esc to cancel')`);
+ await wait(async () => !page.isLoading(), 'page idle');
+ await wait(() => { const rect = browser.tabs.get('browser-test')?.rect; return rect && rect.width > 80 && rect.height > 80; }, 'page bounds');
await js(`document.querySelector('button[aria-pressed]').click()`);
- await wait(() => js(`document.querySelector('button[aria-pressed]').getAttribute('aria-pressed')==='true'`));
- presentWindow(win); page.focus();
+ await wait(() => js(`document.querySelector('button[aria-pressed]').getAttribute('aria-pressed')==='true'`), 'pick armed');
+ await wait(() => picking(), 'pick mode on page');
+ page.focus();
page.sendInputEvent({ type: 'keyDown', keyCode: 'Escape' });
- await wait(() => js(`document.querySelector('button[aria-pressed]').getAttribute('aria-pressed')==='false'`));
- await js(`document.querySelector('button[aria-pressed]').click()`); await sleep(100);
+ await wait(() => js(`document.querySelector('button[aria-pressed]').getAttribute('aria-pressed')==='false'`), 'Escape cancel');
+ await js(`document.querySelector('button[aria-pressed]').click()`);
+ await wait(() => picking(), 'pick mode after recancel');
page.sendInputEvent({ type: 'mouseMove', x: 100, y: 80 });
page.sendInputEvent({ type: 'mouseDown', x: 100, y: 80, button: 'left', clickCount: 1 });
page.sendInputEvent({ type: 'mouseUp', x: 100, y: 80, button: 'left', clickCount: 1 });
- await wait(() => js(`!!document.querySelector('[aria-label="Note for pin 1"]')`));
- await wait(() => page.executeJavaScript(`document.querySelector('[data-graff-pins]')?.textContent==='1'`));
+ await wait(() => js(`!!document.querySelector('[aria-label="Note for pin 1"]')`), 'pin note');
+ await wait(() => page.executeJavaScript(`document.querySelector('[data-graff-pins]')?.textContent==='1'`), 'pin marker');
assert.equal(await page.executeJavaScript('document.body.dataset.activated || document.body.dataset.clicked || null'), null, 'pinning must not activate the target');
assert.equal(await js(`document.activeElement.getAttribute('aria-label')`), 'Note for pin 1');
for (const zoom of [1, 1.25]) {
@@ -57,7 +62,7 @@ async function runBrowserVisuals({ win: fixtureWindow, origin, output }) {
}
fs.writeFileSync(path.join(output, 'browser-pin.png'), (await wc.capturePage()).toPNG());
await js(`document.querySelector('[aria-label="Remove pin 1"]').click()`);
- await wait(() => page.executeJavaScript(`!document.querySelector('[data-graff-pins]')?.textContent`));
+ await wait(() => page.executeJavaScript(`!document.querySelector('[data-graff-pins]')?.textContent`), 'pin removed');
await wc.loadURL('about:blank'); // Leave the pane so its ResizeObserver no longer reattaches it.
browser.hide('browser-test');
const hidden = await browserAction(browser, 'browser-test', 'screenshot'); assert.ok(hidden.data.length > 100);
diff --git a/apps/native/electron/test-window.cjs b/apps/native/electron/test-window.cjs
index 4024caf5..106b9638 100644
--- a/apps/native/electron/test-window.cjs
+++ b/apps/native/electron/test-window.cjs
@@ -7,8 +7,12 @@ function testWindowMode() {
return 'hidden';
}
-function presentWindow(win, app) {
- const mode = testWindowMode();
+function presentWindow(win, app, extra = {}) {
+ // A WebContentsView host has to be mapped: the chrome measures the
+ // pane with getBoundingClientRect, and sendInputEvent only reaches
+ // the page when the view is visible. showInactive keeps #832 — we
+ // still do not steal focus unless foreground is requested.
+ const mode = extra.mapped && testWindowMode() === 'hidden' ? 'visible' : testWindowMode();
if (win.webContents && !win.webContents.isDestroyed()) win.webContents.setBackgroundThrottling(false);
if (mode === 'foreground') {
app?.focus?.({ steal: true });
diff --git a/apps/native/electron/test-window.test.cjs b/apps/native/electron/test-window.test.cjs
index ddd9413d..ca259f88 100644
--- a/apps/native/electron/test-window.test.cjs
+++ b/apps/native/electron/test-window.test.cjs
@@ -24,3 +24,15 @@ test('foreground interaction is an explicit opt-in', () => {
expect(calls).toEqual(['steal', 'show', 'focus']);
process.env.GRAFF_ELECTRON_FOREGROUND = previous;
});
+
+test('mapped presentWindow shows inactive so a BrowserView host can measure', () => {
+ const previous = process.env.GRAFF_ELECTRON_FOREGROUND;
+ const visible = process.env.GRAFF_ELECTRON_VISIBLE;
+ delete process.env.GRAFF_ELECTRON_FOREGROUND;
+ delete process.env.GRAFF_ELECTRON_VISIBLE;
+ const calls = [];
+ expect(presentWindow({ show() { calls.push('show'); }, focus() { calls.push('focus'); }, showInactive() { calls.push('inactive'); }, webContents: { isDestroyed: () => false, setBackgroundThrottling() {} } }, { focus() { calls.push('steal'); } }, { mapped: true })).toBe('visible');
+ expect(calls).toEqual(['inactive']);
+ process.env.GRAFF_ELECTRON_FOREGROUND = previous;
+ process.env.GRAFF_ELECTRON_VISIBLE = visible;
+});