4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

puppeteerでpageがリダイレクトされたかを確認する

Posted at

puppeteerはgotoメソッドの戻り値として最終的な遷移先のレスポンスを返し、
途中にリダイレクトが挟まれたかなどを隠蔽してくれている

だが、ときどきページ遷移がリダイレクトを経由しているかが知りたい場合がある
そういう場合はredirectChain メソッドを使うと経由したURLを確認できる

let response = await page.goto('https://httpbin.org/redirect/3');
let redirectCount = response.request().redirectChain().length;
console.log(redirectCount)  // => 3

参考

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?