Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Oct 9, 2017
1 parent 1205e99 commit c01ee89
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
43 changes: 25 additions & 18 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ class App {
return this;
}
async run() {
// open the browser
this.browser = await puppeteer.launch({
headless: config.isProduction
});

// create a new tab
this.page = await this.browser.newPage();

// set the browser's viewport
await this.page.setViewport({
width: 1366,
height: 768
});

// listen on tab dialog, like alert, confirm
this.page.on('dialog', async dialog => {
console.log(dialog.message());
await dialog.dismiss();
});

const entities = this.entities;
for (let i = 0; i < entities.length; i++) {
const entity = entities[i];
Expand Down Expand Up @@ -80,20 +100,12 @@ class App {
await util.sleep(2000);
}
}

// close the browser
await page.close();
await browser.close();
}
async bootstrap(options = {}) {
const browser = (this.browser = await puppeteer.launch({
headless: config.isProduction
}));
const page = (this.page = await browser.newPage());
await page.setViewport({
width: 1366,
height: 768
});
page.on('dialog', async dialog => {
console.log(dialog.message());
await dialog.dismiss();
});
async bootstrap() {
const entities = this.providers
.map(Provider => new Provider())
.filter(entity => entity.active === true);
Expand All @@ -114,11 +126,6 @@ class App {
await util.sleep(1000 * 10);
}
}

if (options.autoClose === true) {
await page.close();
await browser.close();
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ new App({
once: isProduction === false
})
.resolveProviders('./app/providers/')
.bootstrap({ autoClose: false });
.bootstrap();

0 comments on commit c01ee89

Please sign in to comment.