diff --git a/scrapling/engines/_browsers/_controllers.py b/scrapling/engines/_browsers/_controllers.py index edabb17d..7707ae92 100644 --- a/scrapling/engines/_browsers/_controllers.py +++ b/scrapling/engines/_browsers/_controllers.py @@ -78,7 +78,10 @@ def start(self): if self._config.cdp_url: # pragma: no cover self.browser = self.playwright.chromium.connect_over_cdp(endpoint_url=self._config.cdp_url) if not self._config.proxy_rotator and self.browser: - self.context = self.browser.new_context(**self._context_options) + if self.browser.contexts: + self.context = self.browser.contexts[0] + else: + self.context = self.browser.new_context(**self._context_options) elif self._config.proxy_rotator: self.browser = self.playwright.chromium.launch(**self._browser_options) else: @@ -266,7 +269,10 @@ async def start(self) -> None: if self._config.cdp_url: self.browser = await self.playwright.chromium.connect_over_cdp(endpoint_url=self._config.cdp_url) if not self._config.proxy_rotator and self.browser: - self.context = await self.browser.new_context(**self._context_options) + if self.browser.contexts: + self.context = self.browser.contexts[0] + else: + self.context = await self.browser.new_context(**self._context_options) elif self._config.proxy_rotator: self.browser = await self.playwright.chromium.launch(**self._browser_options) else: diff --git a/scrapling/engines/_browsers/_stealth.py b/scrapling/engines/_browsers/_stealth.py index efa195e2..415fdfb3 100644 --- a/scrapling/engines/_browsers/_stealth.py +++ b/scrapling/engines/_browsers/_stealth.py @@ -83,7 +83,10 @@ def start(self) -> None: self.browser = self.playwright.chromium.connect_over_cdp(endpoint_url=self._config.cdp_url) if not self._config.proxy_rotator: assert self.browser is not None - self.context = self.browser.new_context(**self._context_options) + if self.browser.contexts: + self.context = self.browser.contexts[0] + else: + self.context = self.browser.new_context(**self._context_options) elif self._config.proxy_rotator: self.browser = self.playwright.chromium.launch(**self._browser_options) else: @@ -358,7 +361,10 @@ async def start(self) -> None: self.browser = await self.playwright.chromium.connect_over_cdp(endpoint_url=self._config.cdp_url) if not self._config.proxy_rotator: assert self.browser is not None - self.context = await self.browser.new_context(**self._context_options) + if self.browser.contexts: + self.context = self.browser.contexts[0] + else: + self.context = await self.browser.new_context(**self._context_options) elif self._config.proxy_rotator: self.browser = await self.playwright.chromium.launch(**self._browser_options) else: