Skip to content

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

Scheduled URL tasks open their own tab instead of navigating the user's

Claudeec1852a8fa18
diff --git a/docs/architecture.md b/docs/architecture.md
index 1bfa58094..253d74520 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -1301,7 +1301,7 @@ pending β†’ running β†’ completed
**Targets**
- `current_tab` β€” runs against the tab that was active when the job was created; fails if the tab is gone or has navigated away.
-- `url` β€” opens (or reuses) a tab for a given http(s) URL at run time.
+- `url` β€” opens (or reuses) a tab for a given http(s) URL at run time. A tab already on that URL is used as it is. Otherwise the run opens its own inactive helper tab and keeps it for later runs; only that helper is ever navigated back to the URL. The tab the task was created from belongs to the user and is never navigated away from its page. The run is told that an error or "not found" page at the address means the target is missing, so it ends as failed and repeated failures pause the task.
**Schedule**
diff --git a/src/chrome/src/agent/scheduler.js b/src/chrome/src/agent/scheduler.js
index a2734d383..0ec014a45 100644
--- a/src/chrome/src/agent/scheduler.js
+++ b/src/chrome/src/agent/scheduler.js
@@ -1610,11 +1610,16 @@ export class ScheduledJobManager {
if (sameTargetUrl(job.target.url, tab?.url || '')) {
return job.target.tabId;
}
+ // Only a helper tab this job opened is sent back to its page. The
+ // tab the task was created from is the user's: it may be on
+ // anything by now, so a run never navigates it away.
if (job.source !== 'watch') {
- try {
- await this.api.tabs.update(job.target.tabId, { url: job.target.url });
- return job.target.tabId;
- } catch { /* create a fresh tab below */ }
+ if (job.target.helperTab === true) {
+ try {
+ await this.api.tabs.update(job.target.tabId, { url: job.target.url });
+ return job.target.tabId;
+ } catch { /* create a fresh tab below */ }
+ }
} else {
// A diverged helper is watch-owned and inactive; close it instead
// of leaking one abandoned tab per poll on pages that redirect or
@@ -1630,7 +1635,7 @@ export class ScheduledJobManager {
['pending', 'queued'].includes(prev.status) && !execution?.cancelled
), (prev) => ({
tabId: tab.id,
- target: { ...prev.target, tabId: tab.id },
+ target: { ...prev.target, tabId: tab.id, helperTab: true },
}));
} finally {
// Cancellation/pause can finish before tabs.create returns, when it
@@ -1703,10 +1708,14 @@ export class ScheduledJobManager {
// a different schedule ("on Monday at 9, start an hourly check").
const recurring = job.schedule?.type === 'recurring';
const pauseNote = recurring ? '; repeated failed runs pause this schedule for the user' : '';
+ // A run opens its URL itself, so an error page there is not a page the
+ // user chose: the target is missing, not the answer.
+ const targetNote = job.target?.type === 'url'
+ ? ' An error or "not found" page at the task\'s address means the target is missing.' : '';
const scheduleNote = recurring
? ' This run comes from the task\'s own recurring schedule, which already repeats it; do not create another schedule for this task.'
: ' This run is the scheduled execution of an existing task; do not schedule this task again. Create a different schedule only if the task explicitly asks to set one up.';
- return `[Scheduled task ${job.id}: ${job.title}]\nThe user explicitly scheduled this future task. Treat this as the user-authored task for this scheduled run.\nTask: ${job.prompt}\nFirst reread the current page/state. If the task is stale, conflicts with newer user messages, or needs user input, stop and explain. If the target or condition needed to do this is missing or ambiguous, do not guess: call done with outcome "failed" and name what is missing${pauseNote}.${scheduleNote}`;
+ return `[Scheduled task ${job.id}: ${job.title}]\nThe user explicitly scheduled this future task. Treat this as the user-authored task for this scheduled run.\nTask: ${job.prompt}\nFirst reread the current page/state. If the task is stale, conflicts with newer user messages, or needs user input, stop and explain. If the target or condition needed to do this is missing or ambiguous, do not guess: call done with outcome "failed" and name what is missing${pauseNote}.${targetNote}${scheduleNote}`;
}
async _evaluateSystemOne(job, result, outcome, runMeta = {}) {
diff --git a/src/firefox/src/agent/scheduler.js b/src/firefox/src/agent/scheduler.js
index c4ba45149..90f6a0441 100644
--- a/src/firefox/src/agent/scheduler.js
+++ b/src/firefox/src/agent/scheduler.js
@@ -1586,11 +1586,16 @@ export class ScheduledJobManager {
if (sameTargetUrl(job.target.url, tab?.url || '')) {
return job.target.tabId;
}
+ // Only a helper tab this job opened is sent back to its page. The
+ // tab the task was created from is the user's: it may be on
+ // anything by now, so a run never navigates it away.
if (job.source !== 'watch') {
- try {
- await this.api.tabs.update(job.target.tabId, { url: job.target.url });
- return job.target.tabId;
- } catch { /* create a fresh tab below */ }
+ if (job.target.helperTab === true) {
+ try {
+ await this.api.tabs.update(job.target.tabId, { url: job.target.url });
+ return job.target.tabId;
+ } catch { /* create a fresh tab below */ }
+ }
} else {
// A diverged helper is watch-owned and inactive; close it instead
// of leaking one abandoned tab per poll on pages that redirect or
@@ -1606,7 +1611,7 @@ export class ScheduledJobManager {
['pending', 'queued'].includes(prev.status) && !execution?.cancelled
), (prev) => ({
tabId: tab.id,
- target: { ...prev.target, tabId: tab.id },
+ target: { ...prev.target, tabId: tab.id, helperTab: true },
}));
} finally {
// Cancellation/pause can finish before tabs.create returns, when it
@@ -1679,10 +1684,14 @@ export class ScheduledJobManager {
// a different schedule ("on Monday at 9, start an hourly check").
const recurring = job.schedule?.type === 'recurring';
const pauseNote = recurring ? '; repeated failed runs pause this schedule for the user' : '';
+ // A run opens its URL itself, so an error page there is not a page the
+ // user chose: the target is missing, not the answer.
+ const targetNote = job.target?.type === 'url'
+ ? ' An error or "not found" page at the task\'s address means the target is missing.' : '';
const scheduleNote = recurring
? ' This run comes from the task\'s own recurring schedule, which already repeats it; do not create another schedule for this task.'
: ' This run is the scheduled execution of an existing task; do not schedule this task again. Create a different schedule only if the task explicitly asks to set one up.';
- return `[Scheduled task ${job.id}: ${job.title}]\nThe user explicitly scheduled this future task. Treat this as the user-authored task for this scheduled run.\nTask: ${job.prompt}\nFirst reread the current page/state. If the task is stale, conflicts with newer user messages, or needs user input, stop and explain. If the target or condition needed to do this is missing or ambiguous, do not guess: call done with outcome "failed" and name what is missing${pauseNote}.${scheduleNote}`;
+ return `[Scheduled task ${job.id}: ${job.title}]\nThe user explicitly scheduled this future task. Treat this as the user-authored task for this scheduled run.\nTask: ${job.prompt}\nFirst reread the current page/state. If the task is stale, conflicts with newer user messages, or needs user input, stop and explain. If the target or condition needed to do this is missing or ambiguous, do not guess: call done with outcome "failed" and name what is missing${pauseNote}.${targetNote}${scheduleNote}`;
}
async _evaluateSystemOne(job, result, outcome, runMeta = {}) {
diff --git a/test/agent-lifecycle.mjs b/test/agent-lifecycle.mjs
index a8502cf96..eb5881a10 100644
--- a/test/agent-lifecycle.mjs
+++ b/test/agent-lifecycle.mjs
@@ -1187,6 +1187,36 @@ for (const [browser, Agent, Scheduler] of schedulingVariants) {
assert.equal(f.manager._executions.size, 0);
} finally { await f.close(); }
});
+ test(`${browser}: a URL task opens its own background tab instead of navigating the tab it was created from`, async () => {
+ const f = await schedulingFixture(Agent, Scheduler);
+ const created = [], navigations = [], runs = [], prompts = [];
+ let helperUrl = 'https://owned.example/inspection';
+ api.tabs.get = async id => id === 1902 ? { id, url: helperUrl, title: 'Owned helper' } : { id, url: 'https://example.com/', title: 'The page the user is on' };
+ api.tabs.create = async args => { created.push(structuredClone(args)); return { id: 1902, ...args }; };
+ api.tabs.update = async (id, args) => { navigations.push({ id, ...structuredClone(args) }); return { id, ...args }; };
+ f.agent.processMessage = async (id, prompt) => { runs.push(id); prompts.push(prompt); return 'The owned page was read.'; };
+ try {
+ // The task was created from the user's tab, which is on another page.
+ const result = await f.manager.createTaskJob({ tabId: f.tabId, conversationId: 'manual', source: 'ui', currentUrl: 'https://example.com/',
+ args: { ...schedulingArgs('schedule_task'), schedule: { type: 'recurring', after_seconds: 90, interval_minutes: 5 },
+ target: { type: 'url', url: 'https://owned.example/inspection' } } });
+ assert.equal(result.success, true);
+ f.agent._finishSteeringRun(f.tabId); f.agent._releaseRunEntry(f.tabId);
+ const alarmName = [...f.alarms.keys()][0];
+ await f.manager.handleAlarm(alarmName);
+ assert.deepEqual(navigations, [], 'the tab the task was created from is never navigated');
+ assert.deepEqual(created, [{ url: 'https://owned.example/inspection', active: false }]);
+ assert.deepEqual(runs, [1902]);
+ assert.equal(f.jobs()[0].target.tabId, 1902); assert.equal(f.jobs()[0].target.helperTab, true);
+ assert.match(prompts[0], /"not found" page at the task's address means the target is missing/);
+ // The helper the job opened is its own: once it has wandered off, the
+ // next run sends it back instead of opening another one.
+ helperUrl = 'https://owned.example/elsewhere';
+ await f.manager.handleAlarm(alarmName);
+ assert.deepEqual(navigations, [{ id: 1902, url: 'https://owned.example/inspection' }]);
+ assert.equal(created.length, 1); assert.deepEqual(runs, [1902, 1902]);
+ } finally { await f.close(); }
+ });
}
for (const [browser, Agent, Scheduler] of schedulingVariants) {