Skip to content

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

Classify every effective first-page value as a placeholder page

Claudedc4c5a27ba68
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 05e48283f..6156582e6 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -11321,6 +11321,13 @@ export class Agent extends LoopDetector {
return typeof scalar === 'string' && key === 'filter' ? scalar.trim().toLowerCase() : scalar;
};
const agrees = (key, value) => !Object.hasOwn(next, key) || Object.is(normalized(next[key], key), normalized(value, key));
+ // Every page value the read treats as the first (Math.max(1, floor(Number(page) || 1))).
+ const firstPage = value => {
+ if (value === undefined || value === null || value === '') return true;
+ const page = normalized(value, 'page');
+ const number = typeof page === 'string' ? decimal(page) : page;
+ return typeof number === 'number' && Number.isFinite(number) && Math.max(1, Math.floor(number)) === 1;
+ };
// Only a truncated result returns a continuation, and it is always for
// page 2 or later with a tree revision. One for page 1 without a
// revision, on a call that names none either, continues nothing: the
@@ -11330,7 +11337,7 @@ export class Agent extends LoopDetector {
const restart = continuation && typeof continuation === 'object' && !Array.isArray(continuation)
&& Object.keys(continuation).length > 0 && Object.keys(continuation).every(key => allowed.includes(key))
&& !String(continuation.tree_revision ?? '').trim() && !String(next.tree_revision ?? '').trim()
- && [undefined, null, '', 1].includes(normalized(continuation.page, 'page'))
+ && firstPage(continuation.page)
// It is a placeholder only beside a read of the call's own. A restart
// the tool returns is always anchored (it names a ref_id), so one that
// names none cannot be genuine and is dropped beside any top-level read;
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 202fa9d61..e55ba3461 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -10999,6 +10999,13 @@ export class Agent extends LoopDetector {
return typeof scalar === 'string' && key === 'filter' ? scalar.trim().toLowerCase() : scalar;
};
const agrees = (key, value) => !Object.hasOwn(next, key) || Object.is(normalized(next[key], key), normalized(value, key));
+ // Every page value the read treats as the first (Math.max(1, floor(Number(page) || 1))).
+ const firstPage = value => {
+ if (value === undefined || value === null || value === '') return true;
+ const page = normalized(value, 'page');
+ const number = typeof page === 'string' ? decimal(page) : page;
+ return typeof number === 'number' && Number.isFinite(number) && Math.max(1, Math.floor(number)) === 1;
+ };
// Only a truncated result returns a continuation, and it is always for
// page 2 or later with a tree revision. One for page 1 without a
// revision, on a call that names none either, continues nothing: the
@@ -11008,7 +11015,7 @@ export class Agent extends LoopDetector {
const restart = continuation && typeof continuation === 'object' && !Array.isArray(continuation)
&& Object.keys(continuation).length > 0 && Object.keys(continuation).every(key => allowed.includes(key))
&& !String(continuation.tree_revision ?? '').trim() && !String(next.tree_revision ?? '').trim()
- && [undefined, null, '', 1].includes(normalized(continuation.page, 'page'))
+ && firstPage(continuation.page)
// It is a placeholder only beside a read of the call's own. A restart
// the tool returns is always anchored (it names a ref_id), so one that
// names none cannot be genuine and is dropped beside any top-level read;
diff --git a/test/read-continuation-schema.mjs b/test/read-continuation-schema.mjs
index b3877eead..98fece8f9 100644
--- a/test/read-continuation-schema.mjs
+++ b/test/read-continuation-schema.mjs
@@ -269,7 +269,7 @@ for (const browser of ['chrome', 'firefox']) {
const partial = agent._repairToolCallArgs('get_accessibility_tree', { filter: 'all', continuationArgs: { maxDepth: 1, page: 1 } });
assert.equal(partial.result, undefined);
assert.deepEqual(partial.args, { filter: 'all' });
- for (const page of [' 1 ', '1.0', '01']) {
+ for (const page of [' 1 ', '1.0', '01', 0, 1.5, '0', -2]) {
const loose = agent._repairToolCallArgs('get_accessibility_tree', { filter: 'all', maxDepth: 8,
continuationArgs: { filter: 'visible', maxDepth: 15, page } });
assert.equal(loose.result, undefined, JSON.stringify(page));