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

流过昼夜 提交于 2020-01-24 05:41:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!