Question
Answer (51)
Is there an existing issue for this?
- [ ] I have searched the existing issues.
Is this a problem caused by your code, or is it specifically because of the library?
- [x] I have double-checked my code carefully.
Describe the bug.
Hello, I have the following issue: I activate the bot and save the session. I want to reload the bot from the session when the server is restarted, but I get this error:
Error initialize client:Failed to launch the browser process: Code: 21
stderr:
[14:14:0130/094243.901492:ERROR:chrome/browser/process_singleton_posix.cc:363] The profile appears to be in use by another Chromium process (140) on another computer (034287356bb6). Chromium has locked the profile so that it doesn't get corrupted. If you are sure no other processes are using this profile, you can unlock the profile and relaunch Chromium.
[14:14:0130/094243.909525:ERROR:chrome/browser/ui/views/message_box_dialog.cc:199] Unable to show message box: Google Chrome for Testing - The profile appears to be in use by another Chromium process (140) on another computer (034287356bb6). Chromium has locked the profile so that it doesn't get corrupted. If you are sure no other processes are using this profile, you can unlock the profile and relaunch Chromium.
Expected Behavior
I expect to be able to reuse the same session without having to activate the bot again.
Steps to Reproduce the Bug or Issue
This is my function for restore bot after the server is started:
function restoreBots() { const sessionsDir = path.join(__dirname, 'sessions'); if (!fs.existsSync(sessionsDir)) return;
const folders = fs.readdirSync(sessionsDir).filter(folder => folder.startsWith('session-'));
folders.forEach(folder => {
const botId = folder.replace('session-', '');
createBot(botId, null, null)
.catch(err => console.error(`❌ Failed to restore bot ${botId}:`, err.message));
});
}
WhatsApp Account Type
Standard
Browser Type
Chromium
Operation System Type
Linux | Docker + Debian
Phone OS Type
Android
WhatsApp-Web.js Version
github:timothydillan/whatsapp-web.js#fix/duplicate-events-and-bindings
WhatsApp Web Version
github:timothydillan/whatsapp-web.js#fix/duplicate-events-and-bindings
Node.js Version
v20.20.0
Authentication Strategy
LocalAuth
Additional Context
No response
Answer:
Based on the information provided, it seems that the issue is caused by the Chromium browser process still being active from a previous session. When trying to restore the bot, the script is encountering an error because the Chromium profile is locked and in use by another process.
Solution:
To resolve this issue, you can try the following steps:
-
Stop all running Chromium processes: You can use the
pgrepcommand to find and kill all running Chromium processes.sudo pgrep chromium | xargs kill -9Note that using
kill -9forcefully terminates the process and may cause data loss if the process was in the middle of writing to a file. -
Delete the Chromium profile directory: You can delete the Chromium profile directory to allow the script to create a new one.
sudo rm -rf /home/<username>/.config/chromiumReplace
<username>with the actual username of the user running the script. -
Restart the bot: After deleting the Chromium profile directory, try restarting the bot again. The script should now be able to create a new profile and launch the Chromium browser process without encountering the error.
Expected Behavior:
The script should be able to restore the bot from a saved session without having to activate it again.
Steps to Reproduce the Issue:
The issue can be reproduced by saving a bot session and then trying to restore it after the server is restarted. The error message indicates that the Chromium profile is still in use by another process.
Additional Context:
To prevent this issue from happening in the future, you can modify the script to check if the Chromium process is already running before trying to launch a new one. You can use the pgrep command to check for running Chromium processes and exit the script if one is already running. This will prevent multiple instances of the Chromium browser from launching at the same time.