-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Real Browser] close the browser after getBrowser() #3791
base: master
Are you sure you want to change the base?
[Real Browser] close the browser after getBrowser() #3791
Conversation
This probably works, but it may be better for |
Haven't look into this issue yet, but by my design, one browser belongs to one monitor. If the browser closed in here, the next beat should throw an exception unexpectedly. The |
@louislam I have reviewed the code every time async function getBrowser() {
if (!browser) {
let executablePath = await Settings.get("chromeExecutable");
executablePath = await prepareChromeExecutable(executablePath);
browser = await chromium.launch({
//headless: false,
executablePath,
});
}
return browser;
} |
@louislam I updated the code. Can you give me some thoughts/insights on what needs to be done to get rid of this issue? |
async function cleanupBrowser() { | ||
if (browser) { | ||
const contexts = browser.contexts(); | ||
for (const context of contexts) { | ||
await context.clearCookies(); | ||
await context.clearPermissions(); | ||
await context.close(); | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the current design, Uptime Kuma creates one browser instance for multiple monitors.
So I am afraid that your new fix is still not working, as closing all contexts will probably affect other monitors.
As I said before, the current code is working fine on Windows.
Uncommenting headless: false,
can see behind the screens.
However, I don't have a desktop environment right now on Linux, I can't debug it with headless: false
on Linux
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the current design, Uptime Kuma creates one browser instance for multiple monitors.
So I am afraid that your new fix is still not working, as closing all contexts will probably affect other monitors.
that's what I suspected... I will send a fix now.
As I said before, the current code is working fine on Windows.
Uncommenting headless: false, can see behind the screens.
As I posted in
#3788 there are many chromium processes/tabs left opened after check() is called, and needs to be closed to prevent the DoS.
Tick the checkbox if you understand [x]:
Description
This fixes High CPU Usage after enabling the Web Driver (#3788).
This PR focuses on improving the cleanup process after each monitoring check in the
server/monitor-types/real-browser-monitor-type.js
file. The main changes include the introduction of a newcleanupBrowser
function, which is responsible for terminating all browser processes and clearing the cache, and the replacement of thecontext.close()
method with the newcleanupBrowser
function in theRealBrowserMonitorType
class.Here are the key changes:
server/monitor-types/real-browser-monitor-type.js
: Added a newcleanupBrowser
function that terminates all browser processes and clears the cache after each monitoring check. This function loops through all contexts of the browser, clears cookies and permissions, and then closes the context.server/monitor-types/real-browser-monitor-type.js
: Replaced thecontext.close()
method with the newcleanupBrowser
function in theRealBrowserMonitorType
class. This ensures that the cleanup process is executed after each monitoring check.Type of change
Please delete any options that are not relevant.
Checklist
(including JSDoc for methods)
Screenshots (if any)