single-file-cli 2.0.3 → 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} +18 -22
- package/{deno-polyfill.js → lib/deno-polyfill.js} +62 -72
- 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,9 +23,9 @@
|
|
|
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
|
-
import {
|
|
28
|
+
import { CDP } from "simple-cdp";
|
|
29
29
|
|
|
30
30
|
const LOAD_TIMEOUT_ERROR = "ERR_LOAD_TIMEOUT";
|
|
31
31
|
const NETWORK_IDLE_STATE = "networkIdle";
|
|
@@ -42,7 +42,6 @@ async function initialize(options) {
|
|
|
42
42
|
|
|
43
43
|
async function getPageData(options) {
|
|
44
44
|
let targetInfo;
|
|
45
|
-
const CDP = await getCDP();
|
|
46
45
|
try {
|
|
47
46
|
const targetInfo = await CDP.createTarget({ url: EMPTY_PAGE_URL });
|
|
48
47
|
const { Browser, Security, Page, Emulation, Fetch, Network, Runtime, Debugger } = new CDP(targetInfo);
|
|
@@ -120,16 +119,14 @@ async function getPageData(options) {
|
|
|
120
119
|
worldName: SINGLE_FILE_WORLD_NAME
|
|
121
120
|
});
|
|
122
121
|
await Runtime.enable();
|
|
123
|
-
|
|
122
|
+
const topFrameId = targetInfo.id;
|
|
124
123
|
const executionContextIdPromise = new Promise(resolve => {
|
|
125
124
|
const CONTEXT_CREATED_EVENT = "executionContextCreated";
|
|
126
125
|
Runtime.addEventListener(CONTEXT_CREATED_EVENT, executionContextCreated);
|
|
127
126
|
|
|
128
127
|
async function executionContextCreated({ params }) {
|
|
129
128
|
const { context } = params;
|
|
130
|
-
if (context.
|
|
131
|
-
topFrameId = context.auxData.frameId;
|
|
132
|
-
} 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) {
|
|
133
130
|
Runtime.removeEventListener(CONTEXT_CREATED_EVENT, executionContextCreated);
|
|
134
131
|
await Runtime.disable();
|
|
135
132
|
resolve(context.id);
|
|
@@ -146,20 +143,19 @@ async function getPageData(options) {
|
|
|
146
143
|
|
|
147
144
|
async function onLifecycleEvent({ params }) {
|
|
148
145
|
const { name, frameId } = params;
|
|
149
|
-
if (
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
contentLoaded
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
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
|
+
}
|
|
163
159
|
}
|
|
164
160
|
}
|
|
165
161
|
}
|
|
@@ -210,7 +206,7 @@ async function getPageData(options) {
|
|
|
210
206
|
|
|
211
207
|
function getBrowserOptions(options) {
|
|
212
208
|
const browserOptions = {};
|
|
213
|
-
browserOptions.args = options.browserArgs
|
|
209
|
+
browserOptions.args = options.browserArgs;
|
|
214
210
|
browserOptions.headless = options.browserHeadless && !options.browserDebug;
|
|
215
211
|
browserOptions.executablePath = options.browserExecutablePath;
|
|
216
212
|
browserOptions.browserDebug = options.browserDebug;
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
/* global globalThis, URL, Deno, process */
|
|
25
25
|
|
|
26
26
|
import * as path from "path";
|
|
27
|
-
import { CDP } from "simple-cdp";
|
|
28
27
|
|
|
29
28
|
const DENO_RUNTIME_DETECTED = typeof Deno !== "undefined";
|
|
30
29
|
|
|
@@ -40,24 +39,7 @@ const NODE_MODULES = {
|
|
|
40
39
|
"url": "node:url"
|
|
41
40
|
};
|
|
42
41
|
|
|
43
|
-
export {
|
|
44
|
-
initGlobalThisProperties,
|
|
45
|
-
args,
|
|
46
|
-
readTextFile,
|
|
47
|
-
writeTextFile,
|
|
48
|
-
mkdir,
|
|
49
|
-
makeTempDir,
|
|
50
|
-
stat,
|
|
51
|
-
remove,
|
|
52
|
-
stdout,
|
|
53
|
-
exit,
|
|
54
|
-
build,
|
|
55
|
-
errors,
|
|
56
|
-
Command,
|
|
57
|
-
toFileUrl,
|
|
58
|
-
dirname,
|
|
59
|
-
getCDP
|
|
60
|
-
};
|
|
42
|
+
export { DenoAPI as Deno, pathAPI as path, initGlobalThisProperties };
|
|
61
43
|
|
|
62
44
|
const args = DENO_RUNTIME_DETECTED ? Deno.args : process.argv.slice(2);
|
|
63
45
|
|
|
@@ -66,7 +48,7 @@ const stdout = {
|
|
|
66
48
|
};
|
|
67
49
|
|
|
68
50
|
const build = {
|
|
69
|
-
os: DENO_RUNTIME_DETECTED ? Deno.build.os : process.platform
|
|
51
|
+
os: DENO_RUNTIME_DETECTED ? Deno.build.os : process.platform == "win32" ? "windows" : process.platform
|
|
70
52
|
};
|
|
71
53
|
|
|
72
54
|
const errors = {
|
|
@@ -78,6 +60,65 @@ const errors = {
|
|
|
78
60
|
}
|
|
79
61
|
};
|
|
80
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
|
+
|
|
81
122
|
async function initGlobalThisProperties() {
|
|
82
123
|
if (!DENO_RUNTIME_DETECTED) {
|
|
83
124
|
const { WebSocket } = await import(getNPMModule("ws"));
|
|
@@ -154,45 +195,6 @@ function exit(code) {
|
|
|
154
195
|
}
|
|
155
196
|
}
|
|
156
197
|
|
|
157
|
-
const Command = DENO_RUNTIME_DETECTED ? Deno.Command : class Command {
|
|
158
|
-
constructor(path, options = {}) {
|
|
159
|
-
this.path = path;
|
|
160
|
-
this.options = options;
|
|
161
|
-
}
|
|
162
|
-
async spawn() {
|
|
163
|
-
const childProcess = await import(NODE_MODULES["child_process"]);
|
|
164
|
-
const child = childProcess.spawn(this.path, this.options.args);
|
|
165
|
-
|
|
166
|
-
await new Promise((resolve, reject) => {
|
|
167
|
-
child.on("spawn", () => resolve());
|
|
168
|
-
child.on("error", error => {
|
|
169
|
-
if (error.code == "ENOENT") {
|
|
170
|
-
reject(new errors.NotFound(error.message));
|
|
171
|
-
} else {
|
|
172
|
-
reject(error);
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
return {
|
|
177
|
-
status: new Promise((resolve, reject) => {
|
|
178
|
-
child.on("exit", code => {
|
|
179
|
-
if (code === 0 || code === 143) {
|
|
180
|
-
resolve();
|
|
181
|
-
} else {
|
|
182
|
-
reject(new Error(`Process exited with code ${code}`));
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
}),
|
|
186
|
-
kill() {
|
|
187
|
-
child.kill();
|
|
188
|
-
},
|
|
189
|
-
ref() {
|
|
190
|
-
// Do nothing
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
|
|
196
198
|
async function toFileUrl(filePath) {
|
|
197
199
|
if (DENO_RUNTIME_DETECTED) {
|
|
198
200
|
return path.toFileUrl(filePath);
|
|
@@ -203,19 +205,7 @@ async function toFileUrl(filePath) {
|
|
|
203
205
|
}
|
|
204
206
|
|
|
205
207
|
async function dirname(filePath) {
|
|
206
|
-
|
|
207
|
-
return path.dirname(filePath);
|
|
208
|
-
} else {
|
|
209
|
-
return path.dirname(filePath);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
async function getCDP() {
|
|
214
|
-
if (DENO_RUNTIME_DETECTED) {
|
|
215
|
-
return CDP;
|
|
216
|
-
} else {
|
|
217
|
-
return CDP;
|
|
218
|
-
}
|
|
208
|
+
return path.dirname(filePath);
|
|
219
209
|
}
|
|
220
210
|
|
|
221
211
|
function getNPMModule(module) {
|