Page.mouse.move() doesn't work in headless mode?
See original GitHub issue- Puppeteer version: 1.18.1
- Platform / OS version: Win64
- URLs (if applicable): -
- Node.js version: 8.11.2
What steps will reproduce the problem?
I am testing a tooltip plugin for webpages. In one of the cases the tooltip should follow the cursor/mouse moves along x-axis. My plugin tracks the mouse moves and then moves the tooltip accordingly. It works with headless: false
, I see all that in action. But when I switch to headless mode it seems that moves don’t happen and the tooltip position remains the same.
await page.goto(url);
await page.waitForSelector(".example5 a"); // it's the element around which the tooltip will appear
await page.hover(".example5 a");
let initialTtPosLeft = parseFloat(await page.evaluate(() => document.querySelector(".example5 span.js-tooltiper").style.left)); // I take initial tooltip left pos.
let link = await page.$('.example5 a'); // I take element's coords to use them to move the mouse later
let linkPos = await page.evaluate((link) => {
const {top, left} = link.getBoundingClientRect();
return {top, left};
}, link);
await page.mouse.move(linkPos.left + 5, linkPos.top + 5); // I move the mouse over the element. +5 just to not go beyond element's limits.
let finalTtPosLeft = parseFloat(await page.evaluate(() => document.querySelector(".example5 span.js-tooltiper").style.left)); // I take again tooltip's left pos
assert.notEqual(initialTtPosLeft, finalTtPosLeft); // In headless mode they are equal as if mouse.move didn't happen
What is the expected result?
The mouse moves and triggers the tooltip moving.
What happens instead?
Seems that in headless mode it doesn’t happen since the tooltip position remains the same.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Is there a way to control the mouse wheel in headless browser
My understanding is that the mouse wheel control is done via positioning on the screen which when it is used in headless mode...
Read more >Web Scraping with a Headless Browser: A Puppeteer Tutorial
In this article, Toptal Freelance JavaScript Developer Nick Chikovani shows how easy it is to perform web scraping using a headless browser.
Read more >Mouse actions - Selenium
This method combines moving the mouse to the center of an element with ... This approach does not work correctly when the element...
Read more >Mouse Hover action in Selenium Webdriver - Tools QA
This explains the different techniques to Mouse hover on a WebElement or on drop down menus using Action Class in Java with Selenium ......
Read more >Avoid Puppeteer or Playwright for Web Scraping
NOTE Headless mode doesn't support navigation to a PDF document. ... keyboard and mouse interaction functionality such as page.click() or ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I encounter the same problem that I simulate a drag event with page.mouse.down() and page.mouse.move() and page.mouse.up(). It’s work in {headless: false} mode but not in the {headless: true} mode… I spent the whole day and figure out that add
page.setViewport({ width: xxx, height: xxx });
before simulating the mouse event will solve my problem.We are closing this issue. If the issue still persists in the latest version of Puppeteer, please reopen the issue and update the description. We will try our best to accomodate it!