Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions examples/fetch_allowed_domains.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from examples import bb
from browserbase import BadRequestError


def run() -> None:
# A host on the list (or a subdomain of one) is fetched as usual.
page = bb.fetch_api.create(
url="https://example.com/",
allowed_domains=["example.com"],
)
print(f"Fetched {page.status_code} from example.com")

# Any other host, or a redirect to one, is rejected with a 400 before it is reached.
try:
bb.fetch_api.create(
url="https://example.com/",
allowed_domains=["example.org"],
)
except BadRequestError as error:
print(f"Blocked: {error.message}")


if __name__ == "__main__":
run()
Loading