0
0

More than 1 year has passed since last update.

puppeteerのpage.evaluateに引数を渡す方法

Posted at

サーバーでChrome動かしてスクリーンショット撮ったり色々するnode.jsプログラムで少し詰まったため備忘録

結論

外のスコープから変数を一つ渡したい場合

sample.js
const a = 100;
page.evaluate(a=> {
    console.log(a)
},a);

複数の引数を渡す場合

sample.js
const a = 100;
const b = 200;
page.evaluate((a,b)=> {
    window.scrollTo(a,b);
},a,b);

以下の書き方見やすくておすすめ

sample.js
page.evaluate(({a,b,c,d})=> {
    ~
},{a,b,c,d});
0
0
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
0
0