-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scroll on 'main scrollable element' when possible #405
base: main
Are you sure you want to change the base?
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
biggest thing is we probably need one unified abstract class called StagehandContainer
that implements methods like getHeight()
, scrollTo()
, etc.
great work here, but these if
statements aren't really sustainable as we keep adding to this kind of workflow
|
||
await stagehand.close(); | ||
const listings = real_estate_listings.listings; | ||
const expectedLength = 38; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we sure this is fixed? this doesn't seem sustainable
@@ -19,7 +19,10 @@ declare global { | |||
}>; | |||
debugDom: () => Promise<void>; | |||
cleanupDebug: () => void; | |||
scrollToHeight: (height: number) => Promise<void>; | |||
scrollToHeight: ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we make this serialized json
let mainScrollable: HTMLElement = document.documentElement; | ||
let maxScrollableArea = 0; | ||
|
||
// Find the largest candidate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this is basically just getting literally the biggest element and marking that main? using this approach should totally be opt-in; i feel like this can get funky super fast
// Verify we can actually scroll that candidate | ||
if (mainScrollable !== document.documentElement) { | ||
if (!canElementScroll(mainScrollable)) { | ||
console.log( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
future note: we should consolidate DOM logs to a window.log
function
export async function scrollToHeight(height: number) { | ||
window.scrollTo({ top: height, left: 0, behavior: "smooth" }); | ||
export async function scrollToHeight( | ||
containerOrWindow: HTMLElement | Window, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's name this differently and make it a custom type as well -- something like mainContainer: StagehandContainer
, where StagehandContainer
is HTMLElement | Window
.
that way you can just do something like mainContainer.scrollTo({ top: height, left: 0, behavior: "smooth" })
without all these if else statements
clearTimeout(scrollEndTimer); | ||
scrollEndTimer = window.setTimeout(() => { | ||
window.removeEventListener("scroll", handleScrollEnd); | ||
if (containerOrWindow instanceof Window) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not be an if statement; this should be one method
window.addEventListener("scroll", handleScrollEnd, { passive: true }); | ||
handleScrollEnd(); | ||
if (containerOrWindow instanceof Window) { | ||
containerOrWindow.addEventListener("scroll", handleScroll, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should also not be in an if statement
let viewportHeight: number; | ||
let totalScrollHeight: number; | ||
|
||
if (container instanceof Window) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not an if statement
why
examples
Zillow:
apartments.com
what changed
processAllOfDom
to attempt scrolling on a large scrollable container, and fall back to the original approach (scrolling on the root DOM) if there are no large scrollable containersimportant note
processAllOfDom
processDom
to enableact
to take actions on elements that are positioned deep within a scrollable containertest plan