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
{{ message }}
Repository navigation
Commit ac70e57
Browse filesBrowse the repository at this point in the historyBrowse files
stlc-bot
committed
feat(scrape): support custom screenshot headers (#1169)
Copy file name to clipboardExpand all lines: src/ServiceContracts/WebContract.php
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -210,6 +210,7 @@ public function extractStyleguide(
210
210
* @param string $domain Domain name to take screenshot of (e.g., 'example.com', 'google.com'). The domain will be automatically normalized and validated. You must provide either 'domain' or 'directUrl', but not both.
211
211
* @param FullScreenshot|value-of<FullScreenshot> $fullScreenshot Optional parameter to determine screenshot type. If 'true', takes a full page screenshot capturing all content. If 'false' or not provided, takes a viewport screenshot (standard browser view).
212
212
* @param bool $handleCookiePopup Optional parameter to control cookie/consent popup handling. If 'true', we dismiss cookie banner before capture. If 'false' or not provided, captures the page without that step.
213
+
* @param array<string,string> $headers Optional outbound HTTP headers, using the same JSON object or deep-object query format as other scrape endpoints (for example headers[Authorization]=Bearer token). Headers are scoped to the target origin during capture. For domain/page requests, discovery receives no custom headers and only pages on the resolved origin are eligible. Non-empty headers bypass screenshot caching and return an in-memory data URL; no screenshot is uploaded. Empty objects behave like omitted headers.
213
214
* @param int|null $maxAgeMs Return a cached screenshot if a prior screenshot for the same parameters exists and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always capture fresh.
214
215
* @param Page|value-of<Page> $page Optional parameter to specify which page type to screenshot. If provided, the system will scrape the domain's links and use heuristics to find the most appropriate URL for the specified page type (30 supported languages). If not provided, screenshots the main domain landing page. Only applicable when using 'domain', not 'directUrl'.
215
216
* @param int|null $scrollOffset Optional vertical scroll offset in pixels for capturing a long page in viewport-sized chunks. When provided, the full page is captured once and the returned image is the viewport-sized slice that begins at this Y offset (e.g. request scrollOffset=0, then 1080, then 2160 to walk a 1920x1080 landing page top to bottom). The final slice may be shorter than the viewport height. Takes precedence over fullScreenshot. Max: 100000.
@@ -230,6 +231,7 @@ public function screenshot(
230
231
?string$domain = null,
231
232
FullScreenshot|string|null$fullScreenshot = null,
232
233
bool$handleCookiePopup = false,
234
+
?array$headers = null,
233
235
?int$maxAgeMs = 86400000,
234
236
Page|string|null$page = null,
235
237
?int$scrollOffset = null,
@@ -489,6 +491,7 @@ public function webScrapeMd(
489
491
* @param \ContextDev\Web\WebWebScrapeScreenshotParams\Country|value-of<\ContextDev\Web\WebWebScrapeScreenshotParams\Country> $country fetch the target page through a residential proxy in this country (ISO 3166-1 alpha-2)
490
492
* @param \ContextDev\Web\WebWebScrapeScreenshotParams\FullScreenshot|value-of<\ContextDev\Web\WebWebScrapeScreenshotParams\FullScreenshot> $fullScreenshot Optional parameter to determine screenshot type. If 'true', takes a full page screenshot capturing all content. If 'false' or not provided, takes a viewport screenshot (standard browser view).
491
493
* @param bool $handleCookiePopup Optional parameter to control cookie/consent popup handling. If 'true', we dismiss cookie banner before capture. If 'false' or not provided, captures the page without that step.
494
+
* @param array<string,string> $headers Optional outbound HTTP headers, using the same JSON object or deep-object query format as other scrape endpoints (for example headers[Authorization]=Bearer token). Headers are scoped to the target origin during capture. For domain/page requests, discovery receives no custom headers and only pages on the resolved origin are eligible. Non-empty headers bypass screenshot caching and return an in-memory data URL; no screenshot is uploaded. Empty objects behave like omitted headers.
492
495
* @param int|null $maxAgeMs Return a cached screenshot if a prior screenshot for the same parameters exists and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always capture fresh.
493
496
* @param int|null $scrollOffset Optional vertical scroll offset in pixels for capturing a long page in viewport-sized chunks. When provided, the full page is captured once and the returned image is the viewport-sized slice that begins at this Y offset (e.g. request scrollOffset=0, then 1080, then 2160 to walk a 1920x1080 landing page top to bottom). The final slice may be shorter than the viewport height. Takes precedence over fullScreenshot. Max: 100000.
494
497
* @param list<string> $tags Comma-separated tags for tracking request usage. Up to 20 tags, each 1-50 characters.
@@ -507,6 +510,7 @@ public function webScrapeScreenshot(
Copy file name to clipboardExpand all lines: src/Services/WebService.php
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -328,6 +328,7 @@ public function extractStyleguide(
328
328
* @param string $domain Domain name to take screenshot of (e.g., 'example.com', 'google.com'). The domain will be automatically normalized and validated. You must provide either 'domain' or 'directUrl', but not both.
329
329
* @param FullScreenshot|value-of<FullScreenshot> $fullScreenshot Optional parameter to determine screenshot type. If 'true', takes a full page screenshot capturing all content. If 'false' or not provided, takes a viewport screenshot (standard browser view).
330
330
* @param bool $handleCookiePopup Optional parameter to control cookie/consent popup handling. If 'true', we dismiss cookie banner before capture. If 'false' or not provided, captures the page without that step.
331
+
* @param array<string,string> $headers Optional outbound HTTP headers, using the same JSON object or deep-object query format as other scrape endpoints (for example headers[Authorization]=Bearer token). Headers are scoped to the target origin during capture. For domain/page requests, discovery receives no custom headers and only pages on the resolved origin are eligible. Non-empty headers bypass screenshot caching and return an in-memory data URL; no screenshot is uploaded. Empty objects behave like omitted headers.
331
332
* @param int|null $maxAgeMs Return a cached screenshot if a prior screenshot for the same parameters exists and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always capture fresh.
332
333
* @param Page|value-of<Page> $page Optional parameter to specify which page type to screenshot. If provided, the system will scrape the domain's links and use heuristics to find the most appropriate URL for the specified page type (30 supported languages). If not provided, screenshots the main domain landing page. Only applicable when using 'domain', not 'directUrl'.
333
334
* @param int|null $scrollOffset Optional vertical scroll offset in pixels for capturing a long page in viewport-sized chunks. When provided, the full page is captured once and the returned image is the viewport-sized slice that begins at this Y offset (e.g. request scrollOffset=0, then 1080, then 2160 to walk a 1920x1080 landing page top to bottom). The final slice may be shorter than the viewport height. Takes precedence over fullScreenshot. Max: 100000.
@@ -348,6 +349,7 @@ public function screenshot(
348
349
?string$domain = null,
349
350
FullScreenshot|string|null$fullScreenshot = null,
350
351
bool$handleCookiePopup = false,
352
+
?array$headers = null,
351
353
?int$maxAgeMs = 86400000,
352
354
Page|string|null$page = null,
353
355
?int$scrollOffset = null,
@@ -367,6 +369,7 @@ public function screenshot(
367
369
'domain' => $domain,
368
370
'fullScreenshot' => $fullScreenshot,
369
371
'handleCookiePopup' => $handleCookiePopup,
372
+
'headers' => $headers,
370
373
'maxAgeMs' => $maxAgeMs,
371
374
'page' => $page,
372
375
'scrollOffset' => $scrollOffset,
@@ -808,6 +811,7 @@ public function webScrapeMd(
808
811
* @param \ContextDev\Web\WebWebScrapeScreenshotParams\Country|value-of<\ContextDev\Web\WebWebScrapeScreenshotParams\Country> $country fetch the target page through a residential proxy in this country (ISO 3166-1 alpha-2)
809
812
* @param \ContextDev\Web\WebWebScrapeScreenshotParams\FullScreenshot|value-of<\ContextDev\Web\WebWebScrapeScreenshotParams\FullScreenshot> $fullScreenshot Optional parameter to determine screenshot type. If 'true', takes a full page screenshot capturing all content. If 'false' or not provided, takes a viewport screenshot (standard browser view).
810
813
* @param bool $handleCookiePopup Optional parameter to control cookie/consent popup handling. If 'true', we dismiss cookie banner before capture. If 'false' or not provided, captures the page without that step.
814
+
* @param array<string,string> $headers Optional outbound HTTP headers, using the same JSON object or deep-object query format as other scrape endpoints (for example headers[Authorization]=Bearer token). Headers are scoped to the target origin during capture. For domain/page requests, discovery receives no custom headers and only pages on the resolved origin are eligible. Non-empty headers bypass screenshot caching and return an in-memory data URL; no screenshot is uploaded. Empty objects behave like omitted headers.
811
815
* @param int|null $maxAgeMs Return a cached screenshot if a prior screenshot for the same parameters exists and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always capture fresh.
812
816
* @param int|null $scrollOffset Optional vertical scroll offset in pixels for capturing a long page in viewport-sized chunks. When provided, the full page is captured once and the returned image is the viewport-sized slice that begins at this Y offset (e.g. request scrollOffset=0, then 1080, then 2160 to walk a 1920x1080 landing page top to bottom). The final slice may be shorter than the viewport height. Takes precedence over fullScreenshot. Max: 100000.
813
817
* @param list<string> $tags Comma-separated tags for tracking request usage. Up to 20 tags, each 1-50 characters.
@@ -826,6 +830,7 @@ public function webScrapeScreenshot(
@@ -96,6 +97,14 @@ final class WebScreenshotParams implements BaseModel
96
97
#[Optional]
97
98
public ?bool$handleCookiePopup;
98
99
100
+
/**
101
+
* Optional outbound HTTP headers, using the same JSON object or deep-object query format as other scrape endpoints (for example headers[Authorization]=Bearer token). Headers are scoped to the target origin during capture. For domain/page requests, discovery receives no custom headers and only pages on the resolved origin are eligible. Non-empty headers bypass screenshot caching and return an in-memory data URL; no screenshot is uploaded. Empty objects behave like omitted headers.
102
+
*
103
+
* @var array<string,string>|null $headers
104
+
*/
105
+
#[Optional(map: 'string')]
106
+
public ?array$headers;
107
+
99
108
/**
100
109
* Return a cached screenshot if a prior screenshot for the same parameters exists and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always capture fresh.
@@ -291,6 +303,19 @@ public function withHandleCookiePopup(bool $handleCookiePopup): self
291
303
return$self;
292
304
}
293
305
306
+
/**
307
+
* Optional outbound HTTP headers, using the same JSON object or deep-object query format as other scrape endpoints (for example headers[Authorization]=Bearer token). Headers are scoped to the target origin during capture. For domain/page requests, discovery receives no custom headers and only pages on the resolved origin are eligible. Non-empty headers bypass screenshot caching and return an in-memory data URL; no screenshot is uploaded. Empty objects behave like omitted headers.
308
+
*
309
+
* @param array<string,string> $headers
310
+
*/
311
+
publicfunctionwithHeaders(array$headers): self
312
+
{
313
+
$self = clone$this;
314
+
$self['headers'] = $headers;
315
+
316
+
return$self;
317
+
}
318
+
294
319
/**
295
320
* Return a cached screenshot if a prior screenshot for the same parameters exists and is younger than this many milliseconds. Defaults to 1 day (86400000 ms) when omitted. Max is 30 days (2592000000 ms). Set to 0 to always capture fresh.
0 commit comments