title: How to pass dynamic page automation commands to puppeteer from external file?
body: <p>I'm trying to pass dynamic page automation commands to puppeteer from an external file.  I'm new to puppeteer and node so I apologize in advance.</p>
  
  <pre><code>// app.js
  // ========
  
  app.get('/test', (req, res) =&gt; 
  (async () =&gt; {
  
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('http://testurl.com');
  
  var events = require('./events.json');
  
  for(var i=0;i&lt;events.length;i++){
    var tmp = events[i];
    await page.evaluate((tmp) =&gt; {  return Promise.resolve(tmp.event); }, tmp);   
  } 
  
  await browser.close();    
  })());
  </code></pre>
  
  <p>My events json file looks like:</p>
  
  <pre><code>// events.json
  // ========
  
    [
      {
          "event":"page.waitFor(4000)"
      },
      {
          "event":"page.click('#aLogin')"
      },
      {
          "event":"page.waitFor(1000)"
      }
  ]
  </code></pre>
  
  <p>I've tried several variations of the above as well as importing a module that passes the page object to one of the module function, but nothing has worked.  Can anyone tell me if this is possible and, if so, how to better achieve this?</p>