asad
asad
CDCloudflare Developers
Created by asad on 4/16/2024 in #workers-help
Browser Rendering Error: 429
Hey, I have a simple browser-rendering API worker (code below). But I frequently get this error: Error: Unabled to create new browser: code: 429: message: Too many browsers already running It happens locally when testing with —remote but also in prod. I had to switch my backend to another service as my tool went viral this weekend. My code to get html for a url:
import puppeteer from "@cloudflare/puppeteer";

let browser;
export default {
async fetch(request, env, ctx) {
const { searchParams } = new URL(request.url);
let url = searchParams.get("url");
if (!url) {
return new Response("Missing url parameter", { status: 400 });
}
url = new URL(url).toString(); // normalize
console.log(`Fetching ${url}`);
const browser = await puppeteer.launch(env.MYBROWSER);
const page = await browser.newPage();
await page.goto(url, { waitUntil: 'networkidle0' });
const data = await page.content();
await browser.close();
// send as txt
return new Response(data, {
headers: {
"content-type": "text/plain",
},
});

},
};
import puppeteer from "@cloudflare/puppeteer";

let browser;
export default {
async fetch(request, env, ctx) {
const { searchParams } = new URL(request.url);
let url = searchParams.get("url");
if (!url) {
return new Response("Missing url parameter", { status: 400 });
}
url = new URL(url).toString(); // normalize
console.log(`Fetching ${url}`);
const browser = await puppeteer.launch(env.MYBROWSER);
const page = await browser.newPage();
await page.goto(url, { waitUntil: 'networkidle0' });
const data = await page.content();
await browser.close();
// send as txt
return new Response(data, {
headers: {
"content-type": "text/plain",
},
});

},
};
7 replies
CDCloudflare Developers
Created by asad on 3/20/2024 in #workers-help
Durable Objects are restarted on code change
I have noticed that if I push a new code update, all durable objects are recreated. Is it possible to do a rolling update? I don't want to kill existing DOs and let them use the old code. If not, is it expected that pushing new code will just restart my prod service and disrupt all state?
1 replies