single-file-cli 2.0.28 → 2.0.29

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.28",
3
+ "version": "2.0.29",
4
4
  "description": "SingleFile CLI",
5
5
  "nodeModulesDir": true,
6
6
  "exports": {
package/lib/cdp-client.js CHANGED
@@ -116,7 +116,7 @@ async function getPageData(options) {
116
116
  if (subtype === "error") {
117
117
  throw new Error(description);
118
118
  }
119
- if (options.compressContent) {
119
+ if (Array.isArray(value.content)) {
120
120
  value.content = new Uint8Array(value.content);
121
121
  }
122
122
  return value;
@@ -162,12 +162,10 @@ async function loadPage({ Page, Runtime }, options) {
162
162
  }
163
163
 
164
164
  async function getTopFrameContextId({ Page, Runtime }, options) {
165
- const FRAME_NAVIGATED_EVENT = "frameNavigated";
166
165
  const CONTEXT_CREATED_EVENT = "executionContextCreated";
167
166
  const contextIds = [];
168
167
  let topFrameId;
169
168
  try {
170
- Page.addEventListener(FRAME_NAVIGATED_EVENT, onFrameNavigated);
171
169
  Runtime.addEventListener(CONTEXT_CREATED_EVENT, onExecutionContextCreated);
172
170
  await waitForPageReady({ Page }, options);
173
171
  const contextId = await getContextId();
@@ -177,21 +175,9 @@ async function getTopFrameContextId({ Page, Runtime }, options) {
177
175
  return contextId;
178
176
  }
179
177
  } finally {
180
- Page.removeEventListener(FRAME_NAVIGATED_EVENT, onFrameNavigated);
181
178
  Runtime.removeEventListener(CONTEXT_CREATED_EVENT, onExecutionContextCreated);
182
179
  }
183
180
 
184
- function onFrameNavigated({ params }) {
185
- const { frame } = params;
186
- if (!frame.parentId) {
187
- if (frame.unreachableUrl) {
188
- throw new Error("Unreachable URL: " + frame.unreachableUrl);
189
- } else {
190
- topFrameId = frame.id;
191
- }
192
- }
193
- }
194
-
195
181
  function onExecutionContextCreated({ params }) {
196
182
  const { context } = params;
197
183
  const { name, auxData = {} } = context;
@@ -203,17 +189,36 @@ async function getTopFrameContextId({ Page, Runtime }, options) {
203
189
  async function waitForPageReady({ Page }, options) {
204
190
  await Page.setLifecycleEventsEnabled({ enabled: true });
205
191
  try {
206
- await new Promise(resolve => {
192
+ await new Promise((resolve, reject) => {
207
193
  const LIFE_CYCLE_EVENT = "lifecycleEvent";
194
+ const FRAME_NAVIGATED_EVENT = "frameNavigated";
208
195
  Page.addEventListener(LIFE_CYCLE_EVENT, onLifecycleEvent);
196
+ Page.addEventListener(FRAME_NAVIGATED_EVENT, onFrameNavigated);
209
197
 
210
198
  function onLifecycleEvent({ params }) {
211
199
  const { frameId, name } = params;
212
200
  if (frameId === topFrameId && (name === options.browserWaitUntil || name === DEFAULT_NETWORK_STATE)) {
213
- Page.removeEventListener(LIFE_CYCLE_EVENT, onLifecycleEvent);
201
+ removeListeners();
214
202
  resolve();
215
203
  }
216
204
  }
205
+
206
+ function onFrameNavigated({ params }) {
207
+ const { frame } = params;
208
+ if (!frame.parentId) {
209
+ if (frame.unreachableUrl) {
210
+ removeListeners();
211
+ reject(new Error("Unreachable URL: " + frame.unreachableUrl));
212
+ } else {
213
+ topFrameId = frame.id;
214
+ }
215
+ }
216
+ }
217
+
218
+ function removeListeners() {
219
+ Page.removeEventListener(LIFE_CYCLE_EVENT, onLifecycleEvent);
220
+ Page.removeEventListener(FRAME_NAVIGATED_EVENT, onFrameNavigated);
221
+ }
217
222
  });
218
223
  } finally {
219
224
  await Page.setLifecycleEventsEnabled({ enabled: false });
package/lib/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "2.0.28";
1
+ export const version = "2.0.29";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-cli",
3
- "version": "2.0.28",
3
+ "version": "2.0.29",
4
4
  "description": "SingleFile CLI",
5
5
  "author": "Gildas Lormeau",
6
6
  "engines": {
@@ -28,15 +28,8 @@ import options from "./options.js";
28
28
 
29
29
  const { readTextFile, exit, addSignalListener } = Deno;
30
30
 
31
- addSignalListener("SIGTERM", async () => {
32
- await closeBrowser();
33
- exit();
34
- });
35
-
36
- addSignalListener("SIGINT", async () => {
37
- await closeBrowser();
38
- exit();
39
- });
31
+ addSignalListener("SIGTERM", closeBrowserAndExit);
32
+ addSignalListener("SIGINT", closeBrowserAndExit);
40
33
 
41
34
  export { run };
42
35
 
@@ -116,3 +109,8 @@ function parseCookies(textValue) {
116
109
  })
117
110
  .filter(cookieData => cookieData);
118
111
  }
112
+
113
+ async function closeBrowserAndExit() {
114
+ await closeBrowser();
115
+ exit();
116
+ }