Skip to content

Commit f8b192d

Browse files
author
stlc-bot
committed
feat(scrape): support custom screenshot headers (#1169)
Stainless-Generated-From: 5b13d3673c7a039f7030a8ebfe760f1a1108c621
1 parent 65fa0fe commit f8b192d

6 files changed

Lines changed: 72 additions & 6 deletions

File tree

‎src/context/dev/resources/web.py‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ def screenshot(
712712
domain: str | Omit = omit,
713713
full_screenshot: Literal["true", "false"] | Omit = omit,
714714
handle_cookie_popup: bool | Omit = omit,
715+
headers: Dict[str, str] | Omit = omit,
715716
max_age_ms: Optional[int] | Omit = omit,
716717
page: Literal["login", "signup", "blog", "careers", "pricing", "terms", "privacy", "contact"] | Omit = omit,
717718
scroll_offset: Optional[int] | Omit = omit,
@@ -759,6 +760,14 @@ def screenshot(
759760
dismiss cookie banner before capture. If 'false' or not provided, captures the
760761
page without that step.
761762
763+
headers: Optional outbound HTTP headers, using the same JSON object or deep-object query
764+
format as other scrape endpoints (for example headers[Authorization]=Bearer
765+
token). Headers are scoped to the target origin during capture. For domain/page
766+
requests, discovery receives no custom headers and only pages on the resolved
767+
origin are eligible. Non-empty headers bypass screenshot caching and return an
768+
in-memory data URL; no screenshot is uploaded. Empty objects behave like omitted
769+
headers.
770+
762771
max_age_ms: Return a cached screenshot if a prior screenshot for the same parameters exists
763772
and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when
764773
omitted. Max is 30 days (2592000000 ms). Set to 0 to always capture fresh.
@@ -821,6 +830,7 @@ def screenshot(
821830
"domain": domain,
822831
"full_screenshot": full_screenshot,
823832
"handle_cookie_popup": handle_cookie_popup,
833+
"headers": headers,
824834
"max_age_ms": max_age_ms,
825835
"page": page,
826836
"scroll_offset": scroll_offset,
@@ -2862,6 +2872,7 @@ def web_scrape_screenshot(
28622872
| Omit = omit,
28632873
full_screenshot: Literal["true", "false"] | Omit = omit,
28642874
handle_cookie_popup: bool | Omit = omit,
2875+
headers: Dict[str, str] | Omit = omit,
28652876
max_age_ms: Optional[int] | Omit = omit,
28662877
scroll_offset: Optional[int] | Omit = omit,
28672878
tags: SequenceNotStr[str] | Omit = omit,
@@ -2905,6 +2916,14 @@ def web_scrape_screenshot(
29052916
dismiss cookie banner before capture. If 'false' or not provided, captures the
29062917
page without that step.
29072918
2919+
headers: Optional outbound HTTP headers, using the same JSON object or deep-object query
2920+
format as other scrape endpoints (for example headers[Authorization]=Bearer
2921+
token). Headers are scoped to the target origin during capture. For domain/page
2922+
requests, discovery receives no custom headers and only pages on the resolved
2923+
origin are eligible. Non-empty headers bypass screenshot caching and return an
2924+
in-memory data URL; no screenshot is uploaded. Empty objects behave like omitted
2925+
headers.
2926+
29082927
max_age_ms: Return a cached screenshot if a prior screenshot for the same parameters exists
29092928
and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when
29102929
omitted. Max is 30 days (2592000000 ms). Set to 0 to always capture fresh.
@@ -2960,6 +2979,7 @@ def web_scrape_screenshot(
29602979
"country": country,
29612980
"full_screenshot": full_screenshot,
29622981
"handle_cookie_popup": handle_cookie_popup,
2982+
"headers": headers,
29632983
"max_age_ms": max_age_ms,
29642984
"scroll_offset": scroll_offset,
29652985
"tags": tags,
@@ -3734,6 +3754,7 @@ async def screenshot(
37343754
domain: str | Omit = omit,
37353755
full_screenshot: Literal["true", "false"] | Omit = omit,
37363756
handle_cookie_popup: bool | Omit = omit,
3757+
headers: Dict[str, str] | Omit = omit,
37373758
max_age_ms: Optional[int] | Omit = omit,
37383759
page: Literal["login", "signup", "blog", "careers", "pricing", "terms", "privacy", "contact"] | Omit = omit,
37393760
scroll_offset: Optional[int] | Omit = omit,
@@ -3781,6 +3802,14 @@ async def screenshot(
37813802
dismiss cookie banner before capture. If 'false' or not provided, captures the
37823803
page without that step.
37833804
3805+
headers: Optional outbound HTTP headers, using the same JSON object or deep-object query
3806+
format as other scrape endpoints (for example headers[Authorization]=Bearer
3807+
token). Headers are scoped to the target origin during capture. For domain/page
3808+
requests, discovery receives no custom headers and only pages on the resolved
3809+
origin are eligible. Non-empty headers bypass screenshot caching and return an
3810+
in-memory data URL; no screenshot is uploaded. Empty objects behave like omitted
3811+
headers.
3812+
37843813
max_age_ms: Return a cached screenshot if a prior screenshot for the same parameters exists
37853814
and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when
37863815
omitted. Max is 30 days (2592000000 ms). Set to 0 to always capture fresh.
@@ -3843,6 +3872,7 @@ async def screenshot(
38433872
"domain": domain,
38443873
"full_screenshot": full_screenshot,
38453874
"handle_cookie_popup": handle_cookie_popup,
3875+
"headers": headers,
38463876
"max_age_ms": max_age_ms,
38473877
"page": page,
38483878
"scroll_offset": scroll_offset,
@@ -5884,6 +5914,7 @@ async def web_scrape_screenshot(
58845914
| Omit = omit,
58855915
full_screenshot: Literal["true", "false"] | Omit = omit,
58865916
handle_cookie_popup: bool | Omit = omit,
5917+
headers: Dict[str, str] | Omit = omit,
58875918
max_age_ms: Optional[int] | Omit = omit,
58885919
scroll_offset: Optional[int] | Omit = omit,
58895920
tags: SequenceNotStr[str] | Omit = omit,
@@ -5927,6 +5958,14 @@ async def web_scrape_screenshot(
59275958
dismiss cookie banner before capture. If 'false' or not provided, captures the
59285959
page without that step.
59295960
5961+
headers: Optional outbound HTTP headers, using the same JSON object or deep-object query
5962+
format as other scrape endpoints (for example headers[Authorization]=Bearer
5963+
token). Headers are scoped to the target origin during capture. For domain/page
5964+
requests, discovery receives no custom headers and only pages on the resolved
5965+
origin are eligible. Non-empty headers bypass screenshot caching and return an
5966+
in-memory data URL; no screenshot is uploaded. Empty objects behave like omitted
5967+
headers.
5968+
59305969
max_age_ms: Return a cached screenshot if a prior screenshot for the same parameters exists
59315970
and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when
59325971
omitted. Max is 30 days (2592000000 ms). Set to 0 to always capture fresh.
@@ -5982,6 +6021,7 @@ async def web_scrape_screenshot(
59826021
"country": country,
59836022
"full_screenshot": full_screenshot,
59846023
"handle_cookie_popup": handle_cookie_popup,
6024+
"headers": headers,
59856025
"max_age_ms": max_age_ms,
59866026
"scroll_offset": scroll_offset,
59876027
"tags": tags,

‎src/context/dev/types/web_screenshot_params.py‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import Optional
5+
from typing import Dict, Optional
66
from typing_extensions import Literal, Required, Annotated, TypedDict
77

88
from .._types import SequenceNotStr
@@ -266,6 +266,17 @@ class WebScreenshotParams(TypedDict, total=False):
266266
captures the page without that step.
267267
"""
268268

269+
headers: Dict[str, str]
270+
"""
271+
Optional outbound HTTP headers, using the same JSON object or deep-object query
272+
format as other scrape endpoints (for example headers[Authorization]=Bearer
273+
token). Headers are scoped to the target origin during capture. For domain/page
274+
requests, discovery receives no custom headers and only pages on the resolved
275+
origin are eligible. Non-empty headers bypass screenshot caching and return an
276+
in-memory data URL; no screenshot is uploaded. Empty objects behave like omitted
277+
headers.
278+
"""
279+
269280
max_age_ms: Annotated[Optional[int], PropertyInfo(alias="maxAgeMs")]
270281
"""
271282
Return a cached screenshot if a prior screenshot for the same parameters exists

‎src/context/dev/types/web_screenshot_response.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ class WebScreenshotResponse(BaseModel):
7474

7575
screenshot: Optional[str] = None
7676
"""
77-
Public image URL for standard requests, or an in-memory data URL when ZDR is
78-
enabled.
77+
Public image URL for standard requests, or an in-memory data URL when ZDR or
78+
non-empty custom headers are supplied.
7979
"""
8080

8181
screenshot_type: Optional[Literal["viewport", "fullPage"]] = FieldInfo(alias="screenshotType", default=None)

‎src/context/dev/types/web_web_scrape_screenshot_params.py‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import Optional
5+
from typing import Dict, Optional
66
from typing_extensions import Literal, Required, Annotated, TypedDict
77

88
from .._types import SequenceNotStr
@@ -254,6 +254,17 @@ class WebWebScrapeScreenshotParams(TypedDict, total=False):
254254
captures the page without that step.
255255
"""
256256

257+
headers: Dict[str, str]
258+
"""
259+
Optional outbound HTTP headers, using the same JSON object or deep-object query
260+
format as other scrape endpoints (for example headers[Authorization]=Bearer
261+
token). Headers are scoped to the target origin during capture. For domain/page
262+
requests, discovery receives no custom headers and only pages on the resolved
263+
origin are eligible. Non-empty headers bypass screenshot caching and return an
264+
in-memory data URL; no screenshot is uploaded. Empty objects behave like omitted
265+
headers.
266+
"""
267+
257268
max_age_ms: Annotated[Optional[int], PropertyInfo(alias="maxAgeMs")]
258269
"""
259270
Return a cached screenshot if a prior screenshot for the same parameters exists

‎src/context/dev/types/web_web_scrape_screenshot_response.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class WebWebScrapeScreenshotResponse(BaseModel):
5555

5656
screenshot: str
5757
"""
58-
Public image URL for standard requests, or an in-memory data URL when ZDR is
59-
enabled.
58+
Public image URL for standard requests, or an in-memory data URL when ZDR or
59+
non-empty custom headers are supplied.
6060
"""
6161

6262
url: str

‎tests/api_resources/test_web.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ def test_method_screenshot_with_all_params(self, client: ContextDev) -> None:
332332
domain="xxx",
333333
full_screenshot="true",
334334
handle_cookie_popup=True,
335+
headers={"foo": "J!"},
335336
max_age_ms=0,
336337
page="login",
337338
scroll_offset=0,
@@ -790,6 +791,7 @@ def test_method_web_scrape_screenshot_with_all_params(self, client: ContextDev)
790791
country="de",
791792
full_screenshot="true",
792793
handle_cookie_popup=True,
794+
headers={"foo": "J!"},
793795
max_age_ms=0,
794796
scroll_offset=0,
795797
tags=["production", "team-alpha"],
@@ -1192,6 +1194,7 @@ async def test_method_screenshot_with_all_params(self, async_client: AsyncContex
11921194
domain="xxx",
11931195
full_screenshot="true",
11941196
handle_cookie_popup=True,
1197+
headers={"foo": "J!"},
11951198
max_age_ms=0,
11961199
page="login",
11971200
scroll_offset=0,
@@ -1650,6 +1653,7 @@ async def test_method_web_scrape_screenshot_with_all_params(self, async_client:
16501653
country="de",
16511654
full_screenshot="true",
16521655
handle_cookie_popup=True,
1656+
headers={"foo": "J!"},
16531657
max_age_ms=0,
16541658
scroll_offset=0,
16551659
tags=["production", "team-alpha"],

0 commit comments

Comments
 (0)