1

I am messing with Puppeteer and I am having trouble getting it to take a PDF of a new page.

I can get a PDF of the initial URL just fine, but if I try to get a PDF of a page I open via clicking on a link, it just takes a PDF of the initial page like always.

This is my code:

const puppeteer = require('puppeteer');

async function takePDF(){
    const browser = await puppeteer.launch({
       slowMo:500, defaultViewport:null
    });
    
    const page = await browser.newPage();

    startUrl = 'https://www.google.com/';

    await page.goto(startUrl);

    await page.mouse.click(1030,468, { button: 'left'});    //click I'm Feeling Lucky

    await page.pdf({path: 'screenshot.pdf'});   //take pdf of I'm Feeling Lucky Results

    browser.close();
}

takePDF();

Do I have to fetch the URL and explicitly tell it it's on a new page now? Thanks.

  • try adding some wait time after the click. You might just be taking a screenshot before the page redirects – async await Oct 29 '21 at 23:40
  • 2
    Does this answer your question? [Puppeteer wait page load after form submit](https://stackoverflow.com/questions/46948489/puppeteer-wait-page-load-after-form-submit) – Ugur Eren Oct 30 '21 at 00:05
  • Try a waitFor before page.pdf it could be help you. – judlup Oct 30 '21 at 00:19

0 Answers0