1
This commit is contained in:
@@ -6,6 +6,18 @@ import { apply_page_stealth_defaults, get_stealth_puppeteer } from './puppeteer_
|
||||
|
||||
let browser_singleton = null;
|
||||
|
||||
export async function close_browser() {
|
||||
if (!browser_singleton) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await browser_singleton.close();
|
||||
} catch (err) {
|
||||
// ignore
|
||||
}
|
||||
browser_singleton = null;
|
||||
}
|
||||
|
||||
function get_action_timeout_ms() {
|
||||
const cfg = get_app_config();
|
||||
return cfg.crawler.action_timeout_ms;
|
||||
@@ -94,7 +106,7 @@ export async function get_or_create_browser() {
|
||||
return browser_singleton;
|
||||
}
|
||||
|
||||
export async function invoke_extension_action(action_name, action_payload) {
|
||||
export async function invoke_extension_action(action_name, action_payload, options) {
|
||||
const cfg = get_app_config();
|
||||
const browser = await get_or_create_browser();
|
||||
|
||||
@@ -189,13 +201,9 @@ export async function invoke_extension_action(action_name, action_payload) {
|
||||
}
|
||||
}
|
||||
|
||||
if (cfg.crawler.auto_close_browser) {
|
||||
try {
|
||||
await browser.close();
|
||||
} catch (err) {
|
||||
// ignore
|
||||
}
|
||||
browser_singleton = null;
|
||||
const keep_browser_open = options && options.keep_browser_open === true;
|
||||
if (cfg.crawler.auto_close_browser && !keep_browser_open) {
|
||||
await close_browser();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user