-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from AlecM33/savant-player-arg
Provide chosen player to /pitcher, /pitcher_savant, /batter, /batter_savant, and also re-use browser instance.
- Loading branch information
Showing
12 changed files
with
253 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const puppeteer = require('puppeteer'); | ||
const LOGGER = require('../logger')(process.env.LOG_LEVEL?.trim() || globals.LOG_LEVEL.INFO); | ||
|
||
class ReusableBrowser { | ||
constructor () { | ||
LOGGER.trace('Launching ReusableBrowser...'); | ||
const launchBrowser = async () => { | ||
this.browser = false; | ||
this.browser = await puppeteer.launch({ | ||
headless: true, | ||
args: [ | ||
'--no-sandbox', | ||
'--disable-setuid-sandbox' | ||
] | ||
}); | ||
this.page = await this.browser.newPage(); | ||
this.browser.on('disconnected', launchBrowser); | ||
}; | ||
|
||
(async () => { | ||
await launchBrowser(); | ||
})(); | ||
} | ||
|
||
getCurrentPage = async () => { | ||
if (this.page && !this.page.isClosed()) { | ||
return this.page; | ||
} | ||
this.page = await this.browser.newPage(); | ||
LOGGER.trace('The ReusableBrowser has ' + (await this.browser.pages()).length + ' pages.'); | ||
return this.page; | ||
}; | ||
} | ||
|
||
module.exports = ReusableBrowser; |
Oops, something went wrong.