Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we pass authentication token in headless chrome in google puppeteer?

I want to pass authentication token(JWT) in puppeteer headers, for the pdf view with headless chrome in my application? We are using react as our front-end UI. And using puppeteer we are able to generate pdf, but the link to pdf we need to authorize using JWT How do we pass the jwt in headers, does puppeteer support Auth token in headers? Please help.

Thanks

like image 391
uppu Avatar asked Apr 24 '19 19:04

uppu


1 Answers

To pass additional headers in the request, you can use the function page.setExtraHTTPHeaders.

Quote from the docs linked above:

The extra HTTP headers will be sent with every request the page initiates.

Example:

page.setExtraHTTPHeaders({
    'Token': '...', 
});

All following requests will then have the additional header Token with the set value.

like image 188
Thomas Dondorf Avatar answered Sep 28 '22 07:09

Thomas Dondorf