single-file-cli 2.0.30 → 2.0.32

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.
package/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@single-file/single-file-cli",
3
- "version": "2.0.30",
3
+ "version": "2.0.32",
4
4
  "description": "SingleFile CLI",
5
5
  "nodeModulesDir": true,
6
6
  "exports": {
package/lib/browser.js CHANGED
@@ -25,6 +25,8 @@ import { BROWSER_PATHS, BROWSER_ARGS } from "./constants.js";
25
25
  import { Deno } from "./deno-polyfill.js";
26
26
 
27
27
  const PIPED_STD_CONFIG = "piped";
28
+ const DEBUG_PORT_MIN = 9222;
29
+ const DEBUG_PORT_RANGE = 256;
28
30
 
29
31
  const { build, makeTempDir, Command, errors, remove } = Deno;
30
32
  let child, profilePath;
@@ -32,10 +34,10 @@ export { launchBrowser, closeBrowser };
32
34
 
33
35
  async function launchBrowser(options = {}, indexPath = 0) {
34
36
  const executablePath = options.executablePath || BROWSER_PATHS[build.os][indexPath];
35
- const args = Array.from(BROWSER_ARGS);
36
- profilePath = await makeTempDir();
37
+ let args = Array.from(BROWSER_ARGS);
37
38
  const debugPort = await getDebugPort();
38
39
  args.push("--remote-debugging-port=" + debugPort);
40
+ profilePath = await makeTempDir();
39
41
  if (options.headless && !options.debug) {
40
42
  args.push("--headless");
41
43
  } else {
@@ -58,8 +60,13 @@ async function launchBrowser(options = {}, indexPath = 0) {
58
60
  }
59
61
  args.push("--user-data-dir=" + profilePath);
60
62
  if (options.args) {
63
+ const argNames = options.args.map(arg => arg.split("=")[0]);
64
+ args = args.filter(arg => !argNames.includes(arg.split("=")[0]));
61
65
  args.push(...options.args);
62
66
  }
67
+ if (options.args.includes("--headless=new") || args.includes("--auto-open-devtools-for-tabs")) {
68
+ args.push("--disable-site-isolation-trials");
69
+ }
63
70
  const command = new Command(executablePath, { args, stdout: PIPED_STD_CONFIG, stderr: PIPED_STD_CONFIG });
64
71
  try {
65
72
  child = await command.spawn();
@@ -78,19 +85,28 @@ async function launchBrowser(options = {}, indexPath = 0) {
78
85
  return debugPort;
79
86
  }
80
87
 
81
- async function getDebugPort(port = 9222) {
88
+ async function getDebugPort(port = getRandomDebugPort(), usedPorts = []) {
82
89
  try {
83
90
  await fetch("http://localhost:" + port + "/json/version");
84
91
  } catch (error) {
85
92
  return port;
86
93
  }
87
- if (port < 9286) {
88
- return getDebugPort(port + 1);
94
+ if (usedPorts.length < DEBUG_PORT_RANGE) {
95
+ usedPorts.push(port);
96
+ do {
97
+ port = getRandomDebugPort();
98
+ } while (usedPorts.includes(port));
99
+ return getDebugPort(port, usedPorts);
89
100
  } else {
90
101
  throw new Error("No available debugging port");
91
102
  }
92
103
  }
93
104
 
105
+
106
+ function getRandomDebugPort() {
107
+ return Math.floor(Math.random() * DEBUG_PORT_RANGE) + DEBUG_PORT_MIN;
108
+ }
109
+
94
110
  async function closeBrowser() {
95
111
  if (child !== undefined) {
96
112
  child.kill();
package/lib/constants.js CHANGED
@@ -35,7 +35,6 @@ const BROWSER_ARGS = [
35
35
  "--no-default-browser-check",
36
36
  "--disable-default-apps",
37
37
  "--disable-dev-shm-usage",
38
- "--disable-extensions",
39
38
  "--disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate,HttpsUpgrades,PaintHolding",
40
39
  "--disable-hang-monitor",
41
40
  "--disable-ipc-flooding-protection",
package/lib/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "2.0.30";
1
+ export const version = "2.0.32";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-cli",
3
- "version": "2.0.30",
3
+ "version": "2.0.32",
4
4
  "description": "SingleFile CLI",
5
5
  "author": "Gildas Lormeau",
6
6
  "engines": {
@@ -28,8 +28,16 @@ import options from "./options.js";
28
28
 
29
29
  const { readTextFile, exit, addSignalListener } = Deno;
30
30
 
31
- addSignalListener("SIGTERM", closeBrowserAndExit);
32
- addSignalListener("SIGINT", closeBrowserAndExit);
31
+ try {
32
+ addSignalListener("SIGTERM", closeBrowserAndExit);
33
+ } catch (_error) {
34
+ // ignored
35
+ }
36
+ try {
37
+ addSignalListener("SIGINT", closeBrowserAndExit);
38
+ } catch (_error) {
39
+ // ignored
40
+ }
33
41
 
34
42
  export { run };
35
43