Skip to content

Commit

Permalink
relaunch browser on disconnect (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsnq authored Dec 13, 2022
1 parent 3eeb952 commit 92d90d8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,23 @@ const closeContextRouter = require('./routes/close_context');

const app = express();

const HEADLESS = (process.env.HEADLESS || "true").toLowerCase() === "true";
const VIEWPORT_WIDTH = parseInt(process.env.VIEWPORT_WIDTH) || 1280;
const VIEWPORT_HEIGHT = parseInt(process.env.VIEWPORT_HEIGHT) || 720;

(async () => {
//TODO add params for puppeteer launch
async function setupBrowser() {
//TODO add params for puppeteer launch
const browser = await puppeteer.launch(
{
headless: true,
defaultViewport: { width: VIEWPORT_WIDTH, height: VIEWPORT_HEIGHT }
});
{
headless: HEADLESS,
defaultViewport: { width: VIEWPORT_WIDTH, height: VIEWPORT_HEIGHT }
});
browser.on('disconnected', setupBrowser);
app.set('browser', browser);
}

(async () => {
await setupBrowser();
app.set('lock', new AsyncLock());
})();

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scrapy-puppeteer-service",
"version": "0.0.6",
"version": "0.0.7",
"private": true,
"scripts": {
"start": "node ./bin/www"
Expand Down

0 comments on commit 92d90d8

Please sign in to comment.