There is a code in the index.js file:
const { Client, LocalAuth } = require('whatsapp-web.js');const qrcode = require('qrcode-terminal');(async () => { console.log('Starting browser launch...'); try { const client = new Client({ puppeteer: { executablePath: '/usr/bin/google-chrome', headless: true, args: ['--no-sandbox','--disable-setuid-sandbox','--disable-web-security','--ignore-certificate-errors','--disable-gpu','--disable-dev-shm-usage','--remote-debugging-port=9222','--disable-software-rasterizer' ], ignoreHTTPSErrors: true, dumpio: true }, authStrategy: new LocalAuth({ clientId: 'exampleSession' }), }); client.on('qr', (qr) => { console.log('QR Code received.'); qrcode.generate(qr, { small: true }); }); client.on('error', (error) => { console.error('Client error:', error); }); await client.initialize(); console.log('WhatsApp client initialized.'); await new Promise(resolve => setTimeout(resolve, 60000)); await browser.close(); console.log('Browser closed.'); } catch (error) { console.error('An error occurred:', error); }})();
When running on Ubuntu 22 with the command:
xvfb-run -a -s "-screen 0 1024x768x24" node index.js
Everything works as it should, but when running the same file from the python code:
import threadingimport subprocessdef start_node_script(): global process command = ['xvfb-run', '-a', '-s', '-screen 0 1024x768x24', 'node', 'index.js'] # Start process Node.js process = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, bufsize=1, ) # Reading output in a separate thread threading.Thread(target=read_process_output, args=(process,), daemon=True).start() log("Node.js script started", session="server") return jsonify({"message": "Node.js script started"})
I'm getting an error:
An error occurred: Error: net::ERR_INVALID_AUTH_CREDENTIALS at https://web.whatsapp.com
What could this be related to, where to look and what are the options for fixing the problem?
I was running the file from the console and everything worked as it should. But I don't understand what dependencies need to be passed when running index.js from a python file.