Merge branch 'dev' into fix/block-ads-unexpected-kwarg

This commit is contained in:
Karim shoair
2026-04-17 20:45:00 +02:00
committed by GitHub
23 changed files with 607 additions and 220 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
__author__ = "Karim Shoair (karim.shoair@pm.me)"
__version__ = "0.4.6"
__version__ = "0.4.7"
__copyright__ = "Copyright (c) 2024 Karim Shoair"
from typing import Any, TYPE_CHECKING
+8 -1
View File
@@ -123,6 +123,7 @@ class ScraplingMCPServer:
async def open_session(
self,
session_type: SessionType,
session_id: Optional[str] = None,
headless: bool = True,
google_search: bool = True,
real_chrome: bool = False,
@@ -152,6 +153,7 @@ class ScraplingMCPServer:
Use close_session to close the session when done, and list_sessions to see all active sessions.
:param session_type: The type of session to open. Use "dynamic" for standard Playwright browser, or "stealthy" for anti-bot bypass with fingerprint spoofing.
:param session_id: Optional custom session ID. If not provided, a random 12-character hex ID will be generated. Useful for naming sessions for easier management.
:param headless: Run the browser in headless/hidden (default), or headful/visible mode.
:param google_search: Enabled by default, Scrapling will set a Google referer header.
:param real_chrome: If you have a Chrome browser installed on your device, enable this, and the Fetcher will launch an instance of your browser and use it.
@@ -175,6 +177,12 @@ class ScraplingMCPServer:
:param solve_cloudflare: (Stealthy only) Solves all types of the Cloudflare's Turnstile/Interstitial challenges.
:param additional_args: (Stealthy only) Additional arguments to be passed to Playwright's context as additional settings.
"""
session_id = session_id or uuid4().hex[:12]
if session_id in self._sessions:
raise ValueError(
f"Session '{session_id}' already exists. Use a different ID or close the existing session first."
)
common_kwargs: Dict[str, Any] = dict(
wait=wait,
proxy=proxy,
@@ -211,7 +219,6 @@ class ScraplingMCPServer:
await session.start()
session_id = uuid4().hex[:12]
entry = _SessionEntry(session=session, session_type=session_type)
self._sessions[session_id] = entry
+12 -2
View File
@@ -719,8 +719,13 @@ class FetcherSession:
config["selector_config"] = self.selector_config
config["proxy_rotator"] = self._proxy_rotator
self._client = _SyncSessionLogic(**config)
try:
result = self._client.__enter__()
except Exception:
self._client = None
raise
self._is_alive = True
return self._client.__enter__()
return result
raise RuntimeError("This FetcherSession instance already has an active synchronous session.")
def __exit__(self, exc_type, exc_val, exc_tb):
@@ -740,8 +745,13 @@ class FetcherSession:
config["selector_config"] = self.selector_config
config["proxy_rotator"] = self._proxy_rotator
self._client = _ASyncSessionLogic(**config)
try:
result = await self._client.__aenter__()
except Exception:
self._client = None
raise
self._is_alive = True
return await self._client.__aenter__()
return result
raise RuntimeError("This FetcherSession instance already has an active asynchronous session.")
async def __aexit__(self, exc_type, exc_val, exc_tb):
+3 -1
View File
@@ -93,7 +93,9 @@ class SessionManager:
async def close(self) -> None:
"""Close all registered sessions."""
for session in self._sessions.values():
for sid, session in self._sessions.items():
if sid in self._lazy_sessions and not session._is_alive:
continue
_ = await session.__aexit__(None, None, None)
self._started = False