Skip to main content

Browserbase

Browserbase is a developer platform to reliably run, manage, and monitor headless browsers.

Power your AI data retrievals with:

Installation and Setupโ€‹

  • Get an API key and Project ID from browserbase.com and set it in environment variables (BROWSERBASE_API_KEY, BROWSERBASE_PROJECT_ID).
  • Install the Browserbase SDK:
% pip install browserbase

Loading documentsโ€‹

You can load webpages into LangChain using BrowserbaseLoader. Optionally, you can set text_content parameter to convert the pages to text-only representation.

from langchain_community.document_loaders import BrowserbaseLoader
API Reference:BrowserbaseLoader
loader = BrowserbaseLoader(
urls=[
"https://example.com",
],
# Text mode
text_content=False,
)

docs = loader.load()
print(docs[0].page_content[:61])

Loader Optionsโ€‹

  • urls Required. A list of URLs to fetch.
  • text_content Retrieve only text content. Default is False.
  • api_key Optional. Browserbase API key. Default is BROWSERBASE_API_KEY env variable.
  • project_id Optional. Browserbase Project ID. Default is BROWSERBASE_PROJECT_ID env variable.
  • session_id Optional. Provide an existing Session ID.
  • proxy Optional. Enable/Disable Proxies.

Loading imagesโ€‹

You can also load screenshots of webpages (as bytes) for multi-modal models.

Full example using GPT-4V:

from browserbase import Browserbase
from browserbase.helpers.gpt4 import GPT4VImage, GPT4VImageDetail
from langchain_core.messages import HumanMessage
from langchain_openai import ChatOpenAI

chat = ChatOpenAI(model="gpt-4-vision-preview", max_tokens=256)
browser = Browserbase()

screenshot = browser.screenshot("https://browserbase.com")

result = chat.invoke(
[
HumanMessage(
content=[
{"type": "text", "text": "What color is the logo?"},
GPT4VImage(screenshot, GPT4VImageDetail.auto),
]
)
]
)

print(result.content)
API Reference:HumanMessage | ChatOpenAI

Was this page helpful?


You can also leave detailed feedback on GitHub.