single-file-cli 2.0.14 → 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 +1 -1
- package/deno.json +1 -1
- package/lib/cdp-client.js +13 -15
- package/lib/deno-polyfill.js +11 -0
- package/lib/single-file-script.js +2 -2
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/single-file-cli-api.js +6 -2
- /package/{build-lib-dev.sh → build-dev-lib.sh} +0 -0
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
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:
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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)];
|
package/lib/deno-polyfill.js
CHANGED
|
@@ -101,6 +101,7 @@ const DenoAPI = {
|
|
|
101
101
|
args,
|
|
102
102
|
readTextFile,
|
|
103
103
|
writeTextFile,
|
|
104
|
+
writeFile,
|
|
104
105
|
mkdir,
|
|
105
106
|
makeTempDir,
|
|
106
107
|
stat,
|
|
@@ -144,6 +145,7 @@ async function writeTextFile(path, data, options = {}) {
|
|
|
144
145
|
return Deno.writeTextFile(path, data, options);
|
|
145
146
|
} else {
|
|
146
147
|
const fsPromise = await import(NODE_MODULES["fs"]);
|
|
148
|
+
options.encoding = "utf8";
|
|
147
149
|
if (options.append) {
|
|
148
150
|
return fsPromise.appendFile(path, data, options);
|
|
149
151
|
} else {
|
|
@@ -152,6 +154,15 @@ async function writeTextFile(path, data, options = {}) {
|
|
|
152
154
|
}
|
|
153
155
|
}
|
|
154
156
|
|
|
157
|
+
async function writeFile(path, data, options = {}) {
|
|
158
|
+
if (DENO_RUNTIME_DETECTED) {
|
|
159
|
+
return Deno.writeFile(path, data, options);
|
|
160
|
+
} else {
|
|
161
|
+
const fsPromise = await import(NODE_MODULES["fs"]);
|
|
162
|
+
return fsPromise.writeFile(path, data, options);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
155
166
|
async function mkdir(path, options = {}) {
|
|
156
167
|
if (DENO_RUNTIME_DETECTED) {
|
|
157
168
|
return Deno.mkdir(path, options);
|
|
@@ -70,11 +70,11 @@ async function getScriptSource(options) {
|
|
|
70
70
|
return source;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
function getHookScriptSource() {
|
|
74
74
|
return hookScript;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
function getZipScriptSource() {
|
|
78
78
|
return zipScript;
|
|
79
79
|
}
|
|
80
80
|
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "2.0.
|
|
1
|
+
export const version = "2.0.16";
|
package/package.json
CHANGED
package/single-file-cli-api.js
CHANGED
|
@@ -76,7 +76,7 @@ const DEFAULT_OPTIONS = {
|
|
|
76
76
|
const STATE_PROCESSING = "processing";
|
|
77
77
|
const STATE_PROCESSED = "processed";
|
|
78
78
|
|
|
79
|
-
const { readTextFile, writeTextFile, stdout, mkdir, stat } = Deno;
|
|
79
|
+
const { readTextFile, writeTextFile, writeFile, stdout, mkdir, stat } = Deno;
|
|
80
80
|
let tasks = [], maxParallelWorkers, sessionFilename;
|
|
81
81
|
|
|
82
82
|
export { DEFAULT_OPTIONS, VALID_URL_TEST, initialize };
|
|
@@ -258,7 +258,11 @@ async function capturePage(options) {
|
|
|
258
258
|
if (directoryName !== ".") {
|
|
259
259
|
await mkdir(directoryName, { recursive: true });
|
|
260
260
|
}
|
|
261
|
-
|
|
261
|
+
if (pageData.content instanceof Uint8Array) {
|
|
262
|
+
await writeFile(filename, pageData.content);
|
|
263
|
+
} else {
|
|
264
|
+
await writeTextFile(filename, pageData.content);
|
|
265
|
+
}
|
|
262
266
|
}
|
|
263
267
|
return pageData;
|
|
264
268
|
} catch (error) {
|
|
File without changes
|