//native
/**
* Get Page as Markdown
* Load a page (url or raw html) in a headless browser and return its content as Markdown. Extra fields go in options (gotoOptions, viewport, waitForSelector, userAgent, ...).
*/
export async function main(
auth: RT.Cloudflare,
url: string | undefined,
html: string | undefined,
options: { [key: string]: any } | undefined
) {
if (!url && !html) throw new Error("Either url or html is required")
const response = await fetch(
`https://api.cloudflare.com/client/v4/accounts/${auth.account_id}/browser-rendering/markdown`,
{
method: "POST",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
url: url || undefined,
html: html || undefined,
...options,
}),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 4 hours ago