Skip to content

Commit

Permalink
use browserless v1 instead of v2 to keep alive
Browse files Browse the repository at this point in the history
  • Loading branch information
lluisd committed Apr 12, 2024
1 parent 73bb185 commit 02043a4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main_twitch-mz-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
envKey_EXTERNAL_URL: ${{ secrets.EXTERNAL_URL }}
envKey_BROWSERLESS_URL: ${{ secrets.BROWSERLESS_URL }}
envKey_BROWSERLESS_TOKEN: ${{ secrets.BROWSERLESS_TOKEN }}
envKey_BROWSERLESS_VERSION: v1
envKey_MYSQL_HOST: ${{ secrets.MYSQL_HOST }}
envKey_MYSQL_USER: ${{ secrets.MYSQL_USER }}
envKey_MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }}
Expand Down
3 changes: 2 additions & 1 deletion config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module.exports = {
},
browserless: {
url: process.env.BROWSERLESS_URL,
token: process.env.BROWSERLESS_TOKEN
token: process.env.BROWSERLESS_TOKEN,
version: process.env.BROWSERLESS_VERISON
},
mariadb: {
host: process.env.MYSQL_HOST,
Expand Down
12 changes: 7 additions & 5 deletions helpers/browserApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ class PuppeteerApi {
svgImage = null

async createNewBrowser() {
const launchArgs = JSON.stringify({
args: ["--no-sandbox", "--window-size=1920,1080", "--disable-infobars", "--disable-setuid-sandbox", "--start-maximized", "--use-gl=angle", "--use-angle=gl"],
});
//
const url = `${config.browserless.url}/chrome?token=${config.browserless.token}&launch=${btoa(launchArgs)}&blockAds=true`
let url = `${config.browserless.url}?token=${config.browserless.token}`
if (config.browserless.version === 'v2') {
const launchArgs = JSON.stringify({
args: ["--no-sandbox", "--window-size=1920,1080", "--disable-infobars", "--disable-setuid-sandbox", "--start-maximized", "--use-gl=angle", "--use-angle=gl"],
});
url = `${config.browserless.url}/chrome?token=${config.browserless.token}&launch=${btoa(launchArgs)}&blockAds=true`
}
this.browser = await puppeteer.connect({ browserWSEndpoint: url, defaultViewport : null })
this.browser.on('disconnected', async () => {
console.log('disconnected browser')
Expand Down

0 comments on commit 02043a4

Please sign in to comment.