Skip to content

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

fix: validate normalized workflow locators

Emre Sokullu5f10b1d6eb4e
diff --git a/test/workflow-editor.mjs b/test/workflow-editor.mjs
index c5de24ae3..ab3f79a1e 100644
--- a/test/workflow-editor.mjs
+++ b/test/workflow-editor.mjs
@@ -102,6 +102,33 @@ for (const [name, browserType] of Object.entries({ chromium, firefox })) {
assert.equal(imported.workflow.steps.length, 1);
}));
+ test(`${name}: locator ref checks use importer text normalization`, () => withEditor(async page => {
+ const refWithSuffix = `ref_${'a'.repeat(236)}!`;
+ const invalidCases = [
+ {
+ label: 'target', issue: 'needs a replayable target',
+ step: { id: 'step_1', tool: 'click_ax', args: {}, target: { id: refWithSuffix } }
+ },
+ {
+ label: 'click text', issue: 'arguments that the workflow importer cannot use',
+ step: { id: 'step_1', tool: 'click', args: { text: refWithSuffix } }
+ },
+ {
+ label: 'wait text', issue: 'arguments that the workflow importer cannot use',
+ step: { id: 'step_1', tool: 'wait_for_element', args: { text: refWithSuffix } }
+ }
+ ];
+ for (const scenario of invalidCases) {
+ const workflow = {
+ schema: 'webbrain-workflow/1', id: 'workflow_1', name: 'Ref validation',
+ start: { origin: 'https://example.com', pathFamily: '/' }, parameters: [], steps: [scenario.step]
+ };
+ await page.evaluate(value => editor.load(value), workflow);
+ assert.ok((await page.evaluate(() => editor.validate())).some(issue => issue.includes(scenario.issue)), `${scenario.label}: editor should report importer rejection`);
+ assert.equal((name === 'chromium' ? importChromeWorkflow : importFirefoxWorkflow)(workflow).reason, 'invalid_workflow', `${scenario.label}: importer rejects normalized ref token`);
+ }
+ }));
+
test(`${name}: parameter ids follow importer normalization and remain unique`, () => withEditor(async page => {
const workflow = {
...fixture,
diff --git a/web/workflow-editor/workflow-editor.js b/web/workflow-editor/workflow-editor.js
index 33c3d11d5..e66c790bf 100644
--- a/web/workflow-editor/workflow-editor.js
+++ b/web/workflow-editor/workflow-editor.js
@@ -42,7 +42,7 @@
if (!object(target)) return false;
let score = 0;
for (const [field, points] of Object.entries(targetFields)) {
- const value = String(target[field] ?? '').trim();
+ const value = workflowCleanText(target[field]);
if (value && !/^ref_[A-Za-z0-9_-]+$/i.test(value)) score += points;
}
return score >= 7;
@@ -66,13 +66,19 @@
&& (!own(args, 'clear') || typeof args.clear === 'boolean')
&& (step.tool !== 'set_field' || !own(args, 'submit') || typeof args.submit === 'boolean');
}
- case 'click': return only(['text']) && typeof args.text === 'string' && !!args.text.trim() && !/^ref_[A-Za-z0-9_-]+$/i.test(args.text.trim());
+ case 'click': {
+ const text = workflowCleanText(args.text);
+ return only(['text']) && typeof args.text === 'string' && !!text && !/^ref_[A-Za-z0-9_-]+$/i.test(text);
+ }
case 'scroll': return only(['direction', 'amount'])
&& (!own(args, 'direction') || ['up', 'down', 'left', 'right'].includes(args.direction))
&& (!own(args, 'amount') || Number.isFinite(args.amount));
- case 'wait_for_element': return only(['text', 'timeout']) && typeof args.text === 'string' && !!args.text.trim()
- && !/^ref_[A-Za-z0-9_-]+$/i.test(args.text.trim())
- && (!own(args, 'timeout') || Number.isFinite(args.timeout));
+ case 'wait_for_element': {
+ const text = workflowCleanText(args.text);
+ return only(['text', 'timeout']) && typeof args.text === 'string' && !!text
+ && !/^ref_[A-Za-z0-9_-]+$/i.test(text)
+ && (!own(args, 'timeout') || Number.isFinite(args.timeout));
+ }
default: return false;
}
}