Skip to content

[Bug]: ElementHandle.click() Doesn't scroll to the center of the element #14018

@moddpc

Description

@moddpc

Minimal, reproducible example

import puppeteer from 'puppeteer'

const browser = await puppeteer.launch({headless: false})
const page = await browser.newPage()

await page.setContent(
    '<div name="scrollContainer" style="width: 150px;height: 200px;background-color: blanchedalmond;position: relative;overflow: auto;"><div style="margin: 30px; width: 600px;height: 75px;background-color: blueviolet;position: relative" id="element1"></div><div style="margin: 30px; width: 600px;height: 75px;background-color: blueviolet;position: relative" id="element2"></div></div>'
)

const handle = await page.waitForSelector('#element2')

await handle.click()

Background

No response

Expectation

the center of the element is outside the scroll container

Reality

By default, new versions of puppeteer use client.send('DOM.scrollIntoViewIfNeeded', {objectId: this.id}) to autoscroll to an element, but this differs from the previously used method element.scrollIntoView({block: 'center',inline: 'center',behavior: 'instant'}) - the method does not scroll to the center of the element and when trying to click on the element - the click occurs outside the scroll container

Puppeteer configuration file (if used)

Puppeteer version

24.11.2

Node version

v20.18.3

Package manager

npm

Package manager version

10.8.2

Operating system

Linux

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions