Skip to content
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

Feature request: x-scroll header #151

Open
mb21 opened this issue Nov 4, 2024 · 2 comments
Open

Feature request: x-scroll header #151

mb21 opened this issue Nov 4, 2024 · 2 comments

Comments

@mb21
Copy link

mb21 commented Nov 4, 2024

We already have the x-timeout header, which works for a lot of javascript-heavy websites. But some websites lazy-load certain things only when you scroll down a bit.

Therefore, I propose an x-scroll header, which would basically execute the following js after the page finished loading:

window.scrollTo({
  top: document.body.scrollHeight,
  behavior: "smooth",
})

(Pretty sure, 'smooth' scrolling triggers any IntersectionObservers in-between the top and the bottom of the page.)

And as soon as that's done and the event loop is empty, execute it again. As many times until either scrolling down doesn't expand the pages height anymore, or x-timeout is reached.

@nomagick
Copy link
Member

We have introduced a script injection mechanism to our API.
Also inside the page, we provide these utility functions/event:

- waitForSelector(selector: string): Promise<HTMLElement> 
  waits for the selector to appear in the DOM
- simulateScroll(): void 
  simulates scrolling to the bottom of the page to trigger lazyload elements
- "mutationIdle" event on document 
  fires when the DOM mutation is idle in 200ms

See #150 for example

@mb21
Copy link
Author

mb21 commented Nov 13, 2024

Thanks! Seems curl ... --data-urlencode 'injectPageScript=document.addEventListener("mutationIdle", window.simulateScroll);' should indeed work for this, I'll give it a try. Feel free to close this issue then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants