{"size": 1551, "ext": "js", "max_stars_repo_path": "experiments/pupscript.js", "max_stars_repo_name": "MadhuNimmo/jalangi2", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "experiments/pupscript.js", "max_issues_repo_name": "MadhuNimmo/jalangi2", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "experiments/pupscript.js", "max_forks_repo_name": "MadhuNimmo/jalangi2", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.2641509434, "max_line_length": 101, "alphanum_fraction": 0.6125080593}
const puppeteer = require('puppeteer');
var express = require('express');
var app = express();
const path_to_basic_app = process.argv[2];
const port = process.argv[3]
app.use(express.static(path_to_basic_app));
// app.use(express.static(main));
app.get('/', function(req, res) {
    res.sendFile('index.html');
});
var server = app.listen(port);

(async () => {
    if (!process.env.BASEURL) {
        console.log('Please specify a base url. E.g. `BASEURL=http://example.org node exercise.js`');
    } else {
      var browser;
      
      if (process.env.DEBUG) {
        browser = await puppeteer.launch({
            headless: false, 
            // executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
        });
      } else {
        browser = await puppeteer.launch();
      }
  
      const page = await browser.newPage()
      page.setDefaultNavigationTimeout(120000) //2 mins
  
      const pageOptions = {waitUntil: 'domcontentloaded'}
      const selectorOptions = {"timeout": 120000} //2 mins
  
      try {
        //Add error handling here in case the endpoint is not ready.
        console.log(process.env.BASEURL + 'index.html')
        await page.goto(process.env.BASEURL + 'index.html', pageOptions);
      } catch (error) {
        console.log(error);
        browser.close();
      }

      await page.waitFor(10000)

      await page.goto(process.env.BASEURL  + '/index.html#secondpage', pageOptions)
      
      await page.waitFor(10000)
  
      browser.close()
      server.close()
    }
  })()
  