Puppeteer Chromium - Error: Failed to launch the browser process when ssh session is not active on server

When calling puppeteer.launch in nodejs

Error: Failed to launch the browser process!

cmd_run.go:1285: WARNING: cannot start document portal: dial unix /run/user/1000/bus: connect: no such file or directory

/system.slice/pm2-ubuntu.service is not a snap cgroup

I am trying to load a webpage in puppeter and generate pdf. but when ssh session is active it is working perfectly fine and when ssh is inactive the error is thrown after a few successfull generation of pdfs.

Is there anyone who have faced this issue.

const browser = await puppeteer.launch({
                headless: "new", userDataDir: "./tmp/" + randomUid, executablePath: process.env.CHROMIUM_URL,
                args: ['--disable-features=IsolateOrigins',
                    '--disable-site-isolation-trials',
                    '--autoplay-policy=user-gesture-required',
                    '--disable-background-networking',
                    '--disable-background-timer-throttling',
                    '--disable-backgrounding-occluded-windows',
                    '--disable-breakpad',
                    '--disable-client-side-phishing-detection',
                    '--disable-component-update',
                    '--disable-default-apps',
                    '--disable-dev-shm-usage',
                    '--disable-domain-reliability',
                    '--disable-extensions',
                    '--disable-features=AudioServiceOutOfProcess',
                    '--disable-hang-monitor',
                    '--disable-ipc-flooding-protection',
                    '--disable-notifications',
                    '--disable-offer-store-unmasked-wallet-cards',
                    '--disable-popup-blocking',
                    '--disable-print-preview',
                    '--disable-prompt-on-repost',
                    '--disable-renderer-backgrounding',
                    '--disable-setuid-sandbox',
                    '--disable-speech-api',
                    '--disable-software-rasterizer',
                    '--disable-sync',
                    '--hide-scrollbars',
                    '--ignore-gpu-blacklist',
                    '--metrics-recording-only',
                    '--mute-audio',
                    '--no-default-browser-check',
                    '--no-first-run',
                    '--no-pings',
                    '--no-sandbox',
                    '--no-zygote',
                    '--password-store=basic',
                    '--use-gl=swiftshader',
                    '--use-mock-keychain']
            });