Skip to content

Commit

Permalink
fix(cli): support --no-sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
atjn committed Aug 24, 2024
1 parent ad30b21 commit 6c86998
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ export default {
alias: 'n',
default: false,
},
sandbox: {
type: 'boolean',
default: true,
},
},

CHROME_LAUNCH_ARGS: [
Expand Down
22 changes: 13 additions & 9 deletions src/helpers/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,25 @@ const getDefaultOptions = (): Options => {
};

const normalizeSandboxOption = (
noSandbox: boolean | undefined,
options: CLIOptions,
logger: LoggerFunction,
): Partial<Options> => {
let sandboxDisabled = false;
if (noSandbox) {
if (os.platform() !== 'linux') {
logger.warn(
'Disabling sandbox is only relevant on Linux platforms, request declined!',
);
} else {
sandboxDisabled = true;
}
if (options.noSandbox === true) {
sandboxDisabled = true;
}
if (options.sandbox === false) {
sandboxDisabled = true;
}
if (sandboxDisabled && os.platform() !== 'linux') {
logger.warn(
'Disabling sandbox is only relevant on Linux platforms, request declined!',
);
sandboxDisabled = false;
}
return {
noSandbox: sandboxDisabled,
sandbox: !sandboxDisabled,
};
};

Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function generateImages(
options,
logger,
),
...flags.normalizeSandboxOption(options.noSandbox, logger),
...flags.normalizeSandboxOption(options, logger),
};
} else {
modOptions = {
Expand Down
7 changes: 7 additions & 0 deletions src/models/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ export interface Options {
@default false
*/
readonly noSandbox: boolean;

/**
Enable sandbox on bundled Chromium on Linux platforms - recommended
@default true
*/
readonly sandbox: boolean;
}

export type CLIOptions = Partial<Options>;

0 comments on commit 6c86998

Please sign in to comment.