single-file-cli 2.0.10 → 2.0.12
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/deno.json +1 -1
- package/lib/browser.js +4 -2
- package/lib/cdp-client.js +1 -1
- package/lib/deno-polyfill.js +5 -3
- package/lib/version.js +1 -1
- package/package.json +4 -2
- package/single-file +2 -105
- package/single-file-cli-api.js +1 -1
- package/single-file-launcher.js +108 -0
- package/single-file-node.js +5 -0
package/deno.json
CHANGED
package/lib/browser.js
CHANGED
|
@@ -54,7 +54,7 @@ async function launchBrowser(options = {}, indexPath = 0) {
|
|
|
54
54
|
if (options.httpProxyServer) {
|
|
55
55
|
args.push("--proxy-server=" + options.httpProxyServer);
|
|
56
56
|
}
|
|
57
|
-
args.push(
|
|
57
|
+
args.push("--user-data-dir=" + profilePath);
|
|
58
58
|
if (options.args) {
|
|
59
59
|
args.push(...options.args);
|
|
60
60
|
}
|
|
@@ -66,8 +66,10 @@ async function launchBrowser(options = {}, indexPath = 0) {
|
|
|
66
66
|
if (indexPath + 1 < BROWSER_PATHS[build.os].length) {
|
|
67
67
|
await launchBrowser(options, indexPath + 1);
|
|
68
68
|
} else {
|
|
69
|
-
throw
|
|
69
|
+
throw "Chromium executable not found. Set the path using the --browser-executable-path option.";
|
|
70
70
|
}
|
|
71
|
+
} else {
|
|
72
|
+
throw error;
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
child.ref();
|
package/lib/cdp-client.js
CHANGED
|
@@ -43,7 +43,7 @@ async function initialize(options) {
|
|
|
43
43
|
async function getPageData(options) {
|
|
44
44
|
let targetInfo;
|
|
45
45
|
try {
|
|
46
|
-
const targetInfo = await CDP.createTarget(
|
|
46
|
+
const targetInfo = await CDP.createTarget(EMPTY_PAGE_URL);
|
|
47
47
|
const { Browser, Security, Page, Emulation, Fetch, Network, Runtime, Debugger } = new CDP(targetInfo);
|
|
48
48
|
if (options.browserStartMinimized) {
|
|
49
49
|
const { windowId, bounds } = await Browser.getWindowForTarget({ targetId: targetInfo.targetId });
|
package/lib/deno-polyfill.js
CHANGED
|
@@ -39,8 +39,6 @@ const NODE_MODULES = {
|
|
|
39
39
|
"url": "node:url"
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
export { DenoAPI as Deno, pathAPI as path, initGlobalThisProperties };
|
|
43
|
-
|
|
44
42
|
const args = DENO_RUNTIME_DETECTED ? Deno.args : process.argv.slice(2);
|
|
45
43
|
|
|
46
44
|
const stdout = {
|
|
@@ -119,6 +117,10 @@ const pathAPI = {
|
|
|
119
117
|
dirname
|
|
120
118
|
};
|
|
121
119
|
|
|
120
|
+
await initGlobalThisProperties();
|
|
121
|
+
|
|
122
|
+
export { DenoAPI as Deno, pathAPI as path };
|
|
123
|
+
|
|
122
124
|
async function initGlobalThisProperties() {
|
|
123
125
|
if (!DENO_RUNTIME_DETECTED) {
|
|
124
126
|
const { WebSocket } = await import(getNPMModule("ws"));
|
|
@@ -165,7 +167,7 @@ async function makeTempDir() {
|
|
|
165
167
|
} else {
|
|
166
168
|
const fsPromise = await import(NODE_MODULES["fs"]);
|
|
167
169
|
const os = await import(NODE_MODULES["os"]);
|
|
168
|
-
return fsPromise.mkdtemp(path.join(os.tmpdir()));
|
|
170
|
+
return fsPromise.mkdtemp(path.join(os.tmpdir(), "/"));
|
|
169
171
|
}
|
|
170
172
|
}
|
|
171
173
|
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "2.0.
|
|
1
|
+
export const version = "2.0.12";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "single-file-cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.12",
|
|
4
4
|
"description": "SingleFile CLI",
|
|
5
5
|
"author": "Gildas Lormeau",
|
|
6
6
|
"engines": {
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
"node": ">=20"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
|
-
"bin":
|
|
12
|
+
"bin": {
|
|
13
|
+
"single-file": "./single-file-node.js"
|
|
14
|
+
},
|
|
13
15
|
"dependencies": {
|
|
14
16
|
"simple-cdp": "^1.8.2",
|
|
15
17
|
"ws": "^8.16.0"
|
package/single-file
CHANGED
|
@@ -1,108 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env -S deno run --allow-read --allow-write --allow-net --allow-env --allow-run
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* Copyright 2010-2024 Gildas Lormeau
|
|
5
|
-
* contact : gildas.lormeau <at> gmail.com
|
|
6
|
-
*
|
|
7
|
-
* This file is part of SingleFile.
|
|
8
|
-
*
|
|
9
|
-
* The code in this file is free software: you can redistribute it and/or
|
|
10
|
-
* modify it under the terms of the GNU Affero General Public License
|
|
11
|
-
* (GNU AGPL) as published by the Free Software Foundation, either version 3
|
|
12
|
-
* of the License, or (at your option) any later version.
|
|
13
|
-
*
|
|
14
|
-
* The code in this file is distributed in the hope that it will be useful,
|
|
15
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
|
|
17
|
-
* General Public License for more details.
|
|
18
|
-
*
|
|
19
|
-
* As additional permission under GNU AGPL version 3 section 7, you may
|
|
20
|
-
* distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU
|
|
21
|
-
* AGPL normally required by section 4, provided you include this license
|
|
22
|
-
* notice and a URL through which recipients can access the Corresponding
|
|
23
|
-
* Source.
|
|
24
|
-
*/
|
|
3
|
+
import { run } from "./single-file-launcher.js";
|
|
25
4
|
|
|
26
|
-
|
|
27
|
-
import { initGlobalThisProperties, Deno, path } from "./lib/deno-polyfill.js";
|
|
28
|
-
import options from "./options.js";
|
|
29
|
-
|
|
30
|
-
const { readTextFile } = Deno;
|
|
31
|
-
const { toFileUrl } = path;
|
|
32
|
-
await initGlobalThisProperties();
|
|
33
|
-
await run(options);
|
|
34
|
-
|
|
35
|
-
async function run(options = {}) {
|
|
36
|
-
let urls;
|
|
37
|
-
if (options.url && !VALID_URL_TEST.test(options.url)) {
|
|
38
|
-
options.url = (await toFileUrl(new URL(options.url, import.meta.url).pathname)).href;
|
|
39
|
-
}
|
|
40
|
-
if (options.urlsFile) {
|
|
41
|
-
urls = (await readTextFile(options.urlsFile)).split("\n");
|
|
42
|
-
} else {
|
|
43
|
-
urls = [options.url];
|
|
44
|
-
}
|
|
45
|
-
if (options.browserCookies) {
|
|
46
|
-
const cookies = [];
|
|
47
|
-
for (const cookie of options.browserCookies) {
|
|
48
|
-
const [name, value, domain, path, expires, httpOnly, secure, sameSite, url] = cookie.split(",");
|
|
49
|
-
cookies.push({
|
|
50
|
-
name,
|
|
51
|
-
value,
|
|
52
|
-
url,
|
|
53
|
-
domain,
|
|
54
|
-
path,
|
|
55
|
-
secure,
|
|
56
|
-
httpOnly,
|
|
57
|
-
sameSite,
|
|
58
|
-
expires
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
options.browserCookies = cookies;
|
|
62
|
-
}
|
|
63
|
-
if (options.browserCookiesFile) {
|
|
64
|
-
const cookiesContent = await readTextFile(options.browserCookiesFile);
|
|
65
|
-
try {
|
|
66
|
-
options.browserCookies = JSON.parse(cookiesContent);
|
|
67
|
-
} catch (error) {
|
|
68
|
-
options.browserCookies = parseCookies(cookiesContent);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (options.httpHeaders) {
|
|
72
|
-
const headers = {};
|
|
73
|
-
for (const header of options.httpHeaders) {
|
|
74
|
-
const [name, value] = header.split("=");
|
|
75
|
-
headers[name] = value.trim();
|
|
76
|
-
}
|
|
77
|
-
options.httpHeaders = headers;
|
|
78
|
-
}
|
|
79
|
-
options.retrieveLinks = true;
|
|
80
|
-
const singlefile = await initialize(options);
|
|
81
|
-
await singlefile.capture(urls);
|
|
82
|
-
await singlefile.finish();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function parseCookies(textValue) {
|
|
86
|
-
const httpOnlyRegExp = /^#HttpOnly_(.*)/;
|
|
87
|
-
return textValue.split(/\r\n|\n/)
|
|
88
|
-
.filter(line => line.trim() && (!/^#/.test(line) || httpOnlyRegExp.test(line)))
|
|
89
|
-
.map(line => {
|
|
90
|
-
const httpOnly = httpOnlyRegExp.test(line);
|
|
91
|
-
if (httpOnly) {
|
|
92
|
-
line = line.replace(httpOnlyRegExp, "$1");
|
|
93
|
-
}
|
|
94
|
-
const values = line.split(/\t/);
|
|
95
|
-
if (values.length == 7) {
|
|
96
|
-
return {
|
|
97
|
-
domain: values[0],
|
|
98
|
-
path: values[2],
|
|
99
|
-
secure: values[3] == "TRUE",
|
|
100
|
-
expires: (values[4] && Number(values[4])) || undefined,
|
|
101
|
-
name: values[5],
|
|
102
|
-
value: values[6],
|
|
103
|
-
httpOnly
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
.filter(cookieData => cookieData);
|
|
108
|
-
}
|
|
5
|
+
await run();
|
package/single-file-cli-api.js
CHANGED
|
@@ -248,7 +248,7 @@ async function capturePage(options) {
|
|
|
248
248
|
if (options.compressContent) {
|
|
249
249
|
await stdout.write(pageData.content);
|
|
250
250
|
} else {
|
|
251
|
-
console.log(pageData.content); // eslint-disable-line no-console
|
|
251
|
+
console.log(pageData.content || ""); // eslint-disable-line no-console
|
|
252
252
|
}
|
|
253
253
|
} else {
|
|
254
254
|
filename = await getFilename(pageData.filename, options);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2010-2024 Gildas Lormeau
|
|
3
|
+
* contact : gildas.lormeau <at> gmail.com
|
|
4
|
+
*
|
|
5
|
+
* This file is part of SingleFile.
|
|
6
|
+
*
|
|
7
|
+
* The code in this file is free software: you can redistribute it and/or
|
|
8
|
+
* modify it under the terms of the GNU Affero General Public License
|
|
9
|
+
* (GNU AGPL) as published by the Free Software Foundation, either version 3
|
|
10
|
+
* of the License, or (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* The code in this file is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
|
|
15
|
+
* General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* As additional permission under GNU AGPL version 3 section 7, you may
|
|
18
|
+
* distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU
|
|
19
|
+
* AGPL normally required by section 4, provided you include this license
|
|
20
|
+
* notice and a URL through which recipients can access the Corresponding
|
|
21
|
+
* Source.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/* global URL */
|
|
25
|
+
|
|
26
|
+
import { VALID_URL_TEST, initialize } from "./single-file-cli-api.js";
|
|
27
|
+
import { Deno, path } from "./lib/deno-polyfill.js";
|
|
28
|
+
import options from "./options.js";
|
|
29
|
+
|
|
30
|
+
const { readTextFile } = Deno;
|
|
31
|
+
const { toFileUrl } = path;
|
|
32
|
+
|
|
33
|
+
export { run };
|
|
34
|
+
|
|
35
|
+
async function run() {
|
|
36
|
+
let urls;
|
|
37
|
+
if (options.url && !VALID_URL_TEST.test(options.url)) {
|
|
38
|
+
options.url = (await toFileUrl(new URL(options.url, import.meta.url).pathname)).href;
|
|
39
|
+
}
|
|
40
|
+
if (options.urlsFile) {
|
|
41
|
+
urls = (await readTextFile(options.urlsFile)).split("\n");
|
|
42
|
+
} else {
|
|
43
|
+
urls = [options.url];
|
|
44
|
+
}
|
|
45
|
+
if (options.browserCookies) {
|
|
46
|
+
const cookies = [];
|
|
47
|
+
for (const cookie of options.browserCookies) {
|
|
48
|
+
const [name, value, domain, path, expires, httpOnly, secure, sameSite, url] = cookie.split(",");
|
|
49
|
+
cookies.push({
|
|
50
|
+
name,
|
|
51
|
+
value,
|
|
52
|
+
url,
|
|
53
|
+
domain,
|
|
54
|
+
path,
|
|
55
|
+
secure,
|
|
56
|
+
httpOnly,
|
|
57
|
+
sameSite,
|
|
58
|
+
expires
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
options.browserCookies = cookies;
|
|
62
|
+
}
|
|
63
|
+
if (options.browserCookiesFile) {
|
|
64
|
+
const cookiesContent = await readTextFile(options.browserCookiesFile);
|
|
65
|
+
try {
|
|
66
|
+
options.browserCookies = JSON.parse(cookiesContent);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
options.browserCookies = parseCookies(cookiesContent);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (options.httpHeaders) {
|
|
72
|
+
const headers = {};
|
|
73
|
+
for (const header of options.httpHeaders) {
|
|
74
|
+
const [name, value] = header.split("=");
|
|
75
|
+
headers[name] = value.trim();
|
|
76
|
+
}
|
|
77
|
+
options.httpHeaders = headers;
|
|
78
|
+
}
|
|
79
|
+
options.retrieveLinks = true;
|
|
80
|
+
const singlefile = await initialize(options);
|
|
81
|
+
await singlefile.capture(urls);
|
|
82
|
+
await singlefile.finish();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function parseCookies(textValue) {
|
|
86
|
+
const httpOnlyRegExp = /^#HttpOnly_(.*)/;
|
|
87
|
+
return textValue.split(/\r\n|\n/)
|
|
88
|
+
.filter(line => line.trim() && (!/^#/.test(line) || httpOnlyRegExp.test(line)))
|
|
89
|
+
.map(line => {
|
|
90
|
+
const httpOnly = httpOnlyRegExp.test(line);
|
|
91
|
+
if (httpOnly) {
|
|
92
|
+
line = line.replace(httpOnlyRegExp, "$1");
|
|
93
|
+
}
|
|
94
|
+
const values = line.split(/\t/);
|
|
95
|
+
if (values.length == 7) {
|
|
96
|
+
return {
|
|
97
|
+
domain: values[0],
|
|
98
|
+
path: values[2],
|
|
99
|
+
secure: values[3] == "TRUE",
|
|
100
|
+
expires: (values[4] && Number(values[4])) || undefined,
|
|
101
|
+
name: values[5],
|
|
102
|
+
value: values[6],
|
|
103
|
+
httpOnly
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
.filter(cookieData => cookieData);
|
|
108
|
+
}
|