title: Running a loop within an instance of Puppeteer
body: <p>Just getting started with Puppeteer and i can launch the browser, go to a url, run a bunch of actions and then close the browser. What i am looking to see if i can do though is open the browser and loop over a set of actions in the same session.</p>
  
  <p>I have a JSON object with urls i want to visit, so want to loop over that</p>
  
  <pre><code>// teams.js
  module.exports = {
    premier_league: [
      { team_name: "Team 1", url: "https://url-of-site/team_1"},
      { team_name: "Team 2", url: "https://url-of-site/team_2"}
    ]
  }
  </code></pre>
  
  <p>My script to launch puppeteer is as follows</p>
  
  <pre><code>// index.js
  const TEAM = require('./teams');
  const puppeteer = require('puppeteer');
  
  (async () =&gt; {
    // Initialise Browser
    const browser = await puppeteer.launch({headless: false});
    const page = await browser.newPage();
    await page.setViewport({
      width: 1280,
      height: 800
    });
    await page.goto('login page');
  
    await page.click('login_box');
    await page.keyboard.type('username');
  
    await page.click('login_password');
    await page.keyboard.type('password');
  
    await page.click('login_button');
    await page.waitForNavigation();
  
    // Go To Team URL
    await page.goto('Team URL')
  
    await browser.close();
  })();
  </code></pre>
  
  <p>So to loop over my JSON object I can use </p>
  
  <pre><code>Object.keys(TEAM['premier_league']).forEach(function(key) {
  
    // Output url of each team
    console.log(TEAM['premier_league'][key]['url'])
  
  });
  </code></pre>
  
  <p>If i wrap my go to url with my loop, then <code>page</code> is no longer accessible</p>
  
  <pre><code>// index.js
  const TEAM = require('./teams');
  const puppeteer = require('puppeteer');
  
  (async () =&gt; {
    // Initialise Browser
    const browser = await puppeteer.launch({headless: false});
    const page = await browser.newPage();
    await page.setViewport({
      width: 1280,
      height: 800
    });
    await page.goto('login page');
  
    await page.click('login_box');
    await page.keyboard.type('username');
  
    await page.click('login_password');
    await page.keyboard.type('password');
  
    await page.click('login_button');
    await page.waitForNavigation();
  
    Object.keys(TEAM['premier_league']).forEach(function(key) {
  
      // Go To Team URL
      await page.goto(TEAM['premier_league'][key]['url'])
  
    });
  
    await browser.close();
  })();
  </code></pre>
  
  <p>The actual error is</p>
  
  <pre><code>await page.goto(TEAM[args][key]['url'])
      ^^^^
  
  SyntaxError: Unexpected identifier
  </code></pre>