Skip to content
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

enhancement/added-browser-shell-flag #530

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading