async function pageFunction(context) {
const { page, request, log } = context;
import fs from 'fs';
await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: './my-downloads'})
await page.click('span.dig-Button-content:contains("Download")');
const fileNames = fs.readdirSync('./my-downloads');
// Let's pick the first one
const fileData = fs.readFileSync(`./my-downloads/${fileNames[0]}`);
const base64PDF = Buffer.from(fileData).toString('base64');
return {
url: request.url,
base64PDF: base64PDF
};
}
async function pageFunction(context) {
const { page, request, log } = context;
import fs from 'fs';
await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: './my-downloads'})
await page.click('span.dig-Button-content:contains("Download")');
const fileNames = fs.readdirSync('./my-downloads');
// Let's pick the first one
const fileData = fs.readFileSync(`./my-downloads/${fileNames[0]}`);
const base64PDF = Buffer.from(fileData).toString('base64');
return {
url: request.url,
base64PDF: base64PDF
};
}