Skip to content

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

Schedule form: keep the chosen target and URL in markup so a restored composer shows them

Claude79d392c662c7
diff --git a/src/chrome/src/ui/sidepanel.js b/src/chrome/src/ui/sidepanel.js
index 542357726..6204bc56f 100644
--- a/src/chrome/src/ui/sidepanel.js
+++ b/src/chrome/src/ui/sidepanel.js
@@ -4555,6 +4555,18 @@ async function submitScheduleComposer(e, form) {
}
}
+// Live control values are not part of the markup a cached chat is rebuilt
+// from, so the target the form shows is also written to attributes.
+function syncScheduleTargetAttributes(form) {
+ const { targetType, urlInput } = getScheduleComposerControls(form);
+ if (!targetType || !urlInput) return;
+ urlInput.setAttribute('value', urlInput.value);
+ for (const option of targetType.options || []) {
+ if (option.value === targetType.value) option.setAttribute('selected', '');
+ else option.removeAttribute('selected');
+ }
+}
+
// The target follows the URL the prompt names until the person picks a target
// themselves; both live on the form so a restored composer keeps them.
function applyScheduleTarget(form, prompt) {
@@ -4569,6 +4581,7 @@ function applyScheduleTarget(form, prompt) {
targetType.value = 'current_tab';
}
updateScheduleComposerVisibility(form);
+ syncScheduleTargetAttributes(form);
}
function bindScheduleComposer(form) {
@@ -4580,8 +4593,12 @@ function bindScheduleComposer(form) {
targetType?.addEventListener('change', () => {
form.dataset.targetChosen = 'true';
updateScheduleComposerVisibility(form);
+ syncScheduleTargetAttributes(form);
+ });
+ urlInput?.addEventListener('input', () => {
+ form.dataset.targetChosen = 'true';
+ syncScheduleTargetAttributes(form);
});
- urlInput?.addEventListener('input', () => { form.dataset.targetChosen = 'true'; });
promptInput?.addEventListener('input', () => {
if (form.dataset.targetChosen !== 'true') applyScheduleTarget(form, promptInput.value);
});
diff --git a/src/firefox/src/ui/sidepanel.js b/src/firefox/src/ui/sidepanel.js
index 73927d824..f9ef59fdc 100644
--- a/src/firefox/src/ui/sidepanel.js
+++ b/src/firefox/src/ui/sidepanel.js
@@ -4419,6 +4419,18 @@ async function submitScheduleComposer(e, form) {
}
}
+// Live control values are not part of the markup a cached chat is rebuilt
+// from, so the target the form shows is also written to attributes.
+function syncScheduleTargetAttributes(form) {
+ const { targetType, urlInput } = getScheduleComposerControls(form);
+ if (!targetType || !urlInput) return;
+ urlInput.setAttribute('value', urlInput.value);
+ for (const option of targetType.options || []) {
+ if (option.value === targetType.value) option.setAttribute('selected', '');
+ else option.removeAttribute('selected');
+ }
+}
+
// The target follows the URL the prompt names until the person picks a target
// themselves; both live on the form so a restored composer keeps them.
function applyScheduleTarget(form, prompt) {
@@ -4433,6 +4445,7 @@ function applyScheduleTarget(form, prompt) {
targetType.value = 'current_tab';
}
updateScheduleComposerVisibility(form);
+ syncScheduleTargetAttributes(form);
}
function bindScheduleComposer(form) {
@@ -4444,8 +4457,12 @@ function bindScheduleComposer(form) {
targetType?.addEventListener('change', () => {
form.dataset.targetChosen = 'true';
updateScheduleComposerVisibility(form);
+ syncScheduleTargetAttributes(form);
+ });
+ urlInput?.addEventListener('input', () => {
+ form.dataset.targetChosen = 'true';
+ syncScheduleTargetAttributes(form);
});
- urlInput?.addEventListener('input', () => { form.dataset.targetChosen = 'true'; });
promptInput?.addEventListener('input', () => {
if (form.dataset.targetChosen !== 'true') applyScheduleTarget(form, promptInput.value);
});
diff --git a/test/run.js b/test/run.js
index 68f6fb6c2..61ebeb4df 100644
--- a/test/run.js
+++ b/test/run.js
@@ -42624,16 +42624,18 @@ 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, /function applyScheduleTarget\(form, prompt\) \{[\s\S]*?const targetUrl = scheduleUrlFromPrompt\(prompt\) \|\| form\.dataset\.initialUrl \|\| '';[\s\S]*?updateScheduleComposerVisibility\(form\);\s*\}/, `${label}: schedule form should pick URL targets from the prompt, else the active tab, and refresh the URL field's visibility`);
+ assert.match(panel, /function applyScheduleTarget\(form, prompt\) \{[\s\S]*?const targetUrl = scheduleUrlFromPrompt\(prompt\) \|\| form\.dataset\.initialUrl \|\| '';[\s\S]*?updateScheduleComposerVisibility\(form\);\s*syncScheduleTargetAttributes\(form\);\s*\}/, `${label}: schedule form should pick URL targets from the prompt, else the active tab, and refresh the URL field's visibility`);
assert.match(panel, /applyScheduleTarget\(form, prefillPrompt\);/, `${label}: the prefilled prompt sets the first target`);
assert.match(panel, /function bindScheduleComposer\(form\) \{[\s\S]*?promptInput\?\.addEventListener\('input', \(\) => \{\s*if \(form\.dataset\.targetChosen !== 'true'\) applyScheduleTarget\(form, promptInput\.value\);/, `${label}: an unchosen target follows the prompt as it is typed or edited, from the rebindable path`);
- assert.match(panel, /urlInput\?\.addEventListener\('input', \(\) => \{ form\.dataset\.targetChosen = 'true'; \}\);/, `${label}: a URL the person typed is not overwritten by the prompt`);
- assert.match(panel, /targetType\?\.addEventListener\('change', \(\) => \{\s*form\.dataset\.targetChosen = 'true';\s*updateScheduleComposerVisibility\(form\);/, `${label}: a target type the person picked is not overwritten by the prompt`);
+ assert.match(panel, /urlInput\?\.addEventListener\('input', \(\) => \{\s*form\.dataset\.targetChosen = 'true';\s*syncScheduleTargetAttributes\(form\);/, `${label}: a URL the person typed is not overwritten by the prompt, and survives a restore`);
+ assert.match(panel, /targetType\?\.addEventListener\('change', \(\) => \{\s*form\.dataset\.targetChosen = 'true';\s*updateScheduleComposerVisibility\(form\);\s*syncScheduleTargetAttributes\(form\);/, `${label}: a target type the person picked is not overwritten by the prompt`);
{
// The tracking runs against a form rebuilt from saved markup, too.
const fields = {};
+ const attrs = {};
const field = (name, value = '') => ({
value, hidden: false,
+ setAttribute: (k, v) => { attrs[`${name}.${k}`] = v; }, removeAttribute() {},
closest: () => ({ classList: { toggle: (_c, on) => { fields[name].hidden = on; } } }),
});
for (const name of ['title', 'prompt', 'type', 'timeMode', 'after', 'runAt', 'interval', 'target', 'url', 'mode']) fields[name] = field(name);
@@ -42642,7 +42644,7 @@ test('sidepanel exposes schedule slash commands in both builds', () => {
const selectors = { '.schedule-target-type': 'target', '.schedule-url': 'url', '.schedule-type': 'type', '.schedule-time-mode': 'timeMode', '.schedule-after': 'after', '.schedule-run-at': 'runAt', '.schedule-interval': 'interval', '.schedule-prompt': 'prompt' };
const form = { dataset: { initialUrl: '' }, querySelector: sel => fields[selectors[sel]] || null };
const env = vm.createContext({ URL });
- vm.runInContext(['isHttpScheduleUrl', 'trimScheduleUrlProse', 'scheduleUrlFromPrompt', 'getScheduleComposerControls', 'updateScheduleComposerVisibility', 'applyScheduleTarget'].map(name => {
+ vm.runInContext(['isHttpScheduleUrl', 'trimScheduleUrlProse', 'scheduleUrlFromPrompt', 'getScheduleComposerControls', 'updateScheduleComposerVisibility', 'syncScheduleTargetAttributes', 'applyScheduleTarget'].map(name => {
const start = panel.indexOf(`function ${name}(`);
return panel.slice(start, panel.indexOf('\n}\n', start) + 2);
}).join('\n'), env);
@@ -42651,6 +42653,7 @@ test('sidepanel exposes schedule slash commands in both builds', () => {
assert.equal(fields.url.value, 'https://example.com/a');
assert.equal(fields.target.value, 'url');
assert.equal(fields.url.hidden, false, `${label}: an automatically chosen URL target shows its URL field`);
+ assert.equal(attrs['url.value'], 'https://example.com/a', `${label}: the chosen URL is kept in markup for a restored composer`);
vm.runInContext(`applyScheduleTarget(form, 'Check the open page.')`, env);
assert.equal(fields.target.value, 'current_tab');
assert.equal(fields.url.hidden, true);