single-file-cli 2.0.4 → 2.0.5
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/Dockerfile +0 -1
- package/build-lib.sh +1 -1
- package/deno.json +1 -1
- package/{back-ends/chromium-browser.js → lib/browser.js} +4 -3
- package/{back-ends/chromium-back-end.js → lib/cdp-client.js} +17 -20
- package/{deno-polyfill.js → lib/deno-polyfill.js} +61 -61
- package/lib/single-file-bundle.js +1 -1
- package/{back-ends → lib}/single-file-script.js +3 -2
- package/{args.js → options.js} +27 -24
- package/package.json +1 -1
- package/single-file +5 -3
- package/single-file-cli-api.js +5 -4
- /package/{back-ends/chromium-constants.js → lib/constants.js} +0 -0
package/Dockerfile
CHANGED
package/build-lib.sh
CHANGED
package/deno.json
CHANGED
|
@@ -21,11 +21,12 @@
|
|
|
21
21
|
* Source.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import { BROWSER_PATHS, BROWSER_ARGS } from "./
|
|
25
|
-
import {
|
|
24
|
+
import { BROWSER_PATHS, BROWSER_ARGS } from "./constants.js";
|
|
25
|
+
import { Deno } from "./deno-polyfill.js";
|
|
26
26
|
|
|
27
27
|
const PIPED_STD_CONFIG = "piped";
|
|
28
28
|
|
|
29
|
+
const { build, makeTempDir, Command, errors, remove } = Deno;
|
|
29
30
|
let child, profilePath;
|
|
30
31
|
export { launchBrowser, closeBrowser };
|
|
31
32
|
|
|
@@ -56,10 +57,10 @@ async function launchBrowser(options = {}, indexPath = 0) {
|
|
|
56
57
|
if (options.httpProxyServer) {
|
|
57
58
|
args.push("--proxy-server=" + options.httpProxyServer);
|
|
58
59
|
}
|
|
60
|
+
args.push(`--user-data-dir=${profilePath}`);
|
|
59
61
|
if (options.args) {
|
|
60
62
|
args.push(...options.args);
|
|
61
63
|
}
|
|
62
|
-
args.push(`--user-data-dir=${profilePath}`);
|
|
63
64
|
const command = new Command(path, { args, stdout: PIPED_STD_CONFIG, stderr: PIPED_STD_CONFIG });
|
|
64
65
|
try {
|
|
65
66
|
child = await command.spawn();
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
/* global setTimeout, clearTimeout */
|
|
25
25
|
|
|
26
|
-
import { launchBrowser, closeBrowser } from "./
|
|
26
|
+
import { launchBrowser, closeBrowser } from "./browser.js";
|
|
27
27
|
import { getScriptSource, getHookScriptSource } from "./single-file-script.js";
|
|
28
28
|
import { CDP } from "simple-cdp";
|
|
29
29
|
|
|
@@ -119,16 +119,14 @@ async function getPageData(options) {
|
|
|
119
119
|
worldName: SINGLE_FILE_WORLD_NAME
|
|
120
120
|
});
|
|
121
121
|
await Runtime.enable();
|
|
122
|
-
|
|
122
|
+
const topFrameId = targetInfo.id;
|
|
123
123
|
const executionContextIdPromise = new Promise(resolve => {
|
|
124
124
|
const CONTEXT_CREATED_EVENT = "executionContextCreated";
|
|
125
125
|
Runtime.addEventListener(CONTEXT_CREATED_EVENT, executionContextCreated);
|
|
126
126
|
|
|
127
127
|
async function executionContextCreated({ params }) {
|
|
128
128
|
const { context } = params;
|
|
129
|
-
if (context.
|
|
130
|
-
topFrameId = context.auxData.frameId;
|
|
131
|
-
} else if (context.name === SINGLE_FILE_WORLD_NAME && context.auxData && context.auxData.frameId === topFrameId) {
|
|
129
|
+
if (context.name === SINGLE_FILE_WORLD_NAME && context.auxData && context.auxData.frameId === topFrameId) {
|
|
132
130
|
Runtime.removeEventListener(CONTEXT_CREATED_EVENT, executionContextCreated);
|
|
133
131
|
await Runtime.disable();
|
|
134
132
|
resolve(context.id);
|
|
@@ -145,20 +143,19 @@ async function getPageData(options) {
|
|
|
145
143
|
|
|
146
144
|
async function onLifecycleEvent({ params }) {
|
|
147
145
|
const { name, frameId } = params;
|
|
148
|
-
if (
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
contentLoaded
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
resolve();
|
|
146
|
+
if (frameId === topFrameId) {
|
|
147
|
+
if (name === "DOMContentLoaded") {
|
|
148
|
+
contentLoaded = true;
|
|
149
|
+
}
|
|
150
|
+
if (contentLoaded && name === (options.browserWaitUntil || NETWORK_IDLE_STATE)) {
|
|
151
|
+
if (options.browserWaitDelay) {
|
|
152
|
+
setTimeout(() => resolve, options.browserWaitDelay);
|
|
153
|
+
} else {
|
|
154
|
+
Page.removeEventListener(LIFE_CYCLE_EVENT, onLifecycleEvent);
|
|
155
|
+
await Page.setLifecycleEventsEnabled({ enabled: false });
|
|
156
|
+
await Page.disable();
|
|
157
|
+
resolve();
|
|
158
|
+
}
|
|
162
159
|
}
|
|
163
160
|
}
|
|
164
161
|
}
|
|
@@ -209,7 +206,7 @@ async function getPageData(options) {
|
|
|
209
206
|
|
|
210
207
|
function getBrowserOptions(options) {
|
|
211
208
|
const browserOptions = {};
|
|
212
|
-
browserOptions.args = options.browserArgs
|
|
209
|
+
browserOptions.args = options.browserArgs;
|
|
213
210
|
browserOptions.headless = options.browserHeadless && !options.browserDebug;
|
|
214
211
|
browserOptions.executablePath = options.browserExecutablePath;
|
|
215
212
|
browserOptions.browserDebug = options.browserDebug;
|
|
@@ -39,23 +39,7 @@ const NODE_MODULES = {
|
|
|
39
39
|
"url": "node:url"
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
export {
|
|
43
|
-
initGlobalThisProperties,
|
|
44
|
-
args,
|
|
45
|
-
readTextFile,
|
|
46
|
-
writeTextFile,
|
|
47
|
-
mkdir,
|
|
48
|
-
makeTempDir,
|
|
49
|
-
stat,
|
|
50
|
-
remove,
|
|
51
|
-
stdout,
|
|
52
|
-
exit,
|
|
53
|
-
build,
|
|
54
|
-
errors,
|
|
55
|
-
Command,
|
|
56
|
-
toFileUrl,
|
|
57
|
-
dirname
|
|
58
|
-
};
|
|
42
|
+
export { DenoAPI as Deno, pathAPI as path, initGlobalThisProperties };
|
|
59
43
|
|
|
60
44
|
const args = DENO_RUNTIME_DETECTED ? Deno.args : process.argv.slice(2);
|
|
61
45
|
|
|
@@ -76,6 +60,65 @@ const errors = {
|
|
|
76
60
|
}
|
|
77
61
|
};
|
|
78
62
|
|
|
63
|
+
const Command = DENO_RUNTIME_DETECTED ? Deno.Command : class Command {
|
|
64
|
+
constructor(path, options = {}) {
|
|
65
|
+
this.path = path;
|
|
66
|
+
this.options = options;
|
|
67
|
+
}
|
|
68
|
+
async spawn() {
|
|
69
|
+
const childProcess = await import(NODE_MODULES["child_process"]);
|
|
70
|
+
const child = childProcess.spawn(this.path, this.options.args);
|
|
71
|
+
|
|
72
|
+
await new Promise((resolve, reject) => {
|
|
73
|
+
child.on("spawn", () => resolve());
|
|
74
|
+
child.on("error", error => {
|
|
75
|
+
if (error.code == "ENOENT") {
|
|
76
|
+
reject(new errors.NotFound(error.message));
|
|
77
|
+
} else {
|
|
78
|
+
reject(error);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
return {
|
|
83
|
+
status: new Promise((resolve, reject) => {
|
|
84
|
+
child.on("exit", code => {
|
|
85
|
+
if (code === 0 || code === 143) {
|
|
86
|
+
resolve();
|
|
87
|
+
} else {
|
|
88
|
+
reject(new Error(`Process exited with code ${code}`));
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}),
|
|
92
|
+
kill() {
|
|
93
|
+
child.kill();
|
|
94
|
+
},
|
|
95
|
+
ref() {
|
|
96
|
+
// Do nothing
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const DenoAPI = {
|
|
103
|
+
args,
|
|
104
|
+
readTextFile,
|
|
105
|
+
writeTextFile,
|
|
106
|
+
mkdir,
|
|
107
|
+
makeTempDir,
|
|
108
|
+
stat,
|
|
109
|
+
remove,
|
|
110
|
+
stdout,
|
|
111
|
+
exit,
|
|
112
|
+
build,
|
|
113
|
+
errors,
|
|
114
|
+
Command
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const pathAPI = {
|
|
118
|
+
toFileUrl,
|
|
119
|
+
dirname
|
|
120
|
+
};
|
|
121
|
+
|
|
79
122
|
async function initGlobalThisProperties() {
|
|
80
123
|
if (!DENO_RUNTIME_DETECTED) {
|
|
81
124
|
const { WebSocket } = await import(getNPMModule("ws"));
|
|
@@ -152,45 +195,6 @@ function exit(code) {
|
|
|
152
195
|
}
|
|
153
196
|
}
|
|
154
197
|
|
|
155
|
-
const Command = DENO_RUNTIME_DETECTED ? Deno.Command : class Command {
|
|
156
|
-
constructor(path, options = {}) {
|
|
157
|
-
this.path = path;
|
|
158
|
-
this.options = options;
|
|
159
|
-
}
|
|
160
|
-
async spawn() {
|
|
161
|
-
const childProcess = await import(NODE_MODULES["child_process"]);
|
|
162
|
-
const child = childProcess.spawn(this.path, this.options.args);
|
|
163
|
-
|
|
164
|
-
await new Promise((resolve, reject) => {
|
|
165
|
-
child.on("spawn", () => resolve());
|
|
166
|
-
child.on("error", error => {
|
|
167
|
-
if (error.code == "ENOENT") {
|
|
168
|
-
reject(new errors.NotFound(error.message));
|
|
169
|
-
} else {
|
|
170
|
-
reject(error);
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
return {
|
|
175
|
-
status: new Promise((resolve, reject) => {
|
|
176
|
-
child.on("exit", code => {
|
|
177
|
-
if (code === 0 || code === 143) {
|
|
178
|
-
resolve();
|
|
179
|
-
} else {
|
|
180
|
-
reject(new Error(`Process exited with code ${code}`));
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
}),
|
|
184
|
-
kill() {
|
|
185
|
-
child.kill();
|
|
186
|
-
},
|
|
187
|
-
ref() {
|
|
188
|
-
// Do nothing
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
|
|
194
198
|
async function toFileUrl(filePath) {
|
|
195
199
|
if (DENO_RUNTIME_DETECTED) {
|
|
196
200
|
return path.toFileUrl(filePath);
|
|
@@ -201,11 +205,7 @@ async function toFileUrl(filePath) {
|
|
|
201
205
|
}
|
|
202
206
|
|
|
203
207
|
async function dirname(filePath) {
|
|
204
|
-
|
|
205
|
-
return path.dirname(filePath);
|
|
206
|
-
} else {
|
|
207
|
-
return path.dirname(filePath);
|
|
208
|
-
}
|
|
208
|
+
return path.dirname(filePath);
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
function getNPMModule(module) {
|