user1862965
user1862965

Reputation: 386

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

Upvotes: 4

Views: 8212

Answers (2)

aashutosh shrivastav
aashutosh shrivastav

Reputation: 71

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()

Upvotes: 1

user1862965
user1862965

Reputation: 386

I found solution:

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

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

Upvotes: 7

Related Questions