question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scroll listeners can make click events unreliable

See original GitHub issue

Steps to reproduce

Tell us about your environment:

Puppeteer version: 1.12.2 Platform / OS version: Windows 10 URLs: Enterprise Domain so I can’t share 😢 Node.js version: v8.12.0

What steps will reproduce the problem?

  1. Be on any page with a significant scroll listener.
  2. await element.click(options).
  3. Click event might not fire, or at least not before a different function runs and moves the scrollbar again.

What is the expected result?

I mean, it’s understandable that the click event doesn’t fire some time (or, again, just doesn’t run in a timely manner), but as things are now, we need some way to be able to do some logic to wait for the page to stabilize between the scroll event and the click event.

For example, using a private property on the element handler can fix this (this is actually what I’m doing in the meantime, while I wait for an alternative):

export default async function safeClick(elHandle = ctx.page, ...args) {
    // an actual private function in the puppeteer api while researching this bug
    await elHandle._scrollIntoViewIfNeeded();
    await myCheckStabilizationFunction();
    await expect(elHandle).toClick(...args);
}

What happens instead?

I have no way to insert stabilization logic between puppeteer attempting to scroll the page and attempting to click the element.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Aaron-Poolcommented, Mar 16, 2019

@aslushnikov I’m not entirely sure that’s true.

I’m writing e2e acceptance test scripts for a web application. I don’t so much care about performance, as much as the highest possible reliability and adaptability to changing conditions such as server speed, dom restructuring, implementation changes, etc. To do this I have a wrapper function for all browser interactions that ensures the page is totally stable before attempting the operation, to ensure the operation occurs as expected. But I’m also recording all of these tests so that, if any of the QA engineers have concerns about a false negative or positive, they can watch the test and skip to the relevant portion.

That being said, if the screen is repeatedly jumping around unnecessarily because I called scrollIntoView on every user interaction, it will make it more difficult to understand what’s happening.

I understand this isn’t really your problem, or anything you’re responsible to fix. Just explaining the circumstance that makes manually calling _scrollIntoViewIfNeeded desirable.

0reactions
aslushnikovcommented, Apr 5, 2019

That being said, if the screen is repeatedly jumping around unnecessarily because I called scrollIntoView on every user interaction, it will make it more difficult to understand what’s happening.

@Aaron-Pool makes perfect sense. I’d steal our implementation then to make sure it doesn’t disappear from the private API (there are no plans though).

Let’s postpone exposing _scrollIntoViewIfNeeded to public API until there are more requests.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scroll listeners can make click events unreliable #4135
I was operating under the assumption that puppeteer implemented its own scrollIntoViewIfNeeded with an intersection observer because the ...
Read more >
How to remove scroll event listener?
What I am trying to do is call a click event when some elements are in a viewport. The problem is that the...
Read more >
Setting up JavaScript event listeners, with 2 examples ...
The 'scroll' event listener type is triggered when the document view or an element has been scrolled. Let's take a look at this...
Read more >
Document: scroll event - Web APIs - MDN Web Docs - Mozilla
The scroll event fires when the document view has been scrolled. To detect when scrolling has completed, see the Document: scrollend event.
Read more >
Working with events | Guide | ArcGIS API for JavaScript 3.42
Events occur when you interact with a JavaScript application. Loading the page, clicking the mouse, executing a task, and many other actions all...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found