Skip to content

Commit 20db2d0

Browse files
authored
feat(api): fetch accepts allowedDomains (#235)
* feat(api): fetch accepts allowedDomains * fix lint: sort the example's imports
1 parent 2346447 commit 20db2d0

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎examples/fetch_allowed_domains.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from examples import bb
2+
from browserbase import BadRequestError
3+
4+
5+
def run() -> None:
6+
# A host on the list (or a subdomain of one) is fetched as usual.
7+
page = bb.fetch_api.create(
8+
url="https://example.com/",
9+
allowed_domains=["example.com"],
10+
)
11+
print(f"Fetched {page.status_code} from example.com")
12+
13+
# Any other host, or a redirect to one, is rejected with a 400 before it is reached.
14+
try:
15+
bb.fetch_api.create(
16+
url="https://example.com/",
17+
allowed_domains=["example.org"],
18+
)
19+
except BadRequestError as error:
20+
print(f"Blocked: {error.message}")
21+
22+
23+
if __name__ == "__main__":
24+
run()

0 commit comments

Comments
 (0)