I get the following errors when trying to run a function with Puppeteer library using the Bun 1.0 runtime.
An internal curl error has occurred within the executor! Error Number: 6. Error Msg: Could not resolve host: someId\nError Code: 500
An internal curl error has occurred within the executor! Error Number: 104. Error Msg: Connection reset by peer\nError Code: 500
Full code below:
Full code:
import axios from "axios";
import { execSync } from "node:child_process";
import puppeteer from "puppeteer";
let installed = false;
// This is your Appwrite function
// It's executed each time we get a request
export default async ({ req, res, log, error }: any) => {
// Why not try the Appwrite SDK?
//
// const client = new Client()
// .setEndpoint('https://cloud.appwrite.io/v1')
// .setProject(Bun.env["APPWRITE_FUNCTION_PROJECT_ID"])
// .setKey(Bun.env["APPWRITE_API_KEY"]);
// Init!
log("Function Invocation Started");
// You can log messages to the console
log("Hello, Logs!");
// If something goes wrong, log an error
error("Hello, Errors!");
// The `req` object contains the request data
if (req.method === "POST") {
try {
// Assuming the body is already parsed as JSON
const { url } = JSON.parse(req.body);
// Validate the URL
if (!url || typeof url !== "string") {
return res.json(
{ error: "Invalid or missing url ", data: url },
400
);
}
log(`Fetching HTML content for: ${url}`);
// Use Axios to fetch the HTML content
const response = await axios.get(url, {
// Axios config: Receive response as a string
responseType: "text",
});
if (response.data) {
// Return the HTML content
return res.send(response.data);
} else {
if (!installed) {
try {
log("Installing Chromium...");
execSync(
"apk update && apk add chromium nss freetype harfbuzz ca-certificates ttf-freefont",
{ stdio: "inherit" }
);
log("Chromium installed successfully...");
installed = true;
} catch (installError) {
log(`Error installing```
```Chromium: ${installError});
return res.send(
Error installing Chromium: ${installError.message}`
);
}
} else {
log("Chromium already installed.");
}
try {
const browser = await puppeteer.launch({
headless: true,
executablePath:
process.env.PUPPETEER_EXECUTABLE_PATH || "chromium-browser",
args: ["--no-sandbox", "--disable-gpu", "--disable-dev-shm-usage"],
});
log("Puppeteer launched successfully.");
const page = await browser.newPage();
log("Browser page opened.");
const response = await page.goto(url, {
waitUntil: "networkidle0",
});
log(`Page loaded with status code: ${response.status()}`);
const content = await page.content();
log("Content retrieved.");
await browser.close();
log("Browser session closed.");```
if (content) {
return res.send(content);
} else {
return res.send("No HTML document was found for the given URL");
}
} catch (error) {
error(`Error during Puppeteer operations: ${error}`);
return res.send(`Error: ${error.message}`);
}
}
} catch (err) {
error(`Error fetching document: ${err.message}`);
return res.json({ error: `Could not fetch document: ${err.message}` }, 500);
}
} else {
// Method not allowed
return res.json({ error: "Method Not Allowed" }, 405);
}
};```
Image of executions
Recommended threads
- Realtime with multiple connections
I need the Realtime on multiple Collections for diffrent applicational logic. So my question is: Is there a way to have only 1 Websocket connection or do I need...
- Can't login or deploy functions in Appwr...
Hello, since i updatet to the appwrite cli 6.1.0 i can't login or deploy functions with the cli. When i call the command: "appwrite get account --verbose" i ge...
- Create admin user?
I'm not really sure how this is supposed to work, I installed Appwrite through docker-compose and set it up. When I launched the app and went into it, I created...