Skip to content

Commit 0d84fa4

Browse files
author
stlc-bot
committed
feat(scrape): support waitForMs for byte downloads (#1170)
Stainless-Generated-From: c8cbb7d292e6d740878c36ffb43edd5d598ca677
1 parent da081b1 commit 0d84fa4

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎pkg/cmd/web.go‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ var webWebCrawlMd = requestflag.WithInnerFlags(cli.Command{
778778

779779
var webWebScrapeBytes = requestflag.WithInnerFlags(cli.Command{
780780
Name: "web-scrape-bytes",
781-
Usage: "Downloads a resource and returns its bytes as base64. Supports images, PDFs,\nHTML pages, and any other content type without image conversion, text\nextraction, or character-encoding changes. HTTP compression is decoded before\nbase64 encoding. HTML is the original HTTP response; JavaScript is not rendered.\nFollows public redirects and retries failed downloads through ISP and\nresidential proxies, with a direct fallback. When country is specified, only a\nresidential proxy in that country is used. Supply headers such as Referer for\nimages that require a referring page. Downloads are not cached. Maximum decoded\nresource size: 20 MiB (20971520 bytes), before base64 encoding. Successful\nrequests cost 1 credit; errors are not billed.",
781+
Usage: "Downloads a resource and returns its bytes as base64. Without waitForMs, returns\nthe original HTTP response without image conversion, text extraction, or\ncharacter-encoding changes. HTTP compression is decoded before base64 encoding.\nSupply waitForMs to render HTML with JavaScript in the browser and return the\nresulting HTML as UTF-8 bytes after the wait. Non-HTML resources, including\nimages and PDFs, keep their original bytes and do not incur a browser wait.\nFollows public redirects and retries failed downloads through ISP and\nresidential proxies, with a direct fallback. When country is specified, only a\nresidential proxy in that country is used. Supply headers such as Referer for\nimages that require a referring page. Downloads are not cached. Maximum decoded\nresource size: 20 MiB (20971520 bytes), before base64 encoding. Successful\nrequests cost 1 credit; errors are not billed.",
782782
Suggest: true,
783783
Flags: []cli.Flag{
784784
&requestflag.Flag[string]{
@@ -807,6 +807,11 @@ var webWebScrapeBytes = requestflag.WithInnerFlags(cli.Command{
807807
Usage: "Optional request deadline and behavior on timeout. For GET requests, use timeoutOpts[milliseconds]=30000&timeoutOpts[behavior]=fail or a JSON-encoded timeoutOpts object.",
808808
QueryPath: "timeoutOpts",
809809
},
810+
&requestflag.Flag[*int64]{
811+
Name: "wait-for-ms",
812+
Usage: "Optional browser wait time after initial page load, in milliseconds (0–30000; 0 uses 500). When supplied, HTML is rendered with JavaScript and returned as UTF-8 bytes. Other resources keep their original bytes without a browser wait. Omit to download the original HTTP response. When combined with timeoutOpts, timeoutOpts.milliseconds must be at least waitForMs + 10000 ms; a shorter deadline is rejected with 400 TIMEOUT_TOO_SHORT_FOR_WAIT.",
813+
QueryPath: "waitForMs",
814+
},
810815
&requestflag.Flag[string]{
811816
Name: "zdr",
812817
Usage: "Set to enabled to bypass shared caches and omit request and response content from retained usage logs. Asset uploads are skipped, so hosted image URLs are omitted. Requires zero data retention to be enabled for your organization (contact support@context.dev), otherwise the request fails with ZDR_NOT_ENABLED. Successful ZDR responses include X-Context-ZDR: true.",

‎pkg/cmd/web_test.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ func TestWebWebScrapeBytes(t *testing.T) {
564564
"--tag", "production",
565565
"--tag", "team-alpha",
566566
"--timeout-opts", "{milliseconds: 1, behavior: fail}",
567+
"--wait-for-ms", "0",
567568
"--zdr", "enabled",
568569
)
569570
})
@@ -584,6 +585,7 @@ func TestWebWebScrapeBytes(t *testing.T) {
584585
"--tag", "team-alpha",
585586
"--timeout-opts.milliseconds", "1",
586587
"--timeout-opts.behavior", "fail",
588+
"--wait-for-ms", "0",
587589
"--zdr", "enabled",
588590
)
589591
})

0 commit comments

Comments
 (0)