jeliebig / WaWebSessionHandler

(DISCONTINUED) Save WhatsApp Web Sessions as files and open them everywhere!
MIT License
27 stars 11 forks source link

how to use #5

Closed erickythierry closed 3 years ago

erickythierry commented 3 years ago

I have a project that uses selenium to automate whatsapp, but one of the problems I've been facing is that chrome ends up creating a lot of cache files in the folder where it saves the session (about 500mb). that your script can save the whatsapp session and then restore it without all that extra chrome cache?

a piece of selenium code below

elif self.client == "chrome":
            self._profile = webdriver.ChromeOptions()
            if self._profile_path is not None:
                self._profile.add_argument("--user-data-dir=%s" % self._profile_path)
            if proxy is not None:
                self._profile.add_argument('--proxy-server=%s' % proxy)
            if headless:
                self._profile.add_argument('--headless')
                self._profile.add_argument('--disable-gpu')
                self._profile.add_argument('--remote-debugging-port=9222')
                self._profile.add_argument('--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36')
            if chrome_options is not None:
                for option in chrome_options:
                    self._profile.add_argument(option)

            if executable_path is not None:
                self.logger.info("Starting webdriver")
                self.driver = webdriver.Chrome(executable_path=executable_path, chrome_options=self._profile, **extra_params)
            else:
                self.logger.info("Starting webdriver")
                self.driver = webdriver.Chrome(chrome_options=self._profile, **extra_params)

I point a folder to chrome to save the data and so I can recover the whatsapp session, but these extra chrome files end up hurting the project's performance after a few days running ...

TSRBerry commented 3 years ago

Yes, that's because you created a new chrome profile in your specified directory. But you don't need that if you only want to store a WhatsApp Web Session. WhatsApp stores the data for the session in local storage and/or (depending on what method they are using, they sometimes mix it up) IndexedDB. So you need a method to get data from those two storages and a method to inject it in there again.

If you want to use my script, you could easily save yourself the extra effort of writing that yourself and just import my SessionHandler class to your script.