Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How To Clear Chromium Data Safely? #1986

Closed
1 task done
rendyep opened this issue Feb 8, 2023 · 4 comments
Closed
1 task done

How To Clear Chromium Data Safely? #1986

rendyep opened this issue Feb 8, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@rendyep
Copy link

rendyep commented Feb 8, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have 2 running clients simultaneously. After some days (around 3 or 4 days), chromium data takes around 600 MB of disk space. Is there a way to clear the data safely without removing the session part so I don't have to re-login by scanning QR code again when I restart the clients?

I have tried to remove the PATH/TO/session/Default/Cache after stopping the process, but when I started again, it triggered error:

Feb 09 01:49:03 Nenosaurus systemd[1]: Started Whatsapp API Client.
Feb 09 01:49:04 Nenosaurus node[398266]: [2023-02-08T18:49:04.901Z][info] App is listening on 127.0.0.1:1802
Feb 09 01:49:08 Nenosaurus node[398266]: [2023-02-08T18:49:08.173Z][info][[email protected]] Loading screen... 0%
Feb 09 01:49:08 Nenosaurus node[398266]: [2023-02-08T18:49:08.644Z][info][[email protected]] Loading screen... 0%
Feb 09 01:49:25 Nenosaurus node[398266]: [2023-02-08T18:49:25.427Z][info][[email protected]] Screen loaded
Feb 09 01:49:25 Nenosaurus node[398266]: [2023-02-08T18:49:25.769Z][info][[email protected]] Screen loaded
Feb 09 01:49:36 Nenosaurus node[398266]: [2023-02-08T18:49:36.661Z][info][[email protected]] Client authenticated
Feb 09 01:49:37 Nenosaurus node[398266]: /home/rendyep/apps/whatsapp-api-client/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:221
Feb 09 01:49:37 Nenosaurus node[398266]:             throw new Error('Evaluation failed: ' + helper_js_1.helper.getExceptionMessage(exceptionDetails));
Feb 09 01:49:37 Nenosaurus node[398266]:                   ^
Feb 09 01:49:37 Nenosaurus node[398266]: Error: Evaluation failed: TypeError: Cannot read properties of undefined (reading 'queryExists')
Feb 09 01:49:37 Nenosaurus node[398266]:     at __puppeteer_evaluation_script__:25:69
Feb 09 01:49:37 Nenosaurus node[398266]:     at ExecutionContext._evaluateInternal (/home/rendyep/apps/whatsapp-api-client/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:221:19)
Feb 09 01:49:37 Nenosaurus node[398266]:     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Feb 09 01:49:37 Nenosaurus node[398266]:     at async ExecutionContext.evaluate (/home/rendyep/apps/whatsapp-api-client/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:110:16)
Feb 09 01:49:37 Nenosaurus node[398266]:     at async Client.initialize (/home/rendyep/apps/whatsapp-api-client/node_modules/whatsapp-web.js/src/Client.js:267:9)
Feb 09 01:49:37 Nenosaurus node[398266]: Node.js v18.13.0
Feb 09 01:49:37 Nenosaurus systemd[1]: whatsapp-api-client.service: Main process exited, code=exited, status=1/FAILURE
Feb 09 01:49:37 Nenosaurus systemd[1]: whatsapp-api-client.service: Killing process 398342 (ThreadPoolForeg) with signal SIGKILL.
Feb 09 01:49:37 Nenosaurus systemd[1]: whatsapp-api-client.service: Failed with result 'exit-code'.
Feb 09 01:49:37 Nenosaurus systemd[1]: whatsapp-api-client.service: Consumed 55.343s CPU time.

Below is my code which should handle any SIGINT and/or SIGTERM signal correctly.

clientsConfig.forEach((clientConfig) => {
  const clientId = clientConfig.id;
  
  clients[clientId] = new Client({
    authStrategy: new LocalAuth({ dataPath: `./.data/${clientId}` }),
    puppeteer: {
      handleSIGINT: false,
      handleSIGTERM: false,
      args: [
        '--no-sandbox',
        '--no-default-browser-check',
        '--disable-dev-shm-usage',
        '--disable-accelerated-2d-canvas',
        '--no-first-run',
        '--no-zygote',
        '--single-process',
        '--disable-gpu',
      ],
    }
  });
  clients[clientId].initialize();
}

// handle SIGINT
process.on('SIGINT', async () => {
  logger.warn('(SIGINT) Shutting down...');
  await destroyClients();
  process.exit(0);
});

// handle SIGTERM
process.on('SIGTERM', async () => {
  logger.warn('(SIGTERM) Shutting down...');
  await destroyClients();
  process.exit(0);
});

Below is the proof that the process exited gracefully when I stop the service.

Feb 08 11:47:52 Nenosaurus systemd[1]: Stopping Whatsapp API Client...
Feb 08 11:47:52 Nenosaurus node[325273]: [2023-02-08T04:47:52.808Z][info] (SIGTERM) Shutting down...
Feb 08 11:47:52 Nenosaurus node[325273]: [2023-02-08T04:47:52.904Z][info][[email protected]] Client destroyed
Feb 08 11:47:52 Nenosaurus node[325273]: [2023-02-08T04:47:52.905Z][info][[email protected]] Client destroyed

Expected behavior

I need the way to clear browser data (eg. cache) safely without requiring to re-login after restart.

Steps to Reproduce the Bug or Issue

  1. Run the app
  2. Wait for 3 or 4 days
  3. Restart the app safely (handling SIGTERM and/or SIGKILL properly by calling client.destroy() before the process exit)
  4. Chromium data takes around 600 MB of disk space after 3 or 4 days

Relevant Code

No response

Browser Type

Chromium

WhatsApp Account Type

Standard

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

OS: Ubuntu Headless
Phone OS: Android & iOS
whatsapp-web.js version: 1.19.3
Node.js Version: 18.13.0

Additional context

I guess the chromium data grows rapidly because of restarting the app several times. But my code handle the SIGTERM and SIGKILL signals so that when the process is going to be killed, my code handle the await client.destroy() the correct way without error.

@rendyep rendyep added the bug Something isn't working label Feb 8, 2023
@PurpShell
Copy link
Sponsor Collaborator

It grows because of the whatsapp data

@vlarysc
Copy link

vlarysc commented Dec 28, 2023

I have the same problema,

@robsoncombr
Copy link

It grows because of the whatsapp data

Ok, let´s agree or suppose that everyone knows why the data size increases, what was brought under discussion here is a way to clear this cache data without lose the session auth and avoid need to read QRCode again. This is relevant and I would also like to have a solution on this, we do not need all data, cache, blob, etc. on the client if we think that we already saved everything we need somewhere, so it becomes just a lot of duplicated trash data.
An idea would be to manually delete files and folders until we achieve it and can reproduce into a function to automate?
I will try this when I have a free time and I could share or implement the automation.
Can we have this re-opened as a feature request instead a defect?

@robsoncombr
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants