Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

Preserve guarded key dispatch and portable browser regression checks

Emre Sokullu1076a04c4f21
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index a36ff7e79..aebe79618 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -40001,7 +40001,12 @@ If the user has already named or confirmed this exact recipient, do NOT ask agai
error: `Unsupported key "${key}". Supported keys: ${SUPPORTED_KEYS.join(', ')}.`,
};
}
- const keyProgressBefore = String(key).startsWith('Arrow')
+ // The provisional progress annotation only applies to the unguarded
+ // speculative path (the Instagram carousel fix). A dispatch bound to a
+ // revalidated focused target keeps its pre-annotation contract: the
+ // consume already proved the exact editor, so "page did not change"
+ // must not be reported as a failed dispatch.
+ const keyProgressBefore = String(key).startsWith('Arrow') && !dispatchBinding?.token
? await this._keyProgressSnapshot(tabId, earlyCdpAbortSignal)
: '';
throwIfEarlyCdpAborted();
@@ -40074,10 +40079,12 @@ If the user has already named or confirmed this exact recipient, do NOT ask agai
throwIfEarlyCdpAborted();
}
+ const cdpKeyResponse = { success: true, dispatched: true, method: 'cdp-key', key, repeat };
+ if (guardedTargetConsumed) return cdpKeyResponse;
return await this._verifyProvisionalKeyProgress(
tabId,
key,
- { success: true, dispatched: true, method: 'cdp-key', key, repeat },
+ cdpKeyResponse,
keyProgressBefore,
earlyCdpAbortSignal,
);
diff --git a/test/firefox-bidi.mjs b/test/firefox-bidi.mjs
index 9a24f4c02..a0807b34f 100644
--- a/test/firefox-bidi.mjs
+++ b/test/firefox-bidi.mjs
@@ -81,16 +81,22 @@ test('installer and native launcher preserve Firefox message framing and command
const install = spawnSync(process.execPath, ['firefox-companion/install.mjs', directory], { encoding: 'utf8' });
assert.equal(install.status, 0, install.stderr);
const manifest = JSON.parse(await readFile(join(directory, 'one.webbrain.bidi.json'), 'utf8'));
+ // On Windows the wrapper is a .cmd batch file, which Node cannot spawn
+ // directly (CreateProcess EINVAL); route it through cmd.exe the same way
+ // Firefox does. POSIX wrappers are executable scripts and spawn directly.
+ const spawnHost = input => process.platform === 'win32'
+ ? spawnSync(process.env.ComSpec || 'cmd.exe', ['/c', manifest.path], { input, timeout: 5000 })
+ : spawnSync(manifest.path, [], { input, timeout: 5000 });
assert.deepEqual(manifest.allowed_extensions, ['[email protected]']);
const message = Buffer.from(JSON.stringify({ id: 12, command: 'script.evaluate', expression: 'arbitrary code' }));
const header = Buffer.alloc(4); header.writeUInt32LE(message.length);
- const result = spawnSync(manifest.path, [], { input: Buffer.concat([header, message]), timeout: 5000 });
+ const result = spawnHost(Buffer.concat([header, message]));
assert.equal(result.status, 0, result.stderr?.toString());
assert.equal(result.stdout.readUInt32LE(0), result.stdout.length - 4);
assert.deepEqual(JSON.parse(result.stdout.subarray(4)), { id: 12, error: 'Unknown companion command' });
const rejected = Buffer.from(JSON.stringify({id:13,command:'perform',runId:id(),action:'click',payload:{}}));
const rejectedHeader = Buffer.alloc(4); rejectedHeader.writeUInt32LE(rejected.length);
- const rejectedResult = spawnSync(manifest.path, [], {input:Buffer.concat([rejectedHeader,rejected]),timeout:5000});
+ const rejectedResult = spawnHost(Buffer.concat([rejectedHeader, rejected]));
assert.equal(rejectedResult.status,0,rejectedResult.stderr?.toString());
const failure = JSON.parse(rejectedResult.stdout.subarray(4));
assert.equal(failure.id,13);
diff --git a/test/systemone-trace.mjs b/test/systemone-trace.mjs
index c3dea9427..477c5bc83 100644
--- a/test/systemone-trace.mjs
+++ b/test/systemone-trace.mjs
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { readFile } from 'node:fs/promises';
-import { resolve } from 'node:path';
+import { resolve, sep } from 'node:path';
import { chromium, firefox } from 'playwright';
for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {
@@ -31,7 +31,7 @@ for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {
const path = new URL(route.request().url()).pathname;
if (path === '/') return route.fulfill({ contentType: 'text/html', body: '<!doctype html>' });
const file = resolve(`src/${build}`, '.' + path);
- if (!file.startsWith(resolve(`src/${build}`) + '/')) return route.abort();
+ if (!file.startsWith(resolve(`src/${build}`) + sep)) return route.abort();
await route.fulfill({ contentType: 'text/javascript', body: await readFile(file) });
});
await page.goto('http://jev-trace.local/');
diff --git a/test/trace-full-export.mjs b/test/trace-full-export.mjs
index e38a47abd..7daf8e5d5 100644
--- a/test/trace-full-export.mjs
+++ b/test/trace-full-export.mjs
@@ -1,7 +1,7 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
-import { resolve } from 'node:path';
+import { resolve, sep } from 'node:path';
import { chromium, firefox } from 'playwright';
import vm from 'node:vm';
@@ -126,7 +126,7 @@ for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {
if (path === '/') return route.fulfill({ contentType: 'text/html', body: '<!doctype html>' });
if (path === '/src/ui/export-harness.js') return route.fulfill({ contentType: 'text/javascript', body: harness });
const file = resolve(`src/${build}`, '.' + path);
- if (!file.startsWith(resolve(`src/${build}`) + '/')) return route.abort();
+ if (!file.startsWith(resolve(`src/${build}`) + sep)) return route.abort();
await route.fulfill({ contentType: 'text/javascript', body: await readFile(file) });
});
const writer = await context.newPage();
@@ -223,7 +223,7 @@ for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {
const path = new URL(route.request().url()).pathname;
if (path === '/') return route.fulfill({ contentType: 'text/html', body: '<!doctype html>' });
const file = resolve(`src/${build}`, '.' + path);
- if (!file.startsWith(resolve(`src/${build}`) + '/')) return route.abort();
+ if (!file.startsWith(resolve(`src/${build}`) + sep)) return route.abort();
await route.fulfill({ contentType: 'text/javascript', body: await readFile(file) });
});
await page.goto('http://trace-test.local/');