kaliiiiiiiiii / Selenium-Driverless

undetected Selenium without usage of chromedriver
https://kaliiiiiiiiii.github.io/Selenium-Driverless/
Other
520 stars 63 forks source link

how to disable "clean_dirs" in driver.quit() function #56

Closed henzycuong1 closed 11 months ago

henzycuong1 commented 11 months ago

I tried example code and got an inconvenience is the "quit()" function will delete all dir even when i used "user-data-dir"

async def quit(self, timeout: float = 30) -> None:
        """Quits the target and closes every associated window.

        :Usage:
            ::

                target.quit()
        """

        def clean_dirs(dirs: typing.List[str]):
            for _dir in dirs:
                while os.path.isdir(_dir):
                    shutil.rmtree(_dir, ignore_errors=True)

        start = time.monotonic()
        # noinspection PyUnresolvedReferences,PyBroadException
        try:
            await self.base_target.execute_cdp_cmd("Browser.close")
        except websockets.exceptions.ConnectionClosedError:
            pass
        except Exception:
            import sys
            print('Ignoring exception at self.base_target.execute_cdp_cmd("Browser.close")', file=sys.stderr)
            traceback.print_exc()

        if not self._is_remote:
            # noinspection PyBroadException,PyUnusedLocal
            try:
                # wait for process to be killed
                while True:
                    try:
                        os.kill(self.browser_pid, 15)
                    except OSError:
                        break
                    await asyncio.sleep(0.1)
                    check_timeout(start, timeout)
                loop = asyncio.get_running_loop()
                await asyncio.wait_for(
                    # wait for
                    loop.run_in_executor(None,
                                         lambda: clean_dirs([self._temp_dir, self._options.user_data_dir])),
                    timeout=timeout - (time.monotonic() - start))
            except Exception as e:
                traceback.print_exc()
            finally:
                pass

can you create a feature except user_data_dir ? Thank you so much