Skip to content

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

fix(selection): preserve answer edge whitespace

Emre Sokullu32207b1309e9
diff --git a/src/chrome/src/content/selection-shortcut.js b/src/chrome/src/content/selection-shortcut.js
index 4cb18d511..e8fb5c98b 100644
--- a/src/chrome/src/content/selection-shortcut.js
+++ b/src/chrome/src/content/selection-shortcut.js
@@ -1063,12 +1063,12 @@
});
if (requestId !== cardRequestId || !cardState) return;
cardJobId = '';
- let answer = typeof response?.text === 'string' ? response.text.trim() : '';
+ let answer = typeof response?.text === 'string' ? response.text : '';
cardState.truncated = response?.truncated === true;
// This also applies to a textless cut-off, where it warns that continuing
// in the panel would be blocked by the exhausted allowance.
cardState.notice = typeof response?.notice === 'string' ? response.notice.slice(0, 300) : '';
- if (!response?.ok || !answer) {
+ if (!response?.ok || !answer.trim()) {
throw new Error(typeof response?.error === 'string' && !cardState.truncated ? response.error : '');
}
if (answer.length > INLINE_ANSWER_MAX_CHARS) {
diff --git a/src/firefox/src/content/selection-shortcut.js b/src/firefox/src/content/selection-shortcut.js
index 9c7c9e6d5..64cbaeafa 100644
--- a/src/firefox/src/content/selection-shortcut.js
+++ b/src/firefox/src/content/selection-shortcut.js
@@ -1063,12 +1063,12 @@
});
if (requestId !== cardRequestId || !cardState) return;
cardJobId = '';
- let answer = typeof response?.text === 'string' ? response.text.trim() : '';
+ let answer = typeof response?.text === 'string' ? response.text : '';
cardState.truncated = response?.truncated === true;
// This also applies to a textless cut-off, where it warns that continuing
// in the sidebar would be blocked by the exhausted allowance.
cardState.notice = typeof response?.notice === 'string' ? response.notice.slice(0, 300) : '';
- if (!response?.ok || !answer) {
+ if (!response?.ok || !answer.trim()) {
throw new Error(typeof response?.error === 'string' && !cardState.truncated ? response.error : '');
}
if (answer.length > INLINE_ANSWER_MAX_CHARS) {
diff --git a/test/fixtures/run.mjs b/test/fixtures/run.mjs
index 4b7e501de..7e3f66cad 100644
--- a/test/fixtures/run.mjs
+++ b/test/fixtures/run.mjs
@@ -2207,7 +2207,7 @@ for (const [label, sourcePath, manualOpen] of [
test(`${label}: Proofread preserves whitespace-sensitive corrections`, async (page) => {
await setupSelectionShortcut(page, sourcePath, { requiresManualOpen: manualOpen });
- const correction = 'def example():\n return {\n "answer": 42,\n }';
+ const correction = ' def example():\n return {\n "answer": 42,\n }\n';
await page.evaluate((text) => {
window.__selectionInlineHandler = async () => ({ ok: true, text });
}, correction);