Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/add-get-markdown.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@browserbasehq/browse-cli": patch
---

Add `browse get markdown [selector]` command to convert page HTML to markdown. Defaults to body content, supports optional selector for specific elements. Uses node-html-markdown for high-quality conversion with links, tables, and code blocks preserved.
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@browserbasehq/stagehand": "workspace:*",
"commander": "^12.0.0",
"dotenv": "^16.4.5",
"node-html-markdown": "^1.3.0",
"pino": "^9.6.0",
"pino-pretty": "^13.0.0",
"ws": "^8.18.0"
Expand Down
8 changes: 7 additions & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as readline from "readline";
import type { Protocol } from "devtools-protocol";
import { version as VERSION } from "../package.json";
import { resolveWsTarget } from "./resolve-ws";
import { NodeHtmlMarkdown } from "node-html-markdown";

const program = new Command();

Expand Down Expand Up @@ -1231,6 +1232,11 @@ async function executeCommand(
.deepLocator(resolveSelector(selector!))
.isChecked(),
};
case "markdown": {
const target = selector ? resolveSelector(selector) : "body";
const html = await page!.deepLocator(target).innerHtml();
return { markdown: NodeHtmlMarkdown.translate(html) };
}
default:
throw new Error(`Unknown get type: ${what}`);
}
Expand Down Expand Up @@ -2465,7 +2471,7 @@ program
program
.command("get <what> [selector]")
.description(
"Get page info: url, title, text, html, value, box, visible, checked",
"Get page info: url, title, text, html, markdown, value, box, visible, checked",
)
.action(async (what: string, selector?: string) => {
const opts = program.opts<GlobalOpts>();
Expand Down
91 changes: 91 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading