Main difference there is you sort of have to manage the load of the durable objects yourself a bit
Main difference there is you sort of have to manage the load of the durable objects yourself a bit
A browser instance gets killed if it does not get any command for 60 seconds, freeing one instance.
setContent and that html runs some javascript that wants to access a large local json file, can puppeteer somehow access the local filestystem of the worker? Or how would this work?<script> const json = JSON.parse(${rawJson}; ...) and then use page.setContents works, but not sure if this is a performant way to do it.

291b861f09df80526646856f248a8776
setContent<script> const json = JSON.parse(${rawJson}; ...page.setContents291b861f09df80526646856f248a8776 const browser = await pup.launch({
headless: `new`,
defaultViewport: { width: 1920, height: 1080 },
})
const getPageSnapshot = (url, fullPage) => new Promise(async (resolve, reject) => { // this returns a promise resolving to a buffer
const page = await browser.newPage().catch(reject)
await page.goto(url).catch(reject)
resolve(await page.screenshot({
fullPage
}).then(async (r) => { await page.close(); return r }).catch(reject))
}) async handle(
request: Request,
env: any,
context: any,
data: Record<string, any>
) : Promise<Response> {
// some url handling
const browser = await puppeteer.launch(env.MYBROWSER);
const page = await browser.newPage();
await page.setViewport({ width: 1920, height: 1080 })
await page.goto(url);
const screenshot = (await page.screenshot({
fullPage: false,
})) as Buffer;
await browser.close();
return new Response(screenshot, {
headers: {
'Content-Type': `image/jpeg`,
},
});
} await page.goto(url, {
waitUntil: `load`
});