You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(ai)!: keep session settings on MCP session fetches (#418)
The three MCP tools that accept a `session_id` forwarded every per-fetch
parameter to the session's `fetch()`, including their own defaults when
the caller supplied nothing. `validate_fetch` treats every key it
receives as an override, so the branch that reads the value from the
session config never ran, and the tool defaults replaced the settings the
session was opened with.
- Forward only the parameters the caller actually supplied
- Default those parameters to `None` on `fetch`, `bulk_fetch`,
`stealthy_fetch`, `bulk_stealthy_fetch` and `screenshot`
- Add regression tests for the forwarded kwargs, and for the session
settings surviving the validation the tools go through
"""Use playwright to open a browser to fetch a URL and return a structured output of the result.
@@ -573,7 +580,7 @@ async def fetch(
573
580
:param google_search: Enabled by default, Scrapling will set a Google referer header.
574
581
:param extra_headers: A dictionary of extra headers to add to the request. _The referer set by `google_search` takes priority over the referer set here if used together._
575
582
:param proxy: The proxy to be used with requests, it can be a string or a dictionary with the keys 'server', 'username', and 'password' only.
576
-
:param session_id: Optional session ID from open_session. If provided, reuses the existing browser session instead of creating a new one.
583
+
:param session_id: Optional session ID from open_session. If provided, reuses the existing browser session instead of creating a new one, and every option you leave out here keeps the value the session was opened with.
"""Use playwright to open a browser, then fetch a group of URLs at the same time, and for each page return a structured output of the result.
@@ -652,32 +659,26 @@ async def bulk_fetch(
652
659
:param google_search: Enabled by default, Scrapling will set a Google referer header.
653
660
:param extra_headers: A dictionary of extra headers to add to the request. _The referer set by `google_search` takes priority over the referer set here if used together._
654
661
:param proxy: The proxy to be used with requests, it can be a string or a dictionary with the keys 'server', 'username', and 'password' only.
655
-
:param session_id: Optional session ID from open_session. If provided, reuses the existing browser session instead of creating a new one.
662
+
:param session_id: Optional session ID from open_session. If provided, reuses the existing browser session instead of creating a new one, and every option you leave out here keeps the value the session was opened with.
:param extra_headers: A dictionary of extra headers to add to the request. _The referer set by `google_search` takes priority over the referer set here if used together._
761
757
:param proxy: The proxy to be used with requests, it can be a string or a dictionary with the keys 'server', 'username', and 'password' only.
762
758
:param additional_args: Additional arguments to be passed to Playwright's context as additional settings, and it takes higher priority than Scrapling's settings.
763
-
:param session_id: Optional session ID from open_session. If provided, reuses the existing browser session instead of creating a new one.
759
+
:param session_id: Optional session ID from open_session. If provided, reuses the existing browser session instead of creating a new one, and every option you leave out here keeps the value the session was opened with.
:param extra_headers: A dictionary of extra headers to add to the request. _The referer set by `google_search` takes priority over the referer set here if used together._
855
851
:param proxy: The proxy to be used with requests, it can be a string or a dictionary with the keys 'server', 'username', and 'password' only.
856
852
:param additional_args: Additional arguments to be passed to Playwright's context as additional settings, and it takes higher priority than Scrapling's settings.
857
-
:param session_id: Optional session ID from open_session. If provided, reuses the existing browser session instead of creating a new one.
853
+
:param session_id: Optional session ID from open_session. If provided, reuses the existing browser session instead of creating a new one, and every option you leave out here keeps the value the session was opened with.
5. For all fetch tools, `main_content_only` is enabled by default and returns only the content inside the page's `<body>` tag. Pass `main_content_only=False` when you need the full page instead.
941
925
6. If the task consists of multiple requests to the same website, open a session to be more efficient.
942
926
7. For browser-based tools, if a `session_id` is provided (from open_session), the browser session will be reused instead of creating a new one.
943
-
When using a session, browser-level params (headless, proxy, locale, etc.) are ignored since they were set at session creation time.
927
+
When using a session, browser-level params (headless, locale, useragent, etc.) are ignored since they were set at session creation time, and any per-request param you leave out keeps the value the session was opened with.
944
928
8. If you are making multiple requests, use the bulk version of the tool to be more efficient.
945
929
9. If you are crawling/browsing a website, be more efficient by using the `css_selector` parameter to only access the parts you are interested in and save money/time. Example: use the `a` selector to extract the urls right away.
946
930
10. The user can pass a CDP URL to connect to a remote browser session through the `open_session` tool, then use it in the rest of the tools.
0 commit comments