Skip to content

Commit

Permalink
Fix: Make sure browser is connected before returning (#4417)
Browse files Browse the repository at this point in the history
  • Loading branch information
chakflying authored Jan 24, 2024
1 parent b4e45c7 commit 288cab6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions server/monitor-types/real-browser-monitor-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const Database = require("../database");
const jwt = require("jsonwebtoken");
const config = require("../config");

/**
* Cached instance of a browser
* @type {import ("playwright-core").Browser}
*/
let browser = null;

let allowedList = [];
Expand Down Expand Up @@ -62,8 +66,15 @@ async function isAllowedChromeExecutable(executablePath) {
return allowedList.includes(executablePath);
}

/**
* Get the current instance of the browser. If there isn't one, create
* it.
* @returns {Promise<import ("playwright-core").Browser>} The browser
*/
async function getBrowser() {
if (!browser) {
if (browser && browser.isConnected()) {
return browser;
} else {
let executablePath = await Settings.get("chromeExecutable");

executablePath = await prepareChromeExecutable(executablePath);
Expand All @@ -72,8 +83,9 @@ async function getBrowser() {
//headless: false,
executablePath,
});

return browser;
}
return browser;
}

async function prepareChromeExecutable(executablePath) {
Expand Down

0 comments on commit 288cab6

Please sign in to comment.