single-file-cli 2.9.0 → 2.9.2

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/build-dev.sh CHANGED
@@ -92,7 +92,9 @@ const hookScript = await Deno.readTextFile('lib-dev/single-file-hooks-frames.js'
92
92
  script += 'const hookScript = ' + JSON.stringify(hookScript) + ';';
93
93
  const zipScript = await Deno.readTextFile('lib-dev/zip.min.js');
94
94
  script += 'const zipScript = ' + JSON.stringify(zipScript) + ';';
95
- script += 'export { script, zipScript, hookScript };';
95
+ const webStreamsPonyfill = await Deno.readTextFile('node_modules/web-streams-polyfill/dist/ponyfill.js');
96
+ script += 'const webStreamsPonyfill = ' + JSON.stringify(webStreamsPonyfill) + ';';
97
+ script += 'export { script, zipScript, hookScript, webStreamsPonyfill };';
96
98
  await Deno.writeTextFile('lib-dev/single-file-bundle.js', script)
97
99
  await Promise.all(SCRIPTS.map(script => Deno.remove(script)));
98
100
  await Deno.remove('lib-dev/single-file-hooks-frames.js');
package/build.sh CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  set -e
4
4
 
5
- CORE_PACKAGE="npm:single-file-core@1.5.121"
5
+ CORE_PACKAGE="npm:single-file-core@1.5.123"
6
6
  ESBUILD_PACKAGE="npm:esbuild@0.27.7"
7
7
  WEB_STREAMS_PACKAGE="npm:web-streams-polyfill@4.3.0"
8
8
 
package/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@single-file/single-file-cli",
3
- "version": "2.9.0",
3
+ "version": "2.9.2",
4
4
  "description": "SingleFile CLI",
5
5
  "exports": {
6
6
  ".": "./single-file-cli-api.js"
@@ -34,6 +34,8 @@ import {
34
34
  FETCH_FUNCTION_NAME,
35
35
  RESOLVE_FETCH_FUNCTION_NAME,
36
36
  REJECT_FETCH_FUNCTION_NAME,
37
+ SCRIPT_READY_PROPERTY_NAME,
38
+ SCRIPT_ERROR_PROPERTY_NAME,
37
39
  getScriptSource,
38
40
  getHookScriptSource,
39
41
  getPageDataScriptSource
@@ -65,7 +67,7 @@ const PRINT_TO_PDF_FUNCTION_NAME = "printToPDF";
65
67
  const SET_SCREENSHOT_FUNCTION_NAME = "setScreenshot";
66
68
  const SET_PDF_FUNCTION_NAME = "setPDF";
67
69
  const SET_PAGE_DATA_FUNCTION_NAME = "setPageData";
68
- const SINGLE_FILE_GLOBAL_DECLARATION = "var singlefile=";
70
+ const SINGLE_FILE_GLOBAL_DECLARATION = /var singlefile\s*=\s*/;
69
71
  const SINGLE_FILE_GLOBAL_ASSIGNMENT = "globalThis.singlefile=window.singlefile=";
70
72
  const SERVER_CONNECT_TIMEOUT = 30000;
71
73
  const SESSION_TIMEOUT = 120000;
@@ -1100,7 +1102,7 @@ function waitForPageReadyState(state, waitUntil, pageContext) {
1100
1102
  }
1101
1103
 
1102
1104
  async function checkSingleFileContext(pageContext) {
1103
- const SINGLE_FILE_DETECTION_TEST = "typeof singlefile !== 'undefined'";
1105
+ const SINGLE_FILE_DETECTION_TEST = "typeof singlefile !== 'undefined' && globalThis." + SCRIPT_READY_PROPERTY_NAME + " === true";
1104
1106
  const NO_VALID_CONTEXT_ERROR_MESSAGE = "No valid SingleFile execution context found";
1105
1107
  const { context } = pageContext;
1106
1108
  logData(["Getting execution context"], pageContext);
@@ -1110,10 +1112,19 @@ async function checkSingleFileContext(pageContext) {
1110
1112
  awaitPromise: false
1111
1113
  });
1112
1114
  if (!result || result.value !== true) {
1113
- throw new Error(NO_VALID_CONTEXT_ERROR_MESSAGE);
1115
+ throw new Error(NO_VALID_CONTEXT_ERROR_MESSAGE + await getInjectionErrorSuffix(context));
1114
1116
  }
1115
1117
  }
1116
1118
 
1119
+ async function getInjectionErrorSuffix(context) {
1120
+ const { result } = await session.send("script.evaluate", {
1121
+ expression: "globalThis." + SCRIPT_ERROR_PROPERTY_NAME,
1122
+ target: getSingleFileTarget(context),
1123
+ awaitPromise: false
1124
+ }).catch(() => ({}));
1125
+ return result && result.value ? ": " + result.value : "";
1126
+ }
1127
+
1117
1128
  async function capturePageData(pageContext) {
1118
1129
  const CAPTURE_TIMEOUT_ERROR_MESSAGE = "Capture timeout";
1119
1130
  const EXCEPTION_TYPE = "exception";
package/lib/cdp-client.js CHANGED
@@ -37,6 +37,8 @@ import {
37
37
  FETCH_FUNCTION_NAME,
38
38
  RESOLVE_FETCH_FUNCTION_NAME,
39
39
  REJECT_FETCH_FUNCTION_NAME,
40
+ SCRIPT_READY_PROPERTY_NAME,
41
+ SCRIPT_ERROR_PROPERTY_NAME,
40
42
  getScriptSource,
41
43
  getHookScriptSource,
42
44
  getPageDataScriptSource
@@ -670,7 +672,7 @@ function createFrameNavigatedHandler(state, timeoutState, reject, cleanup, { opt
670
672
  }
671
673
 
672
674
  async function getSingleFileContext({ Page, Runtime }, topFrameId, { options, debugMessages }) {
673
- const SINGLE_FILE_DETECTION_TEST = "typeof singlefile !== 'undefined'";
675
+ const SINGLE_FILE_DETECTION_TEST = "typeof singlefile !== 'undefined' && globalThis." + SCRIPT_READY_PROPERTY_NAME + " === true";
674
676
  const NO_VALID_CONTEXT_ERROR_MESSAGE = "No valid SingleFile execution context found";
675
677
  logData(["Getting execution context"], { options, debugMessages });
676
678
  // the world already exists, so asking for it by name returns the context the
@@ -687,11 +689,19 @@ async function getSingleFileContext({ Page, Runtime }, topFrameId, { options, de
687
689
  contextId: executionContextId
688
690
  });
689
691
  if (result.value !== true) {
690
- throw new Error(NO_VALID_CONTEXT_ERROR_MESSAGE);
692
+ throw new Error(NO_VALID_CONTEXT_ERROR_MESSAGE + await getInjectionErrorSuffix(Runtime, executionContextId));
691
693
  }
692
694
  return executionContextId;
693
695
  }
694
696
 
697
+ async function getInjectionErrorSuffix(Runtime, executionContextId) {
698
+ const { result } = await Runtime.evaluate({
699
+ expression: "globalThis." + SCRIPT_ERROR_PROPERTY_NAME,
700
+ contextId: executionContextId
701
+ }).catch(() => ({}));
702
+ return result && result.value ? ": " + result.value : "";
703
+ }
704
+
695
705
  function setupPageDataCapture({ Runtime }, { options, debugMessages }) {
696
706
  return new Promise((resolve, reject) => {
697
707
  let pageDataResponse = "";