Skip to content

Commit 5f1868b

Browse files
fix for targetted extract (#554)
* fix scrollIntoView * dont use boundingClientRect to determine when we should chunk * changeset
1 parent cf7fe66 commit 5f1868b

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

Diff for: .changeset/great-lizards-yell.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@browserbasehq/stagehand": patch
3+
---
4+
5+
fix targetted extract issue with scrollintoview and not chunking correctly

Diff for: lib/dom/ElementContainer.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export class ElementContainer extends StagehandContainer {
5151
* @returns A promise that resolves once scrolling is finished.
5252
*/
5353
public async scrollTo(offset: number): Promise<void> {
54+
await new Promise((resolve) => setTimeout(resolve, 1500));
5455
this.el.scrollTo({ top: offset, behavior: "smooth" });
5556
await this.waitForScrollEnd();
5657
}
@@ -67,7 +68,7 @@ export class ElementContainer extends StagehandContainer {
6768
if (!element) {
6869
this.el.scrollTo({ top: 0, behavior: "smooth" });
6970
} else {
70-
element.scrollIntoView({ behavior: "smooth", block: "end" });
71+
element.scrollIntoView();
7172
}
7273
await this.waitForScrollEnd();
7374
}

Diff for: lib/dom/process.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,10 @@ export async function processAllOfDom(xpath?: string) {
190190

191191
// Now check if the element “fits” in the container’s viewport
192192
const scrollTargetHeight = scrollTarget.getViewportHeight();
193-
const rect = candidateElementContainer.getBoundingClientRect();
193+
const candidateElementContainerHeight =
194+
candidateElementContainer.scrollHeight;
194195

195-
if (rect.height <= scrollTargetHeight) {
196+
if (candidateElementContainerHeight <= scrollTargetHeight) {
196197
// Single-chunk approach
197198
console.log(
198199
"Element is smaller/equal to container’s viewport. Doing single chunk.",
@@ -235,7 +236,7 @@ export async function processAllOfDom(xpath?: string) {
235236
const startOffset = scrollTarget.getScrollPosition();
236237
const viewportHeight = scrollTarget.getViewportHeight();
237238
const maxScroll = candidateElementContainer
238-
? startOffset + candidateElementContainer.getBoundingClientRect().height
239+
? startOffset + candidateElementContainer.scrollHeight
239240
: scrollTarget.getScrollHeight();
240241
const chunkSize = viewportHeight;
241242

0 commit comments

Comments
 (0)