Skip to content
Snippets Groups Projects
Commit b82e967f authored by Etienne LOUPIAS's avatar Etienne LOUPIAS
Browse files

comment

parent a90d13d4
No related branches found
No related tags found
1 merge request!455Improve publication on LinkedIn
......@@ -92,8 +92,8 @@ async function getPage(url: string, waitUntil: PuppeteerLifeCycleEvent): Promise
});
const page = await browser.newPage();
await page.goto(url, { waitUntil: waitUntil });
return { page, browser };
}
......@@ -120,7 +120,10 @@ export async function generatePDF(url: string): Promise<Uint8Array> {
export async function renderPage(url: string): Promise<string> {
let browser, page;
try {
({ page, browser } = await getPage(url, 'load')); // wait until only the page is loaded, not all network ressources (cf. https://www.browserless.io/blog/waituntil-option-for-puppeteer-and-playwright )
// We use renderPage to generate html meta tags, so we wait only until the page is loaded, not all network ressources (cf. https://www.browserless.io/blog/waituntil-option-for-puppeteer-and-playwright )
// ("waitUntil: 'networkidle0'" fails with timeout error on appsoc server where outgoing connections are closed)
({ page, browser } = await getPage(url, 'load'));
// We sleep for a bit to let the page load (we don't use waitForSelector function because we don't know which page is requested and which tag to wait ; https://stackoverflow.com/questions/52497252/puppeteer-wait-until-page-is-completely-loaded/61304202 )
await setTimeout(2000);
// Puppeteer generated HTML (with computed og meta html tags, for LinkedIn post publication)
......@@ -131,7 +134,6 @@ export async function renderPage(url: string): Promise<string> {
throw error;
} finally {
if (browser) {
// When using the KEEP_ALIVE flag, we need to replace browser.close() with browser.disconnect() (https://docs.browserless.io/v1/docker/config#keeping-chrome-alive )
await browser.close();
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment