Skip to content

Commit ced7b17

Browse files
authored
Merge pull request #530 from highcharts/enhancement/added-browser-shell-flag
enhancement/added-browser-shell-flag
2 parents 0d0bb18 + 0a5f25c commit ced7b17

File tree

12 files changed

+261
-160
lines changed

12 files changed

+261
-160
lines changed

.env.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ OTHER_NODE_ENV = production
7272
OTHER_LISTEN_TO_PROCESS_EXITS = true
7373
OTHER_NO_LOGO = false
7474
OTHER_HARD_RESET_PAGE = false
75+
OTHER_BROWSER_SHELL_MODE = true
7576

7677
# DEBUG CONFIG
7778
DEBUG_ENABLE = false

.puppeteerrc.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const {join} = require('path');
1+
const { join } = require('path');
22

33
/**
44
* @type {import("puppeteer").Configuration}
55
*/
66
module.exports = {
7-
cacheDirectory: join(__dirname, 'node_modules', '.puppeteer-cache'),
7+
cacheDirectory: join(__dirname, 'node_modules', '.puppeteer-cache')
88
};

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ _Enhancements:_
2020
- Optimized code by reducing evaluate function calls to enhance performance and minimize jumping between NodeJS and browser processes.
2121
- Optimized and moved chart creation initialization scripts from the HTML template to a separate module named `highcharts.js`.
2222
- Optimized the `clearPage` function to ensure content cleaning is only performed once, during resource release.
23-
- Introduced `hardResetPage` option for resetting the page's content (including Highcharts scripts) each time the page is released to the pool (defaulting to `false`).
23+
- Introduced the `hardResetPage` option for resetting the page's content (including Highcharts scripts) each time the page is released to the pool (defaulting to `false`).
24+
- Introduced the `browserShellMode` option for controlling the mode in which the browser runs (new or old, `shell` mode).
2425
- Optimized creating and acquiring pages from the pool.
2526
- Optimized adding and releasing additional JS and CSS resources.
2627
- Made corrections for gracefully shutting down resources, including running servers, ongoing intervals, browser instance, created pages, and workers pool.

README.md

Lines changed: 40 additions & 36 deletions
Large diffs are not rendered by default.

dist/index.cjs

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

dist/index.esm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.esm.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/browser.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,22 @@ export function get() {
5858
* instance are reached, or if no browser instance is found after retries.
5959
*/
6060
export async function create(puppeteerArgs) {
61+
// Get debug and other options
62+
const { debug, other } = getOptions();
63+
6164
// Get the debug options
62-
const { enable: enabledDebug, ...debug } = getOptions().debug;
65+
const { enable: enabledDebug, ...debugOptions } = debug;
66+
6367
const launchOptions = {
64-
headless: 'shell',
68+
headless: other.browserShellMode ? 'shell' : true,
6569
userDataDir: './tmp/',
6670
args: puppeteerArgs,
6771
handleSIGINT: false,
6872
handleSIGTERM: false,
6973
handleSIGHUP: false,
7074
waitForInitialPage: false,
7175
defaultViewport: null,
72-
...(enabledDebug && debug)
76+
...(enabledDebug && debugOptions)
7377
};
7478

7579
// Create a browser
@@ -103,6 +107,12 @@ export async function create(puppeteerArgs) {
103107

104108
try {
105109
await open();
110+
111+
// Shell mode inform
112+
if (launchOptions.headless === 'shell') {
113+
log(3, `[browser] Launched browser in shell mode.`);
114+
}
115+
106116
// Debug mode inform
107117
if (enabledDebug) {
108118
log(3, `[browser] Launched browser in debug mode.`);

lib/envs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ export const Config = z.object({
204204
OTHER_LISTEN_TO_PROCESS_EXITS: v.boolean(),
205205
OTHER_NO_LOGO: v.boolean(),
206206
OTHER_HARD_RESET_PAGE: v.boolean(),
207+
OTHER_BROWSER_SHELL_MODE: v.boolean(),
207208

208209
// debugger
209210
DEBUG_ENABLE: v.boolean(),

lib/schemas/config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,12 @@ export const defaultConfig = {
618618
type: 'boolean',
619619
envLink: 'OTHER_HARD_RESET_PAGE',
620620
description: 'Decides if the page content should be reset entirely.'
621+
},
622+
browserShellMode: {
623+
value: true,
624+
type: 'boolean',
625+
envLink: 'OTHER_BROWSER_SHELL_MODE',
626+
description: 'Decides if the browser runs in the shell mode.'
621627
}
622628
},
623629
debug: {
@@ -1040,6 +1046,12 @@ export const promptsConfig = {
10401046
name: 'hardResetPage',
10411047
message: 'Decides if the page content should be reset entirely',
10421048
initial: defaultConfig.other.hardResetPage.value
1049+
},
1050+
{
1051+
type: 'toggle',
1052+
name: 'browserShellMode',
1053+
message: 'Decides if the browser runs in the shell mode',
1054+
initial: defaultConfig.other.browserShellMode.value
10431055
}
10441056
],
10451057
debug: [

0 commit comments

Comments
 (0)