-
Notifications
You must be signed in to change notification settings - Fork 183
Add session.fetch for HTTP requests from the page #943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9b45fe6
feat(sdk): add session.fetch for in-page HTTP requests
giordano-lucas 677102d
fix(fetch): keep params before fragments, reject GET/HEAD bodies
giordano-lucas 307a063
test(fetch): send the content-type case as a POST
giordano-lucas a614c68
feat(fetch): return a requests.Response instead of a custom type
giordano-lucas 418f3a1
fix(docs): make llms.txt generation offline for pre-commit
giordano-lucas d88d87e
fix(fetch): preserve response bytes and honour the declared charset
giordano-lucas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| --- | ||
| title: "Response" | ||
| description: "The :class:`Response <Response>` object, which contains a" | ||
| --- | ||
|
|
||
|
|
||
| server's response to an HTTP request | ||
|
|
||
| ## Methods | ||
|
|
||
| ### close | ||
|
|
||
| ```python | ||
| close() | ||
| ``` | ||
|
|
||
| Releases the connection back to the pool | ||
|
|
||
| --- | ||
|
|
||
| ### iter_content | ||
|
|
||
| ```python | ||
| iter_content(chunk_size = 1, decode_unicode = False) | ||
| ``` | ||
|
|
||
| Iterates over the response data | ||
|
|
||
| --- | ||
|
|
||
| ### iter_lines | ||
|
|
||
| ```python | ||
| iter_lines(chunk_size = 512, decode_unicode = False, delimiter = None) | ||
| ``` | ||
|
|
||
| Iterates over the response data, one line at a time | ||
|
|
||
| --- | ||
|
|
||
| ### json | ||
|
|
||
| ```python | ||
| json(kwargs) | ||
| ``` | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| Decodes the JSON response body (if any) as a Python object | ||
|
|
||
| --- | ||
|
|
||
| ### raise_for_status | ||
|
|
||
| ```python | ||
| raise_for_status() | ||
| ``` | ||
|
|
||
| Raises :class:`HTTPError`, if one occurred | ||
|
|
||
| --- | ||
|
|
||
|
|
||
|
|
||
| ## Module | ||
|
|
||
| `requests.models` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| --- | ||
| title: "fetch" | ||
| description: "Issue an HTTP request from the page the session is on and return the response" | ||
| --- | ||
| import AgentMdNotice from '/partials/agent-md-notice.mdx'; | ||
|
|
||
| <AgentMdNotice /> | ||
|
|
||
| The request runs inside the browser through `fetch()`, so it carries the | ||
| page's cookies, the session's proxy and the browser's own network | ||
| fingerprint. A relative `url` resolves against the current page, which | ||
| also makes it same-origin; a cross-origin URL is subject to CORS exactly | ||
| as in a browser tab, so `goto` the target origin first. Redirects are | ||
| followed and the final URL is on `response.url`. The result is a standard | ||
| `requests.Response`: a non-2xx status is returned, not raised, and | ||
| `response.raise_for_status()` raises `requests.HTTPError`. A network | ||
| failure surfaces as the JavaScript error. | ||
|
|
||
| `json` is serialised as the body with an `application/json` content type, | ||
| `data` as a form body when it is a mapping or verbatim when it is a string. | ||
|
|
||
| ```python | ||
| session.execute(type="goto", url="https://en.wikipedia.org/wiki/Main_Page") | ||
| summary = session.fetch("/api/rest_v1/page/summary/Main_Page").json() | ||
| ``` | ||
|
|
||
|
|
||
| ## Parameters | ||
|
|
||
| <ParamField path="url" type="str" required> | ||
| </ParamField> | ||
|
|
||
| <ParamField path="method" type="str" default="GET"> | ||
| </ParamField> | ||
|
|
||
| <ParamField path="headers" type="UnionType[Mapping[str, str], None]" default="None"> | ||
| </ParamField> | ||
|
|
||
| <ParamField path="params" type="UnionType[Mapping[str, Any], None]" default="None"> | ||
| </ParamField> | ||
|
|
||
| <ParamField path="json" type="Any" default="None"> | ||
| </ParamField> | ||
|
|
||
| <ParamField path="data" type="UnionType[str, Mapping[str, Any], None]" default="None"> | ||
| </ParamField> | ||
|
|
||
| <ParamField path="timeout" type="UnionType[float, None]" default="None"> | ||
| </ParamField> | ||
|
|
||
| ## Returns | ||
|
|
||
| <Visibility for="humans">[`Response`](/sdk-reference/misc/response)</Visibility><Visibility for="agents">[`Response`](/sdk-reference/misc/response.md)</Visibility> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.