async def _set_cookies(self, page: Page, cookies: Union[List[Dict[str, str]], Dict[str, str]]) -> None: """Add cookies to page.""" if isinstance(cookies, dict): await page.setCookie(cookies) elif isinstance(cookies, (list, tuple, set)): await asyncio.gather( *[page.setCookie(cookie) for cookie in cookies])
async def load_cookies(self, page: Page): if os.path.exists(self.cookie_path): with open(self.cookie_path, mode="r") as f: cookies = json.load(f) tasks = [ asyncio.create_task(page.setCookie(c)) for c in cookies if c["name"] not in self.IGNORE_COOKIE_NAMES ] if len(tasks) > 0: await asyncio.wait(tasks, return_when=asyncio.ALL_COMPLETED) LOG.info(f"Cookies for {self.password_manager.username} loaded.") else: LOG.info( f"Cookies for {self.password_manager.username} not yet existing." )