Skip to content

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

Schedule form: show its heading, target the URL the prompt names

Claude7fa80e892351
diff --git a/docs/slash-commands.md b/docs/slash-commands.md
index 2cec849ea..f29c9e54f 100644
--- a/docs/slash-commands.md
+++ b/docs/slash-commands.md
@@ -14,7 +14,7 @@ for its available flags.
| `/act` | Switch to Act mode before sending |
| `/dev` | Switch to Dev mode before sending |
| `/plan` | Switch to Ask mode with planning intent |
-| `/schedule [prompt]` | Create a scheduled task, optionally prefilling its prompt |
+| `/schedule [prompt]` | Create a scheduled task, optionally prefilling its prompt; a prompt that names one http(s) address targets that page instead of the open tab |
| `/schedule --list` | Show scheduled tasks |
| `/watch [--keep] [--secs <30-120>] [--long \| --short] <condition and action> [/beep]` | Poll the current page for a condition; stop after the first match unless `--keep` is set, and optionally play a background alert |
| `/progress` | Show the current progress ledger |
diff --git a/src/chrome/src/ui/sidepanel.js b/src/chrome/src/ui/sidepanel.js
index 1934eb53d..f7be8e05a 100644
--- a/src/chrome/src/ui/sidepanel.js
+++ b/src/chrome/src/ui/sidepanel.js
@@ -4373,6 +4373,17 @@ function isHttpScheduleUrl(value) {
}
}
+// The one http(s) address a task's prompt names, so "check https://example.com/
+// every day" targets that page rather than whatever tab is open.
+function scheduleUrlFromPrompt(prompt) {
+ const urls = new Set();
+ for (const match of String(prompt || '').matchAll(/https?:\/\/[^\s<>"'`]+/gi)) {
+ const url = match[0].replace(/[)\].,;:!?]+$/, '');
+ if (isHttpScheduleUrl(url)) urls.add(url);
+ }
+ return urls.size === 1 ? [...urls][0] : '';
+}
+
async function getCurrentScheduleUrl(tabId = currentTabId) {
if (tabId == null) return '';
try {
@@ -4573,7 +4584,7 @@ async function renderScheduleComposer(prefillPrompt = '', tabId = currentTabId)
const initialScheduleUrl = await getCurrentScheduleUrl(tabId);
if (currentTabId !== tabId) return;
- const msgEl = addMessage('system', t('sp.schedule_form.opened'));
+ const msgEl = addMessage('system', systemHtml(t('sp.schedule_form.opened')));
const content = msgEl.querySelector('.message-content');
const form = document.createElement('form');
form.className = 'schedule-composer';
@@ -4643,8 +4654,9 @@ async function renderScheduleComposer(prefillPrompt = '', tabId = currentTabId)
urlInput.className = 'schedule-url';
urlInput.placeholder = 'https://example.com/';
addScheduleField(form, t('sp.schedule_form.target_url'), urlInput);
- if (isHttpScheduleUrl(initialScheduleUrl)) {
- urlInput.value = initialScheduleUrl;
+ const targetUrl = scheduleUrlFromPrompt(prefillPrompt) || initialScheduleUrl;
+ if (isHttpScheduleUrl(targetUrl)) {
+ urlInput.value = targetUrl;
targetType.value = 'url';
}
diff --git a/src/firefox/src/ui/sidepanel.js b/src/firefox/src/ui/sidepanel.js
index 258efabf6..c73c6ec28 100644
--- a/src/firefox/src/ui/sidepanel.js
+++ b/src/firefox/src/ui/sidepanel.js
@@ -4237,6 +4237,17 @@ function isHttpScheduleUrl(value) {
}
}
+// The one http(s) address a task's prompt names, so "check https://example.com/
+// every day" targets that page rather than whatever tab is open.
+function scheduleUrlFromPrompt(prompt) {
+ const urls = new Set();
+ for (const match of String(prompt || '').matchAll(/https?:\/\/[^\s<>"'`]+/gi)) {
+ const url = match[0].replace(/[)\].,;:!?]+$/, '');
+ if (isHttpScheduleUrl(url)) urls.add(url);
+ }
+ return urls.size === 1 ? [...urls][0] : '';
+}
+
async function getCurrentScheduleUrl(tabId = currentTabId) {
if (tabId == null) return '';
try {
@@ -4437,7 +4448,7 @@ async function renderScheduleComposer(prefillPrompt = '', tabId = currentTabId)
const initialScheduleUrl = await getCurrentScheduleUrl(tabId);
if (currentTabId !== tabId) return;
- const msgEl = addMessage('system', t('sp.schedule_form.opened'));
+ const msgEl = addMessage('system', systemHtml(t('sp.schedule_form.opened')));
const content = msgEl.querySelector('.message-content');
const form = document.createElement('form');
form.className = 'schedule-composer';
@@ -4507,8 +4518,9 @@ async function renderScheduleComposer(prefillPrompt = '', tabId = currentTabId)
urlInput.className = 'schedule-url';
urlInput.placeholder = 'https://example.com/';
addScheduleField(form, t('sp.schedule_form.target_url'), urlInput);
- if (isHttpScheduleUrl(initialScheduleUrl)) {
- urlInput.value = initialScheduleUrl;
+ const targetUrl = scheduleUrlFromPrompt(prefillPrompt) || initialScheduleUrl;
+ if (isHttpScheduleUrl(targetUrl)) {
+ urlInput.value = targetUrl;
targetType.value = 'url';
}
diff --git a/test/run.js b/test/run.js
index 76b38745d..3c903ab35 100644
--- a/test/run.js
+++ b/test/run.js
@@ -42613,7 +42613,7 @@ test('sidepanel exposes schedule slash commands in both builds', () => {
assert.match(panel, /function replaceCachedScheduleComposer\(tabId, composerId, job\) \{[\s\S]*?form\.remove\(\);[\s\S]*?renderScheduledJobCreatedMessage\(job, msgEl, wrapper\);[\s\S]*?persistTabChat\(tabId, wrapper\.innerHTML\);[\s\S]*?\}/, `${label}: completed off-tab schedule creates should reconcile cached composer messages by job id`);
assert.match(panel, /function updateCachedScheduleComposerError\(tabId, composerId, message\) \{[\s\S]*?form\.schedule-composer\[data-composer-id="\$\{composerId\}"\][\s\S]*?submit\.disabled = false;[\s\S]*?errorEl\.textContent = message \|\| '';[\s\S]*?\}/, `${label}: failed off-tab schedule creates should re-enable cached composers with the error`);
assert.match(panel, /async function renderScheduleComposer\(prefillPrompt = '', tabId = currentTabId\)/, `${label}: schedule form should capture the requested tab`);
- assert.match(panel, /const initialScheduleUrl = await getCurrentScheduleUrl\(tabId\);[\s\S]*?if \(currentTabId !== tabId\) return;[\s\S]*?addMessage\('system', t\('sp\.schedule_form\.opened'\)\)/, `${label}: schedule form should resolve target defaults before rendering and drop stale tab switches`);
+ assert.match(panel, /const initialScheduleUrl = await getCurrentScheduleUrl\(tabId\);[\s\S]*?if \(currentTabId !== tabId\) return;[\s\S]*?addMessage\('system', systemHtml\(t\('sp\.schedule_form\.opened'\)\)\)/, `${label}: schedule form should resolve target defaults before rendering and drop stale tab switches; its heading is markup, not text`);
assert.match(panel, /form\.dataset\.tabId = String\(tabId\);/, `${label}: schedule form should retain its captured target tab`);
assert.match(panel, /form\.dataset\.composerId = `schedule-\$\{Date\.now\(\)\}-\$\{Math\.random\(\)\.toString\(36\)\.slice\(2\)\}`;/, `${label}: schedule form should tag its cached composer instance`);
assert.match(panel, /titleInput\.className = 'schedule-title'[\s\S]*?promptInput\.className = 'schedule-prompt'[\s\S]*?modeInput\.className = 'schedule-mode'/, `${label}: schedule form controls should have stable selectors for restore rebinding`);
@@ -42624,7 +42624,21 @@ test('sidepanel exposes schedule slash commands in both builds', () => {
assert.match(panel, /if \(currentTabId !== tabId\) \{[\s\S]*?replaceCachedScheduleComposer\(tabId, form\.dataset\.composerId, \{[\s\S]*?id: res\.jobId,[\s\S]*?scheduledAt: res\.scheduledAt,[\s\S]*?\}\);[\s\S]*?return;[\s\S]*?\}[\s\S]*?form\.remove\(\);[\s\S]*?renderScheduledJobCreatedMessage/, `${label}: schedule form should reconcile hidden and visible composer confirmations by job id`);
assert.match(panel, /catch \(err\) \{[\s\S]*?if \(currentTabId !== tabId\) \{[\s\S]*?updateCachedScheduleComposerError\(tabId, form\.dataset\.composerId, err\.message\);[\s\S]*?return;[\s\S]*?\}[\s\S]*?submit\.disabled = false;[\s\S]*?errorEl\.textContent = err\.message;/, `${label}: schedule form failures should update hidden cached composers instead of leaving disabled forms`);
assert.match(panel, /renderScheduleComposer\(payload, tabId\)/, `${label}: /schedule should pass the initiating tab into the async composer`);
- assert.match(panel, /urlInput\.value = initialScheduleUrl/, `${label}: schedule form should prefill URL targets from the active tab`);
+ assert.match(panel, /const targetUrl = scheduleUrlFromPrompt\(prefillPrompt\) \|\| initialScheduleUrl;\s*if \(isHttpScheduleUrl\(targetUrl\)\) \{\s*urlInput\.value = targetUrl;/, `${label}: schedule form should prefill URL targets from the prompt, else the active tab`);
+ {
+ const helpers = vm.createContext({ URL });
+ vm.runInContext(['isHttpScheduleUrl', 'scheduleUrlFromPrompt'].map(name => {
+ const start = panel.indexOf(`function ${name}(`);
+ return panel.slice(start, panel.indexOf('\n}\n', start) + 2);
+ }).join('\n'), helpers);
+ const pick = prompt => vm.runInContext(`scheduleUrlFromPrompt(${JSON.stringify(prompt)})`, helpers);
+ assert.equal(pick('Every 30 days, check https://example.com/ and tell me if it changed.'), 'https://example.com/');
+ assert.equal(pick('Open (https://example.com/a?b=1), then report.'), 'https://example.com/a?b=1');
+ assert.equal(pick('Compare https://a.example/ with https://b.example/'), '', `${label}: two addresses leave the target to the user`);
+ assert.equal(pick('Check https://example.com/ twice: https://example.com/'), 'https://example.com/');
+ assert.equal(pick('Check the open page.'), '');
+ assert.equal(pick('Run javascript:alert(1) on ftp://example.com'), '');
+ }
assert.match(panel, /targetType\.value = 'url'/, `${label}: schedule form should default http(s) pages to URL targets`);
assert.match(panel, /content\.appendChild\(form\)/, `${label}: schedule form should append after initial target defaults are applied`);
assert.match(locale, /'sp\.slash\.schedule':/, `${label}: /schedule description missing`);