Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Keep slash output visible during scheduled response streams
Barack Sokullubecd3acf7dda
diff --git a/src/chrome/src/ui/sidepanel.js b/src/chrome/src/ui/sidepanel.jsindex e59dd06ad..6b91aa1b2 100644--- a/src/chrome/src/ui/sidepanel.js+++ b/src/chrome/src/ui/sidepanel.js@@ -14677,12 +14677,13 @@ function scrollToBottom({ force = false, reveal = null } = {}) {// A forced jump deliberately takes the reader to the live edge (blocking// prompts, slash-command output, or the navigation pill). Keep subsequent// deltas visible until the reader scrolls upward again.- if (force && chatTurnIsConnected()) {+ if (force) {chatAutoFollow = true;chatUserChoseReadingPosition = false;}- if (!force && chatTurnIsConnected() && !chatAutoFollow- && (chatUserChoseReadingPosition || chatTurnIsRunning() || chatTurnNeedsReadingNavigation())) {+ if (!force && !chatAutoFollow+ && (chatUserChoseReadingPosition+ || (chatTurnIsConnected() && (chatTurnIsRunning() || chatTurnNeedsReadingNavigation())))) {scheduleChatNavigationUpdate();return;}@@ -14695,10 +14696,8 @@ function scrollToBottom({ force = false, reveal = null } = {}) {if (reveal?.isConnected&& reveal.getBoundingClientRect().top < container.getBoundingClientRect().top) {reveal.scrollIntoView({ block: 'nearest', behavior: 'instant' });- if (chatTurnIsConnected()) {- chatAutoFollow = false;- chatUserChoseReadingPosition = true;- }+ chatAutoFollow = false;+ chatUserChoseReadingPosition = true;}};pinAndReveal();@@ -14719,7 +14718,7 @@ chatContainerEl?.addEventListener('pointermove', (event) => {if (event.buttons) markChatUserScrollIntent();}, { passive: true });chatContainerEl?.addEventListener('scroll', () => {- if (chatTurnIsConnected() && chatUserScrollActive) {+ if ((chatTurnIsConnected() || chatUserChoseReadingPosition) && chatUserScrollActive) {const distanceToBottom = chatContainerEl.scrollHeight- chatContainerEl.scrollTop- chatContainerEl.clientHeight;diff --git a/src/firefox/src/ui/sidepanel.js b/src/firefox/src/ui/sidepanel.jsindex 12f2d1589..e574a73a1 100644--- a/src/firefox/src/ui/sidepanel.js+++ b/src/firefox/src/ui/sidepanel.js@@ -14297,12 +14297,13 @@ function scrollToBottom({ force = false, reveal = null } = {}) {// A forced jump deliberately takes the reader to the live edge (blocking// prompts, slash-command output, or the navigation pill). Keep subsequent// deltas visible until the reader scrolls upward again.- if (force && chatTurnIsConnected()) {+ if (force) {chatAutoFollow = true;chatUserChoseReadingPosition = false;}- if (!force && chatTurnIsConnected() && !chatAutoFollow- && (chatUserChoseReadingPosition || chatTurnIsRunning() || chatTurnNeedsReadingNavigation())) {+ if (!force && !chatAutoFollow+ && (chatUserChoseReadingPosition+ || (chatTurnIsConnected() && (chatTurnIsRunning() || chatTurnNeedsReadingNavigation())))) {scheduleChatNavigationUpdate();return;}@@ -14315,10 +14316,8 @@ function scrollToBottom({ force = false, reveal = null } = {}) {if (reveal?.isConnected&& reveal.getBoundingClientRect().top < container.getBoundingClientRect().top) {reveal.scrollIntoView({ block: 'nearest', behavior: 'instant' });- if (chatTurnIsConnected()) {- chatAutoFollow = false;- chatUserChoseReadingPosition = true;- }+ chatAutoFollow = false;+ chatUserChoseReadingPosition = true;}};pinAndReveal();@@ -14339,7 +14338,7 @@ chatContainerEl?.addEventListener('pointermove', (event) => {if (event.buttons) markChatUserScrollIntent();}, { passive: true });chatContainerEl?.addEventListener('scroll', () => {- if (chatTurnIsConnected() && chatUserScrollActive) {+ if ((chatTurnIsConnected() || chatUserChoseReadingPosition) && chatUserScrollActive) {const distanceToBottom = chatContainerEl.scrollHeight- chatContainerEl.scrollTop- chatContainerEl.clientHeight;diff --git a/test/run.js b/test/run.jsindex d5272daf9..f5f5ee2ec 100644--- a/test/run.js+++ b/test/run.js@@ -57642,7 +57642,7 @@ test('sidepanel auto-follow bypasses smooth-scroll lag while messages grow', ());assert.match(panel,- /function scrollToBottom\(\{ force = false, reveal = null \} = \{\}\) \{[\s\S]*?if \(force && chatTurnIsConnected\(\)\) \{[\s\S]*?chatAutoFollow = true;[\s\S]*?chatUserChoseReadingPosition = false;[\s\S]*?if \(!force && chatTurnIsConnected\(\) && !chatAutoFollow[\s\S]*?chatUserChoseReadingPosition \|\| chatTurnIsRunning\(\) \|\| chatTurnNeedsReadingNavigation\(\)[\s\S]*?pinChatToBottom\(container\);[\s\S]*?requestAnimationFrame\(\(\) => \{[\s\S]*?pinAndReveal\(\);[\s\S]*?\}\);[\s\S]*?\}/,+ /function scrollToBottom\(\{ force = false, reveal = null \} = \{\}\) \{[\s\S]*?if \(force\) \{[\s\S]*?chatAutoFollow = true;[\s\S]*?chatUserChoseReadingPosition = false;[\s\S]*?if \(!force && !chatAutoFollow[\s\S]*?chatUserChoseReadingPosition[\s\S]*?chatTurnIsConnected\(\) && \(chatTurnIsRunning\(\) \|\| chatTurnNeedsReadingNavigation\(\)[\s\S]*?pinChatToBottom\(container\);[\s\S]*?requestAnimationFrame\(\(\) => \{[\s\S]*?pinAndReveal\(\);[\s\S]*?\}\);[\s\S]*?\}/,`${label}: auto-follow should re-pin after the next layout frame`,);}diff --git a/test/slash-command-timeline-ui.mjs b/test/slash-command-timeline-ui.mjsindex 5a902c958..3d75a5084 100644--- a/test/slash-command-timeline-ui.mjs+++ b/test/slash-command-timeline-ui.mjs@@ -271,32 +271,52 @@ for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {assert.deepEqual(result, { complete: [...prefix, { role: 'assistant', text: 'Final assistant reply' }], incomplete: prefix });}));- await t.test('a slash response is revealed above a long in-flight answer without replacing the stream cursor', () => fixture(async page => {- const initial = await page.evaluate(async () => {- const cursor = currentAssistantEl.querySelector('.message-text');- cursor.innerHTML = Array.from({ length: 100 }, (_, i) => '<p>Streaming answer line ' + i + '</p>').join('');- streamedAssistantTextByEl.set(cursor, 'Original streaming state');- window.streamCursor = cursor;- await parseSlashCommands('/progress');- const card = currentAssistantEl.querySelector('.slash-command-output');- const rect = card.getBoundingClientRect(), viewport = transcript.getBoundingClientRect();- return { visible: rect.bottom > viewport.top && rect.top < viewport.bottom, sameCursor: currentAssistantEl.querySelector('.message-text') === cursor };- });- assert.deepEqual(initial, { visible: true, sameCursor: true });- await page.evaluate(() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))));- const afterFrame = await page.evaluate(() => {- scrollToBottom(); // Subsequent stream events must respect the revealed card.- const rect = currentAssistantEl.querySelector('.slash-command-output').getBoundingClientRect();- const viewport = transcript.getBoundingClientRect();- return {- visible: rect.bottom > viewport.top && rect.top < viewport.bottom,- stream: getStreamedAssistantText(streamCursor),- paragraphs: streamCursor.querySelectorAll('p').length,- reading: chatUserChoseReadingPosition && !chatAutoFollow,- };- });- assert.deepEqual(afterFrame, { visible: true, stream: 'Original streaming state', paragraphs: 100, reading: true });- }));+ for (const connectedTurn of [true, false]) {+ await t.test(`a slash response remains visible above a long ${connectedTurn ? 'connected' : 'scheduled'} answer until a forced jump`, () => fixture(async page => {+ const initial = await page.evaluate(async connected => {+ if (!connected) chatTurnIsConnected = () => false;+ const cursor = currentAssistantEl.querySelector('.message-text');+ cursor.innerHTML = Array.from({ length: 100 }, (_, i) => '<p>Streaming answer line ' + i + '</p>').join('');+ streamedAssistantTextByEl.set(cursor, 'Original streaming state');+ window.streamCursor = cursor;+ await parseSlashCommands('/progress');+ const card = currentAssistantEl.querySelector('.slash-command-output');+ const rect = card.getBoundingClientRect(), viewport = transcript.getBoundingClientRect();+ return { visible: rect.bottom > viewport.top && rect.top < viewport.bottom, sameCursor: currentAssistantEl.querySelector('.message-text') === cursor };+ }, connectedTurn);+ assert.deepEqual(initial, { visible: true, sameCursor: true });+ await page.evaluate(() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))));+ const afterFrame = await page.evaluate(() => {+ scrollToBottom(); // Subsequent stream events must respect the revealed card.+ const rect = currentAssistantEl.querySelector('.slash-command-output').getBoundingClientRect();+ const viewport = transcript.getBoundingClientRect();+ return {+ visible: rect.bottom > viewport.top && rect.top < viewport.bottom,+ stream: getStreamedAssistantText(streamCursor),+ paragraphs: streamCursor.querySelectorAll('p').length,+ reading: chatUserChoseReadingPosition && !chatAutoFollow,+ };+ });+ assert.deepEqual(afterFrame, { visible: true, stream: 'Original streaming state', paragraphs: 100, reading: true });+ const forced = await page.evaluate(() => {+ scrollToBottom({ force: true });+ return {+ following: chatAutoFollow && !chatUserChoseReadingPosition,+ atBottom: Math.abs(transcript.scrollHeight - transcript.clientHeight - transcript.scrollTop) < 2,+ };+ });+ assert.deepEqual(forced, { following: true, atBottom: true });+ await page.evaluate(() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))));+ const continued = await page.evaluate(() => {+ const next = document.createElement('p');+ next.textContent = 'Next streamed paragraph';+ streamCursor.appendChild(next);+ scrollToBottom();+ return Math.abs(transcript.scrollHeight - transcript.clientHeight - transcript.scrollTop) < 2;+ });+ assert.equal(continued, true, 'A forced jump resumes following subsequent output');+ }));+ }await t.test('Markdown export keeps inline system output and the final assistant reply distinct', () => fixture(async page => {const exported = await page.evaluate(async () => {