Skip to content

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

Recognize a zero-padded page one in a placeholder

Claude585c54df9e43
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index ec42440af..1fb24f40c 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -11314,7 +11314,12 @@ export class Agent extends LoopDetector {
const allowed = ['filter', 'maxDepth', 'maxChars', 'ref_id', 'page', 'tree_revision'];
// Two values agree when they are the same once scalar types and the
// case of a filter are normalized, as the call is repaired below.
- const normalized = (value, key) => { const scalar = decimal(value); return typeof scalar === 'string' && key === 'filter' ? scalar.trim().toLowerCase() : scalar; };
+ const normalized = (value, key) => {
+ // A page is repaired below from up to four digits ("01" is 1).
+ if (key === 'page' && typeof value === 'string' && /^\s*\d{1,4}\s*$/.test(value)) return Number(value);
+ const scalar = decimal(value);
+ 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));
// 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
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index f45ccdc0c..f0f6aff54 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -10992,7 +10992,12 @@ export class Agent extends LoopDetector {
const allowed = ['filter', 'maxDepth', 'maxChars', 'ref_id', 'page', 'tree_revision'];
// Two values agree when they are the same once scalar types and the
// case of a filter are normalized, as the call is repaired below.
- const normalized = (value, key) => { const scalar = decimal(value); return typeof scalar === 'string' && key === 'filter' ? scalar.trim().toLowerCase() : scalar; };
+ const normalized = (value, key) => {
+ // A page is repaired below from up to four digits ("01" is 1).
+ if (key === 'page' && typeof value === 'string' && /^\s*\d{1,4}\s*$/.test(value)) return Number(value);
+ const scalar = decimal(value);
+ 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));
// 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
diff --git a/test/read-continuation-schema.mjs b/test/read-continuation-schema.mjs
index 672c3545f..bbca6af3e 100644
--- a/test/read-continuation-schema.mjs
+++ b/test/read-continuation-schema.mjs
@@ -265,7 +265,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'.slice(1)]) {
+ for (const page of [' 1 ', '1.0', '01']) {
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));