puppeteer detach CDP sessions safely for page.close()

I have this code snipper I use with puppeteer to create CDP session.

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
                        });

when I use page.close() as the scroll is happening, the whole program crashes with

node_modulespuppeteer-corelibcjspuppeteercommonCallbackRegistry.js:73
            this._reject(callback, new Errors_js_1.TargetCloseError('Target closed'));
                                   ^

TargetCloseError: Protocol error (Input.synthesizeScrollGesture): Target closed
    at CallbackRegistry.clear 

or this error

cdpCDPSession.js:64
            return Promise.reject(new Errors_js_1.TargetCloseError(`Protocol error (${method}): Session closed. Most likely the ${this.#targetType} has been closed.`));
                                  ^

TargetCloseError: Protocol error (Network.getCookies): Session closed. Most likely the page has been closed.
    at CdpCDPSession.send (

I have no way to prevent this, please help. I want to detach safely and close the page safely.

Indeed the real question is how to page.close() safely without crash ?