Skip to content

Commit

Permalink
Merge pull request #43 from ECLK/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
MrClemRkz authored Jul 31, 2020
2 parents 30424b5 + 7fd9f83 commit 9e682a9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ config.json
.DS_Store
package-lock.json
static/exports
.env
.env
report.*
24 changes: 22 additions & 2 deletions handlers/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ module.exports = async function(req, res) {
}

if (!global.browser) {
const browser = await puppeteer.launch({ args: ['--no-sandbox'] })
await reGenerateBrowser();
}
const page = await global.browser.newPage();
const page = await getNewPageFromBrowser();
page.setDefaultNavigationTimeout(0);
if (req.body.url) {
await page.goto(req.body.url);
Expand All @@ -72,6 +72,26 @@ module.exports = async function(req, res) {
});
}

async function getNewPageFromBrowser() {
const newPage = await global.browser.newPage().catch( (e) => {
console.log("Browser instance seems to be dead.")
})

if (newPage) {
return newPage;
} else {
await reGenerateBrowser();
console.log("Created a new page instance.");
return await global.browser.newPage()
}

}

async function reGenerateBrowser() {
global.browser = await puppeteer.launch({ args: ['--disable-gpu', '--no-sandbox', '--disable-dev-shm-usage'] });
console.log('Browser instance regenerated.')
}

function revisedRandId() {
return Math.random().toString(36).replace(/[^a-z]+/g, '').substr(2, 10);
}
2 changes: 1 addition & 1 deletion puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const puppeteer = require('puppeteer');
const config = require('./config');
const headlessState = true;

puppeteer.launch({ headless: headlessState, args: ['--no-sandbox', '--disable-dev-shm-usage'] }).then(function(browser) {
puppeteer.launch({ headless: headlessState, args: ['--disable-gpu', '--no-sandbox', '--disable-dev-shm-usage'] }).then(function(browser) {
global.browser = browser;
console.log('browser ready');
});
2 changes: 1 addition & 1 deletion purge_expired.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ function purgeExpired() {
}
}
});
}
}

0 comments on commit 9e682a9

Please sign in to comment.