single-file-cli 2.0.23 → 2.0.24

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.23",
3
+ "version": "2.0.24",
4
4
  "description": "SingleFile CLI",
5
5
  "nodeModulesDir": true,
6
6
  "exports": {
package/lib/cdp-client.js CHANGED
@@ -34,7 +34,7 @@ const MINIMIZED_WINDOW_STATE = "minimized";
34
34
  const SINGLE_FILE_WORLD_NAME = "singlefile";
35
35
  const EMPTY_PAGE_URL = "about:blank";
36
36
 
37
- export { initialize, getPageData, closeBrowser };
37
+ export { initialize, getPageData, hasTargets, closeBrowser };
38
38
 
39
39
  async function initialize(options) {
40
40
  if (options.browserRemoteDebuggingURL) {
@@ -45,10 +45,11 @@ async function initialize(options) {
45
45
  }
46
46
 
47
47
  async function getPageData(options) {
48
+ let Browser, Security, Page, Emulation, Fetch, Network, Runtime, Debugger, Target;
48
49
  let targetInfo;
49
50
  try {
50
51
  targetInfo = await CDP.createTarget(EMPTY_PAGE_URL);
51
- const { Browser, Security, Page, Emulation, Fetch, Network, Runtime, Debugger } = new CDP(targetInfo);
52
+ ({ Browser, Security, Page, Emulation, Fetch, Network, Runtime, Debugger, Target } = new CDP(targetInfo));
52
53
  if (options.browserStartMinimized) {
53
54
  const { windowId, bounds } = await Browser.getWindowForTarget({ targetId: targetInfo.id });
54
55
  if (bounds.windowState !== MINIMIZED_WINDOW_STATE) {
@@ -130,12 +131,17 @@ async function getPageData(options) {
130
131
  }
131
132
  throw error;
132
133
  } finally {
133
- if (targetInfo && !options.browserDebug) {
134
+ if (targetInfo) {
134
135
  await CDP.closeTarget(targetInfo.id);
135
136
  }
136
137
  }
137
138
  }
138
139
 
140
+ async function hasTargets() {
141
+ const targets = await CDP.getTargets();
142
+ return targets.filter(target => target.type === "page").length > 0;
143
+ }
144
+
139
145
  async function loadPage({ Page, Runtime }, options) {
140
146
  await Runtime.enable();
141
147
  await Page.enable();
package/lib/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "2.0.23";
1
+ export const version = "2.0.24";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-cli",
3
- "version": "2.0.23",
3
+ "version": "2.0.24",
4
4
  "description": "SingleFile CLI",
5
5
  "author": "Gildas Lormeau",
6
6
  "engines": {
@@ -151,7 +151,7 @@ async function finish(options) {
151
151
  }
152
152
  }
153
153
  }
154
- if (!options.browserDebug) {
154
+ if (!options.browserDebug && !options.browserRemoteDebuggingURL && !(await backend.hasTargets())) {
155
155
  return backend.closeBrowser();
156
156
  }
157
157
  }
@@ -206,7 +206,7 @@ function createTask(url, options, parentTask, rootTask) {
206
206
  if (!VALID_URL_TEST.test(url)) {
207
207
  try {
208
208
  url = url.replace(/\\/g, "/");
209
- url = url.replace(/#/g, "%23");
209
+ url = url.replace(/#/g, "%23");
210
210
  url = new URL(url, import.meta.url).href;
211
211
  } catch (error) {
212
212
  throw new Error("Invalid URL or file path: " + url);
@@ -21,8 +21,6 @@
21
21
  * Source.
22
22
  */
23
23
 
24
- /* global URL */
25
-
26
24
  import { initialize } from "./single-file-cli-api.js";
27
25
  import { Deno } from "./lib/deno-polyfill.js";
28
26
  import options from "./options.js";