uppu
uppu

Reputation: 83

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

Upvotes: 8

Views: 9902

Answers (1)

Thomas Dondorf
Thomas Dondorf

Reputation: 25270

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.

Upvotes: 11

Related Questions