How can I simulate realistic mobile swipe scrolling in Puppeteer?

How can I trigger natural mobile swipe scrolling in Puppeteer? I tried touchscreen functions, but they don’t mimic real finger gestures as expected.

const puppLib = require('puppeteer-extra');
const { KnownDevices } = require('puppeteer');
const mobileDevice = KnownDevices['iPhone 14 Pro'];

(async function simulateSwipe() {
  const browserHandle = await puppLib.launch({
    headless: false,
    defaultViewport: { width: 375, height: 667, isMobile: true }
  });
  const pageHandle = await browserHandle.newPage();
  await pageHandle.emulate(mobileDevice);
  await pageHandle.goto('https://example.com', { waitUntil: 'domcontentloaded' });

  await pageHandle.touchscreen.touchStart(10, 10);
  await pageHandle.touchscreen.touchMove(25, 25);
  await pageHandle.touchscreen.touchEnd();
})();

I have found that the direct approach, using touchStart, touchMove, and touchEnd consecutively, does not quite capture the nuances of a human swipe gesture. In my case, introducing subtle increments with deliberate delays between each phase improved the fidelity of the simulation. By gradually increasing the coordinate values and mimicking the slight variations in speed and pressure of a natural swipe, I was able to create a smoother, more realistic scrolling behavior. Testing on different devices also helped ensure the adjustments are generally applicable.

I encountered a similar issue when trying to replicate realistic mobile swipe behavior. Using Puppeteer’s touchscreen functions, I found that simply sending touchStart, touchMove, and touchEnd in sequence did not result in a gesture that felt natural on the screen. My approach involved injecting a custom script using page.evaluate to dispatch native touch events with more granular control over the timing and movement curve. This allowed me to simulate a continuous and smoother swipe by interpolating coordinates between the start and end points, ultimately enhancing the realism.