
AI Development
AdsCrawl for LangChain
Use AdsCrawl as the browser layer of a LangChain application. Wrap the JavaScript SDK in a LangChain tool to fetch a live page, return readable Markdown and keep its source URL alongside the content.
What you can do
A callable web tool
Define a URL input with Zod and expose read_web_page through LangChain’s tool interface.
Fresh page context
Retrieve browser-rendered text when a task needs information from a known URL.
Traceable answers
Return source and markdown together so downstream chains can cite the page.
Before you start
- An AdsCrawl account with an API key and available credits.
- Node.js 22.22 or newer, running on your server or local development machine.
SETUP METHOD 01
Create a LangChain tool
Use the official AdsCrawl SDK with LangChain’s custom tool API. The first call works without configuring a language model.
Install dependencies
Run this in your application directory.
npm install adscrawl @langchain/core zodConfigure your API key
Set the variables in your server environment or local shell. Replace the placeholders with your own keys; keep them out of browser bundles and source control.
export ADSCRAWL_API_KEY="your_adscrawl_api_key"Save langchain-web.mjs
The tool validates the URL, reads the page and returns a JSON string containing source and markdown. The example invokes the tool directly.
import AdsCrawl from "adscrawl"; import { tool } from "@langchain/core/tools"; import { z } from "zod"; const browser = new AdsCrawl({ apiKey: process.env.ADSCRAWL_API_KEY }); export const readWebPage = tool( async ({ url }) => { const markdown = await browser.markdown({ url, waitUntil: "domcontentloaded", }); if (!markdown.trim()) throw new Error("The page returned no text"); return JSON.stringify({ source: url, markdown }); }, { name: "read_web_page", description: "Read a public web page as browser-rendered Markdown, with its source URL.", schema: z.object({ url: z.string().url() }), }, ); const result = await readWebPage.invoke({ url: "https://example.com" }); console.log(JSON.parse(result));Run and connect the next step
Expect a source URL and Markdown headed Example Domain. Register readWebPage in your LangChain agent’s tools list to let the agent call it. Configure your chosen model separately; ask the agent to cite source when using the result.
node langchain-web.mjs
Usage & limits
- This guide defines a custom tool; it does not install a separate native AdsCrawl–LangChain package. Search, multi-page crawling and a vector store are not included in this example.
- Each page request uses AdsCrawl credits. These examples fetch one public URL; JavaScript-rendered pages may need a different waitUntil setting or additional browser interactions.
- Keep the source URL with the content. For longer pages, choose a chunking or context-budget strategy before passing text to a model.