single-file-cli 2.0.15 → 2.0.17

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/README.MD CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Introduction
4
4
 
5
- SingleFile can be launched from the command line by running it into a (headless) browser.
5
+ [SingleFile](https://github.com/gildas-lormeau/SingleFile) can be launched from the command line by running it into a (headless) browser.
6
6
 
7
7
  It runs through Deno as a standalone script injected into the web page via the Chrome DevTools Protocol instead of being embedded into a WebExtension.
8
8
 
package/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@single-file/single-file-cli",
3
- "version": "2.0.15",
3
+ "version": "2.0.17",
4
4
  "description": "SingleFile CLI",
5
5
  "nodeModulesDir": true,
6
6
  "exports": {
package/lib/cdp-client.js CHANGED
@@ -110,7 +110,7 @@ async function getPageData(options) {
110
110
  });
111
111
  }
112
112
  await Page.addScriptToEvaluateOnNewDocument({
113
- source: await getHookScriptSource(),
113
+ source: getHookScriptSource(),
114
114
  runImmediately: true
115
115
  });
116
116
  await Page.addScriptToEvaluateOnNewDocument({
@@ -120,26 +120,18 @@ async function getPageData(options) {
120
120
  });
121
121
  await Runtime.enable();
122
122
  const topFrameId = targetInfo.id;
123
- const executionContextIdPromise = new Promise(resolve => {
124
- const CONTEXT_CREATED_EVENT = "executionContextCreated";
125
- Runtime.addEventListener(CONTEXT_CREATED_EVENT, executionContextCreated);
126
-
127
- async function executionContextCreated({ params }) {
128
- const { context } = params;
129
- if (context.name === SINGLE_FILE_WORLD_NAME && context.auxData && context.auxData.frameId === topFrameId) {
130
- Runtime.removeEventListener(CONTEXT_CREATED_EVENT, executionContextCreated);
131
- await Runtime.disable();
132
- resolve(context.id);
133
- }
134
- }
135
- });
123
+ let contextId;
124
+ const CONTEXT_CREATED_EVENT = "executionContextCreated";
125
+ Runtime.addEventListener(CONTEXT_CREATED_EVENT, executionContextCreated);
136
126
  await Page.enable();
137
127
  await Page.setLifecycleEventsEnabled({ enabled: true });
138
128
  const pageNavigated = Page.navigate({ url: options.url });
139
129
  const pageReady = new Promise(resolve => {
140
130
  const LIFE_CYCLE_EVENT = "lifecycleEvent";
131
+ const FRAME_NAVIGATED_EVENT = "frameNavigated";
141
132
  let contentLoaded;
142
133
  Page.addEventListener(LIFE_CYCLE_EVENT, onLifecycleEvent);
134
+ Page.addEventListener(FRAME_NAVIGATED_EVENT, onFrameNavigated);
143
135
 
144
136
  async function onLifecycleEvent({ params }) {
145
137
  const { name, frameId } = params;
@@ -152,6 +144,7 @@ async function getPageData(options) {
152
144
  setTimeout(() => resolve, options.browserWaitDelay);
153
145
  } else {
154
146
  Page.removeEventListener(LIFE_CYCLE_EVENT, onLifecycleEvent);
147
+ Page.removeEventListener(FRAME_NAVIGATED_EVENT, onFrameNavigated);
155
148
  await Page.setLifecycleEventsEnabled({ enabled: false });
156
149
  await Page.disable();
157
150
  resolve();
@@ -159,6 +152,13 @@ async function getPageData(options) {
159
152
  }
160
153
  }
161
154
  }
155
+
156
+ async function onFrameNavigated({ params }) {
157
+ const { frame } = params;
158
+ if (!frame.parentId) {
159
+ contextId = undefined;
160
+ }
161
+ }
162
162
  });
163
163
  let timeoutReady, timeoutId, resolveTimeoutReady;
164
164
  if (options.browserLoadMaxTime) {
@@ -172,11 +172,12 @@ async function getPageData(options) {
172
172
  });
173
173
  }
174
174
  await Promise.race([Promise.all([pageNavigated, pageReady, debuggerReady]), timeoutReady]);
175
+ Runtime.removeEventListener(CONTEXT_CREATED_EVENT, executionContextCreated);
176
+ await Runtime.disable();
175
177
  if (timeoutId) {
176
178
  clearTimeout(timeoutId);
177
179
  resolveTimeoutReady();
178
180
  }
179
- const contextId = await executionContextIdPromise;
180
181
  const { result } = await Runtime.evaluate({
181
182
  expression: `singlefile.getPageData(${JSON.stringify(options)})`,
182
183
  awaitPromise: true,
@@ -188,6 +189,13 @@ async function getPageData(options) {
188
189
  value.content = new Uint8Array(value.content);
189
190
  }
190
191
  return value;
192
+
193
+ async function executionContextCreated({ params }) {
194
+ const { context } = params;
195
+ if (contextId === undefined && context.name === SINGLE_FILE_WORLD_NAME && context.auxData && context.auxData.frameId === topFrameId) {
196
+ contextId = context.id;
197
+ }
198
+ }
191
199
  } catch (error) {
192
200
  if (error.code === LOAD_TIMEOUT_ERROR && options.browserWaitUntilFallback && options.browserWaitUntil) {
193
201
  const browserWaitUntil = NETWORK_STATES[(NETWORK_STATES.indexOf(options.browserWaitUntil) + 1)];
@@ -70,11 +70,11 @@ async function getScriptSource(options) {
70
70
  return source;
71
71
  }
72
72
 
73
- async function getHookScriptSource() {
73
+ function getHookScriptSource() {
74
74
  return hookScript;
75
75
  }
76
76
 
77
- async function getZipScriptSource() {
77
+ function getZipScriptSource() {
78
78
  return zipScript;
79
79
  }
80
80
 
package/lib/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "2.0.15";
1
+ export const version = "2.0.17";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-cli",
3
- "version": "2.0.15",
3
+ "version": "2.0.17",
4
4
  "description": "SingleFile CLI",
5
5
  "author": "Gildas Lormeau",
6
6
  "engines": {
@@ -240,7 +240,7 @@ function getHostURL(url) {
240
240
  async function capturePage(options) {
241
241
  try {
242
242
  let filename;
243
- options.zipScript = await getZipScriptSource();
243
+ options.zipScript = getZipScriptSource();
244
244
  const pageData = await backend.getPageData(options);
245
245
  if (options.output) {
246
246
  filename = await getFilename(options.output, options);
File without changes
File without changes