Skip to content

Commit

Permalink
Added the browserShellMode option along with some readme tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulDalek committed May 23, 2024
1 parent 0d0bb18 commit e86e39c
Show file tree
Hide file tree
Showing 10 changed files with 257 additions and 157 deletions.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ OTHER_NODE_ENV = production
OTHER_LISTEN_TO_PROCESS_EXITS = true
OTHER_NO_LOGO = false
OTHER_HARD_RESET_PAGE = false
OTHER_BROWSER_SHELL_MODE = true

# DEBUG CONFIG
DEBUG_ENABLE = false
Expand Down
76 changes: 40 additions & 36 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/index.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.esm.js.map

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,22 @@ export function get() {
* instance are reached, or if no browser instance is found after retries.
*/
export async function create(puppeteerArgs) {
// Get debug and other options
const { debug, other } = getOptions();

// Get the debug options
const { enable: enabledDebug, ...debug } = getOptions().debug;
const { enable: enabledDebug, ...debugOptions } = debug;

const launchOptions = {
headless: 'shell',
headless: other.browserShellMode ? 'shell' : true,
userDataDir: './tmp/',
args: puppeteerArgs,
handleSIGINT: false,
handleSIGTERM: false,
handleSIGHUP: false,
waitForInitialPage: false,
defaultViewport: null,
...(enabledDebug && debug)
...(enabledDebug && debugOptions)
};

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

try {
await open();

// Shell mode inform
if (launchOptions.headless === 'shell') {
log(3, `[browser] Launched browser in shell mode.`);
}

// Debug mode inform
if (enabledDebug) {
log(3, `[browser] Launched browser in debug mode.`);
Expand Down
1 change: 1 addition & 0 deletions lib/envs.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export const Config = z.object({
OTHER_LISTEN_TO_PROCESS_EXITS: v.boolean(),
OTHER_NO_LOGO: v.boolean(),
OTHER_HARD_RESET_PAGE: v.boolean(),
OTHER_BROWSER_SHELL_MODE: v.boolean(),

// debugger
DEBUG_ENABLE: v.boolean(),
Expand Down
12 changes: 12 additions & 0 deletions lib/schemas/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,12 @@ export const defaultConfig = {
type: 'boolean',
envLink: 'OTHER_HARD_RESET_PAGE',
description: 'Decides if the page content should be reset entirely.'
},
browserShellMode: {
value: true,
type: 'boolean',
envLink: 'OTHER_BROWSER_SHELL_MODE',
description: 'Decides if the browser runs in the shell mode.'
}
},
debug: {
Expand Down Expand Up @@ -1040,6 +1046,12 @@ export const promptsConfig = {
name: 'hardResetPage',
message: 'Decides if the page content should be reset entirely',
initial: defaultConfig.other.hardResetPage.value
},
{
type: 'toggle',
name: 'browserShellMode',
message: 'Decides if the browser runs in the shell mode',
initial: defaultConfig.other.browserShellMode.value
}
],
debug: [
Expand Down
Loading

0 comments on commit e86e39c

Please sign in to comment.