I'm working on an Express JS API for converting base64 HTML to PDF.
I'm using Puppeteer for this conversion. Within the HTML code, there is an image hosted on a dedicated server that requires authentication. I'm encountering an issue when trying to retrieve the image from this third-party server. In Chromium with "headless: false" mode, I'm receiving these errors:
**"Failed to load resource: net::ERR_BLOCKED_BY_ORB." **
Please note that the cookie is present in Chromium.
(I'm also experiencing CORS policy problems when loading Google fonts.)
My errors here:
→ My puppeteer code :
export class PdfManager {
async convertToPdf({ content, jwtToken }: HtmlToPdfTypes) {
const cookie = [
{
name: "user",
value: jwtToken,
domain: ".mysubdomain.domain.com",
httpOnly: false,
secure: false,
hostOnly: false,
},
];
const browser = await puppeteer.launch({
headless: false,
args: [
// "--disable-web-security",
"--no-sandbox",
],
});
const page = await browser.newPage();
await page.setCookie(...cookie);
const htmlContent = Buffer.from(content, "base64").toString();
await page.setContent(htmlContent);
const pdf = await page.pdf({
format: "A4",
printBackground: true,
});
// await browser.close();
return pdf;
}
}
→ My app.ts code:
const app = express();
app.use(bodyParser.json({ limit: "10mb" }));
app.use(
bodyParser.urlencoded({
extended: true,
limit: "10mb",
parameterLimit: 50000,
})
);
app.use(express.json());
app.use(
cors({
credentials: true,
origin: process.env.FRONTEND_URL,
optionsSuccessStatus: 200,
})
);
app.use(router);
app.use(express.static(path.join(__dirname, "../public")));
export default app;
I've tried adding Helmet, but it hasn't improved the situation. I've also attempted to use "--disable-web-security" with puppeteer.launch for testing, but I'm receiving a 403 error.
I do my tests locally, and the image is stored on a Java/spring server.
Thank you for your responses.
-I tried to add Helmet dependency/ received no results. -I tried to disable web security in Chromium / received "Failed to load resource: the server responded with a status of 403 ()". -I tried using crossorigin="anonymous" in my tag / didn't work
