@push.rocks/smartpuppeteer 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,10 +2,18 @@ import * as plugins from './smartpuppeteer.plugins.js';
2
2
 
3
3
  export interface IEnvAwareOptions {
4
4
  forceNoSandbox?: boolean;
5
+ requireSandbox?: boolean;
5
6
  usePipe?: boolean;
6
7
  launchOptions?: plugins.puppeteer.LaunchOptions;
7
8
  }
8
9
 
10
+ const sandboxDisablingArguments = [
11
+ '--disable-gpu-sandbox',
12
+ '--disable-seccomp-filter-sandbox',
13
+ '--disable-setuid-sandbox',
14
+ '--no-sandbox',
15
+ ];
16
+
9
17
  export const resolveBrowserExecutablePath = (
10
18
  candidateNamesArg: string[] = [
11
19
  'google-chrome',
@@ -29,15 +37,30 @@ export const getEnvAwareBrowserInstance = async (
29
37
  ): Promise<plugins.puppeteer.Browser> => {
30
38
  const options: IEnvAwareOptions = {
31
39
  forceNoSandbox: false,
40
+ requireSandbox: false,
32
41
  ...optionsArg,
33
42
  };
34
43
 
44
+ if (options.forceNoSandbox && options.requireSandbox) {
45
+ throw new Error('forceNoSandbox and requireSandbox are mutually exclusive');
46
+ }
47
+
35
48
  const launchOptions = options.launchOptions ?? {};
36
49
  let chromeArgs: string[] = [...(launchOptions.args ?? [])];
37
- if (
38
- process.env.CI ||
39
- options.forceNoSandbox ||
40
- plugins.os.userInfo().username === 'root'
50
+ if (options.requireSandbox) {
51
+ const forbiddenArgument = chromeArgs.find((argument) => (
52
+ sandboxDisablingArguments.includes(argument.split('=', 1)[0]!)
53
+ ));
54
+ if (forbiddenArgument) {
55
+ throw new Error(`Sandbox-required browser launch rejects argument: ${forbiddenArgument}`);
56
+ }
57
+ if (process.platform === 'linux' && process.getuid?.() === 0) {
58
+ throw new Error('Sandbox-required Chromium cannot be launched as root');
59
+ }
60
+ } else if (
61
+ process.env.CI
62
+ || options.forceNoSandbox
63
+ || plugins.os.userInfo().username === 'root'
41
64
  ) {
42
65
  for (const sandboxArg of ['--no-sandbox', '--disable-setuid-sandbox']) {
43
66
  if (!chromeArgs.includes(sandboxArg)) {
@@ -23,6 +23,36 @@ export interface ILiveBrowserScreencastOptions {
23
23
  everyNthFrame?: number;
24
24
  }
25
25
 
26
+ export interface ILiveBrowserSecurityOptions {
27
+ denyDownloads?: boolean;
28
+ denyFileChoosers?: boolean;
29
+ denyPermissions?: boolean;
30
+ httpNavigationOnly?: boolean;
31
+ }
32
+
33
+ export interface ILiveBrowserOperationOptions {
34
+ signal?: AbortSignal;
35
+ }
36
+
37
+ export type TLiveBrowserJsonValue =
38
+ | null
39
+ | boolean
40
+ | number
41
+ | string
42
+ | TLiveBrowserJsonValue[]
43
+ | { [key: string]: TLiveBrowserJsonValue };
44
+
45
+ export interface ILiveBrowserEvaluateOptions {
46
+ tabId?: string;
47
+ timeoutMs?: number;
48
+ maxOutputBytes?: number;
49
+ maxDepth?: number;
50
+ maxNodes?: number;
51
+ maxStringBytes?: number;
52
+ maxArrayLength?: number;
53
+ maxObjectKeys?: number;
54
+ }
55
+
26
56
  export type TLiveBrowserLaunchOptions = Omit<
27
57
  NonNullable<IEnvAwareOptions['launchOptions']>,
28
58
  'signal'
@@ -32,6 +62,8 @@ export interface ILiveBrowserSessionOptions extends Omit<IEnvAwareOptions, 'laun
32
62
  launchOptions?: TLiveBrowserLaunchOptions;
33
63
  viewport?: ILiveBrowserViewport;
34
64
  screencast?: ILiveBrowserScreencastOptions;
65
+ security?: ILiveBrowserSecurityOptions;
66
+ allowEvaluation?: boolean;
35
67
  }
36
68
 
37
69
  export interface ILiveBrowserTabState {