Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

puppeteer/playwright: How to get Authorization: Bearer token and pass to request (eg axios)?

I'm logged in to the web page, navigate to the destination web page with puppeteer/playwright and want to download a csv file with request.

The request headers include Authorization: "Bearer eyJ0eXAiOiJKV......"

is it possible to get Authorization: "Bearer Token" from puppeteer/playwright and submit it to request (eg axios).

Thnx a lot

like image 967
user1862965 Avatar asked Oct 24 '25 14:10

user1862965


2 Answers

I found solution:

 var accessTokenObj = await crPage.evaluate(() => {
      return localStorage.getItem("TokenName");
    });

an then put accessTokenObj into axios header Authorization: Bearer ${accessTokenObj}

like image 115
user1862965 Avatar answered Oct 26 '25 05:10

user1862965


Since I couldn't find crPage,I used page from playwright to get authorization token.

var token = page.evaluate(localStorage.getItem("access_token")); playwright docs ! for page.evaluate()

like image 32
aashutosh shrivastav Avatar answered Oct 26 '25 03:10

aashutosh shrivastav



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!