Skip to content

Commit fc5e8b6

Browse files
Fix/scroll scroll to end (#555)
* fix not scrolling to end of page * changeset
1 parent dd9457e commit fc5e8b6

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

Diff for: .changeset/healthy-buttons-sell.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": patch
3+
---
4+
5+
fix issue where processAllOfDom doesnt scroll to end of page when there is dynamic content

Diff for: evals/tasks/extract_snowshoeing_destinations.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const extract_snowshoeing_destinations: EvalFunction = async ({
1919
"https://www.cbisland.com/blog/10-snowshoeing-adventures-on-cape-breton-island/",
2020
);
2121

22-
await stagehand.page.act({ action: "reject the cookies" });
22+
await stagehand.page.act({ action: "accept the cookies" });
2323

2424
const snowshoeing_regions = await stagehand.page.extract({
2525
instruction:

Diff for: lib/dom/StagehandContainer.ts

+19-3
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ export abstract class StagehandContainer {
7575
candidateContainer?: HTMLElement,
7676
): Promise<DomChunk[]> {
7777
const chunks: DomChunk[] = [];
78-
const maxOffset = this.getScrollHeight();
79-
const finalEnd = Math.min(endOffset, maxOffset);
78+
let maxOffset = this.getScrollHeight();
79+
let current = startOffset;
80+
let finalEnd = endOffset;
81+
8082
let index = 0;
8183

82-
for (let current = startOffset; current <= finalEnd; current += chunkSize) {
84+
while (current <= finalEnd) {
8385
// Move the container's scroll position
8486
if (scrollTo) {
8587
await this.scrollTo(current);
@@ -101,6 +103,20 @@ export abstract class StagehandContainer {
101103
});
102104

103105
index += Object.keys(selectorMap).length;
106+
current += chunkSize;
107+
108+
// Only extend finalEnd if there is no candidateContainer
109+
// (meaning we're looking at the entire scrollable area)
110+
if (!candidateContainer && current > endOffset) {
111+
// Check if new content extended the scroll height
112+
const newScrollHeight = this.getScrollHeight();
113+
if (newScrollHeight > maxOffset) {
114+
maxOffset = newScrollHeight;
115+
}
116+
if (newScrollHeight > finalEnd) {
117+
finalEnd = newScrollHeight;
118+
}
119+
}
104120
}
105121

106122
if (scrollBackToTop) {

0 commit comments

Comments
 (0)