How to save cookies and load it in another puppeteer session? : <p>I had to request the same webpage twice to get the cookies in the 1st request and use it in the 2nd request in the following example.</p>

<p>Could anybody show me the code to save the cookies in one puppeteer session and load it in another session so that there is no need to request the same webpage twice in the 2nd session? Thanks.</p>

<pre><code>const puppeteer = require('puppeteer');

(async () =&gt; {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto('https://www.genecards.org/cgi-bin/carddisp.pl?gene=BSCL2');
    await page.goto('https://www.genecards.org/cgi-bin/carddisp.pl?gene=BSCL2');

    const linkHandlers = await page.$x("//div[@id='enhancers']//a[@data-track-event='Table See-All']");

    if (linkHandlers.length &gt; 0) {
        const [response] = await Promise.all([
            page.waitForResponse(response =&gt; response.url().includes('/gene/api/data/Enhancers')),
            linkHandlers[0].click()
        ]);
        const resp_text = await response.text();
        console.log(resp_text);
    } else {
        throw new Error("Link not found");
    }
    await browser.close();
})();
</code></pre>
