I’m using Puppeteer and creating a CDP (Chrome DevTools Protocol) session with page.target().createCDPSession() to simulate user gestures.
let browser = await puppeteer.launch(options);
const page = await browser.newPage();
const session = await page.target().createCDPSession();
await session.send('Input.synthesizeScrollGesture', {
x: 100,
y: 200,
yDistance: -150
});
The issue: if I call page.close() while the scroll gesture or any CDP command is still running, Puppeteer crashes with errors like:
TargetCloseError: Protocol error (Input.synthesizeScrollGesture): Target closed
I’m looking for a safe way to detach or clean up CDP sessions before closing the page to prevent these errors.
Has anyone figured out a reliable method or sequence to gracefully end CDP sessions before calling page.close() when using puppeteer.createCDPSession?