问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/55837273/how-do-we-pass-authentication-token-in-headless-chrome-in-google-puppeteer