single-file-cli 2.0.15 → 2.0.16

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.16",
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,19 +120,9 @@ 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 });
@@ -172,11 +162,12 @@ async function getPageData(options) {
172
162
  });
173
163
  }
174
164
  await Promise.race([Promise.all([pageNavigated, pageReady, debuggerReady]), timeoutReady]);
165
+ Runtime.removeEventListener(CONTEXT_CREATED_EVENT, executionContextCreated);
166
+ await Runtime.disable();
175
167
  if (timeoutId) {
176
168
  clearTimeout(timeoutId);
177
169
  resolveTimeoutReady();
178
170
  }
179
- const contextId = await executionContextIdPromise;
180
171
  const { result } = await Runtime.evaluate({
181
172
  expression: `singlefile.getPageData(${JSON.stringify(options)})`,
182
173
  awaitPromise: true,
@@ -188,6 +179,13 @@ async function getPageData(options) {
188
179
  value.content = new Uint8Array(value.content);
189
180
  }
190
181
  return value;
182
+
183
+ async function executionContextCreated({ params }) {
184
+ const { context } = params;
185
+ if (context.name === SINGLE_FILE_WORLD_NAME && context.auxData && context.auxData.frameId === topFrameId) {
186
+ contextId = context.id;
187
+ }
188
+ }
191
189
  } catch (error) {
192
190
  if (error.code === LOAD_TIMEOUT_ERROR && options.browserWaitUntilFallback && options.browserWaitUntil) {
193
191
  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.16";
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.16",
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