single-file-cli 1.0.0
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/.eslintrc.js +43 -0
- package/Dockerfile +12 -0
- package/README.MD +163 -0
- package/args.js +305 -0
- package/back-ends/common/scripts.js +66 -0
- package/back-ends/extensions/bypass-csp/index.js +36 -0
- package/back-ends/extensions/bypass-csp/manifest.json +20 -0
- package/back-ends/extensions/disable-web-security/index.js +54 -0
- package/back-ends/extensions/disable-web-security/manifest.json +20 -0
- package/back-ends/extensions/network-idle/bg.js +61 -0
- package/back-ends/extensions/network-idle/content.js +29 -0
- package/back-ends/extensions/network-idle/manifest.json +31 -0
- package/back-ends/extensions/signed/bypass_csp-0.0.3-an+fx.xpi +0 -0
- package/back-ends/extensions/signed/disable_web_security-0.0.3-an+fx.xpi +0 -0
- package/back-ends/extensions/signed/network_idle-0.0.2-an+fx.xpi +0 -0
- package/back-ends/jsdom.js +175 -0
- package/back-ends/playwright-chromium.js +113 -0
- package/back-ends/playwright-firefox.js +113 -0
- package/back-ends/puppeteer-firefox.js +170 -0
- package/back-ends/puppeteer.js +189 -0
- package/back-ends/webdriver-chromium.js +168 -0
- package/back-ends/webdriver-gecko.js +181 -0
- package/build-lib.sh +3 -0
- package/lib/single-file-bootstrap.js +1 -0
- package/lib/single-file-frames.js +1 -0
- package/lib/single-file-hooks-frames.js +1 -0
- package/lib/single-file-hooks.js +1 -0
- package/lib/single-file-infobar.js +1 -0
- package/lib/single-file.js +1 -0
- package/package.json +37 -0
- package/rollup.config.dev.js +64 -0
- package/rollup.config.js +64 -0
- package/single-file +81 -0
- package/single-file-cli-api.js +324 -0
- package/single-file.bat +2 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/* global module */
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
"env": {
|
|
5
|
+
"es6": true,
|
|
6
|
+
"node": false,
|
|
7
|
+
"browser": false
|
|
8
|
+
},
|
|
9
|
+
"globals": {
|
|
10
|
+
"console": true
|
|
11
|
+
},
|
|
12
|
+
"extends": "eslint:recommended",
|
|
13
|
+
"parserOptions": {
|
|
14
|
+
"ecmaVersion": 2017,
|
|
15
|
+
"sourceType": "module"
|
|
16
|
+
},
|
|
17
|
+
"ignorePatterns": [
|
|
18
|
+
"/lib/"
|
|
19
|
+
],
|
|
20
|
+
"rules": {
|
|
21
|
+
"indent": [
|
|
22
|
+
"error",
|
|
23
|
+
"tab", {
|
|
24
|
+
"SwitchCase": 1
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"linebreak-style": [
|
|
28
|
+
"error",
|
|
29
|
+
"unix"
|
|
30
|
+
],
|
|
31
|
+
"quotes": [
|
|
32
|
+
"error",
|
|
33
|
+
"double"
|
|
34
|
+
],
|
|
35
|
+
"semi": [
|
|
36
|
+
"error",
|
|
37
|
+
"always"
|
|
38
|
+
],
|
|
39
|
+
"no-console": [
|
|
40
|
+
"warn"
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
};
|
package/Dockerfile
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
FROM zenika/alpine-chrome:with-node
|
|
2
|
+
|
|
3
|
+
RUN npm install --production single-file-cli
|
|
4
|
+
|
|
5
|
+
WORKDIR /usr/src/app/node_modules/single-file-cli
|
|
6
|
+
|
|
7
|
+
ENTRYPOINT [ \
|
|
8
|
+
"./single-file", \
|
|
9
|
+
"--browser-executable-path", "/usr/bin/chromium-browser", \
|
|
10
|
+
"--output-directory", "./../../../out/", \
|
|
11
|
+
"--browser-args", "[\"--no-sandbox\"]", \
|
|
12
|
+
"--dump-content" ]
|
package/README.MD
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# SingleFile CLI (Command Line Interface)
|
|
2
|
+
|
|
3
|
+
## Introduction
|
|
4
|
+
|
|
5
|
+
SingleFile can be launched from the command line by running it into a (headless)
|
|
6
|
+
browser. It runs through Node.js as a standalone script injected into the web
|
|
7
|
+
page instead of being embedded into a WebExtension. To connect to the browser,
|
|
8
|
+
it can use [Puppeteer](https://github.com/GoogleChrome/puppeteer) or
|
|
9
|
+
[Selenium WebDriver](https://www.npmjs.com/package/selenium-webdriver).
|
|
10
|
+
Alternatively, it can also emulate a browser with JavaScript disabled by using
|
|
11
|
+
[jsdom](https://github.com/jsdom/jsdom).
|
|
12
|
+
|
|
13
|
+
## Installation with Docker
|
|
14
|
+
|
|
15
|
+
- Installation from Docker Hub
|
|
16
|
+
|
|
17
|
+
`docker pull capsulecode/singlefile`
|
|
18
|
+
|
|
19
|
+
`docker tag capsulecode/singlefile singlefile`
|
|
20
|
+
|
|
21
|
+
- Manual installation
|
|
22
|
+
|
|
23
|
+
`git clone --depth 1 --recursive https://github.com/gildas-lormeau/single-file-cli.git`
|
|
24
|
+
|
|
25
|
+
`cd single-file-cli`
|
|
26
|
+
|
|
27
|
+
`docker build --no-cache -t singlefile .`
|
|
28
|
+
|
|
29
|
+
- Run
|
|
30
|
+
|
|
31
|
+
`docker run singlefile "https://www.wikipedia.org"`
|
|
32
|
+
|
|
33
|
+
- Run and redirect the result into a file
|
|
34
|
+
|
|
35
|
+
`docker run singlefile "https://www.wikipedia.org" > wikipedia.html`
|
|
36
|
+
|
|
37
|
+
- Run and mount a volume to get the saved file in the current directory
|
|
38
|
+
|
|
39
|
+
- Save one page
|
|
40
|
+
|
|
41
|
+
`docker run -v %cd%:/usr/src/app/out singlefile "https://www.wikipedia.org" wikipedia.html`
|
|
42
|
+
(Windows)
|
|
43
|
+
|
|
44
|
+
`docker run -v $(pwd):/usr/src/app/out singlefile "https://www.wikipedia.org" wikipedia.html`
|
|
45
|
+
(Linux/UNIX)
|
|
46
|
+
|
|
47
|
+
- Save one or multiple pages by using the filename template (see
|
|
48
|
+
`--filename-template` option)
|
|
49
|
+
|
|
50
|
+
`docker run -v %cd%:/usr/src/app/out singlefile "https://www.wikipedia.org" --dump-content=false`
|
|
51
|
+
(Windows)
|
|
52
|
+
|
|
53
|
+
`docker run -v $(pwd):/usr/src/app/out singlefile "https://www.wikipedia.org" --dump-content=false`
|
|
54
|
+
(Linux/UNIX)
|
|
55
|
+
|
|
56
|
+
- An alternative docker file can be found here
|
|
57
|
+
https://github.com/screenbreak/SingleFile-dockerized. It allows you to save
|
|
58
|
+
pages from the command line interface or through an HTTP server.
|
|
59
|
+
|
|
60
|
+
## Manual installation
|
|
61
|
+
|
|
62
|
+
- Make sure Chrome or Firefox is installed and the executable can be found
|
|
63
|
+
through the `PATH` environment variable. Otherwise you will need to set the
|
|
64
|
+
`--browser-executable-path` option to help SingleFile locating it. As an
|
|
65
|
+
alternative to Chrome and Firefox, you can use jsdom by setting the
|
|
66
|
+
`--back-end` option to `jsdom`.
|
|
67
|
+
|
|
68
|
+
- Install [Node.js](https://nodejs.org)
|
|
69
|
+
|
|
70
|
+
- There are 3 ways to download the code of SingleFile, choose the one you prefer
|
|
71
|
+
(`npm` is installed with Node.js):
|
|
72
|
+
|
|
73
|
+
- Download and install globally with `npm`
|
|
74
|
+
|
|
75
|
+
`npm install -g "gildas-lormeau/single-file-cli"`
|
|
76
|
+
|
|
77
|
+
- Download and unzip manually the
|
|
78
|
+
[master archive](https://github.com/gildas-lormeau/single-file-cli/archive/master.zip)
|
|
79
|
+
provided by Github
|
|
80
|
+
|
|
81
|
+
`unzip master.zip .`
|
|
82
|
+
|
|
83
|
+
`cd single-file-cli-master`
|
|
84
|
+
|
|
85
|
+
`npm install`
|
|
86
|
+
|
|
87
|
+
- Download with `git`
|
|
88
|
+
|
|
89
|
+
`git clone --depth 1 --recursive https://github.com/gildas-lormeau/single-file-cli.git`
|
|
90
|
+
|
|
91
|
+
`cd single-file-cli`
|
|
92
|
+
|
|
93
|
+
`npm install`
|
|
94
|
+
|
|
95
|
+
- Make `single-file` executable (Linux/Unix/BSD etc.) if SingleFile is not
|
|
96
|
+
installed globally.
|
|
97
|
+
|
|
98
|
+
`chmod +x single-file`
|
|
99
|
+
|
|
100
|
+
- To use Firefox instead of Chrome, you must download the
|
|
101
|
+
[Selenium WebDriver](https://www.npmjs.com/package/selenium-webdriver)
|
|
102
|
+
component (i.e. `geckodriver` for Firefox). Make sure it can be found through
|
|
103
|
+
the `PATH` environment variable or the `cli` folder. Otherwise you will need
|
|
104
|
+
to set the `--web-driver-executable-path` option to help WebDriver locating
|
|
105
|
+
the executable.
|
|
106
|
+
|
|
107
|
+
## Run
|
|
108
|
+
|
|
109
|
+
- Syntax
|
|
110
|
+
|
|
111
|
+
`single-file <url> [output] [options ...]`
|
|
112
|
+
|
|
113
|
+
- Display help
|
|
114
|
+
|
|
115
|
+
`single-file --help`
|
|
116
|
+
|
|
117
|
+
- Examples
|
|
118
|
+
|
|
119
|
+
- Dump the processed content of https://www.wikipedia.org into the console
|
|
120
|
+
|
|
121
|
+
`single-file https://www.wikipedia.org --dump-content`
|
|
122
|
+
|
|
123
|
+
- Save https://www.wikipedia.org into `wikipedia.html` in the current folder
|
|
124
|
+
|
|
125
|
+
`single-file https://www.wikipedia.org wikipedia.html`
|
|
126
|
+
|
|
127
|
+
- Save https://www.wikipedia.org into `wikipedia.html` in the current folder
|
|
128
|
+
with Firefox instead of Chrome
|
|
129
|
+
|
|
130
|
+
`single-file https://www.wikipedia.org wikipedia.html --back-end=webdriver-gecko`
|
|
131
|
+
|
|
132
|
+
- Save a list of URLs stored into `list-urls.txt` in the current folder
|
|
133
|
+
|
|
134
|
+
`single-file --urls-file=list-urls.txt`
|
|
135
|
+
|
|
136
|
+
- Save https://www.wikipedia.org and crawl its internal links with the query
|
|
137
|
+
parameters removed from the URL
|
|
138
|
+
|
|
139
|
+
`single-file https://www.wikipedia.org --crawl-links=true --crawl-inner-links-only=true --crawl-max-depth=1 --crawl-rewrite-rule="^(.*)\\?.*$ $1"`
|
|
140
|
+
|
|
141
|
+
- Save https://www.wikipedia.org and external links only
|
|
142
|
+
|
|
143
|
+
`single-file https://www.wikipedia.org --crawl-links=true --crawl-inner-links-only=false --crawl-external-links-max-depth=1 --crawl-rewrite-rule="^.*wikipedia.*$"`
|
|
144
|
+
|
|
145
|
+
## Troubleshooting
|
|
146
|
+
|
|
147
|
+
- If the error message
|
|
148
|
+
`UnhandledPromiseRejectionWarning: Error: Browser is not downloaded. Run "npm install" or "yarn install" at ChromeLauncher.launch`
|
|
149
|
+
is displayed, it probably means that `single-file` was not able to find the
|
|
150
|
+
executable of the browser. Using the option `--browser-executable-path` to
|
|
151
|
+
pass to `single-file` the complete path of the executable fixes this issue.
|
|
152
|
+
|
|
153
|
+
- If saving a page takes an unusually long time, this may be due to a timeout
|
|
154
|
+
error that was automatically recovered. Setting `--browser-wait-until` to a
|
|
155
|
+
lower value (e.g. `networkidle0` or `load` instead of `networkidle2`) fixes
|
|
156
|
+
this issue.
|
|
157
|
+
|
|
158
|
+
## License
|
|
159
|
+
|
|
160
|
+
SingleFile is licensed under AGPL. Code derived from third-party projects is
|
|
161
|
+
licensed under MIT. Please contact me at gildas.lormeau <at> gmail.com if
|
|
162
|
+
you are interested in licensing the SingleFile code for a commercial service or
|
|
163
|
+
product.
|
package/args.js
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2010-2020 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 require, module */
|
|
25
|
+
|
|
26
|
+
const args = require("yargs")
|
|
27
|
+
.wrap(null)
|
|
28
|
+
.command("$0 [url] [output]", "Save a page into a single HTML file.", yargs => {
|
|
29
|
+
yargs.positional("url", { description: "URL or path on the filesystem of the page to save", type: "string" });
|
|
30
|
+
yargs.positional("output", { description: "Output filename", type: "string" });
|
|
31
|
+
})
|
|
32
|
+
.default({
|
|
33
|
+
"accept-headers": {
|
|
34
|
+
"font": "application/font-woff2;q=1.0,application/font-woff;q=0.9,*/*;q=0.8",
|
|
35
|
+
"image": "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
|
|
36
|
+
"stylesheet": "text/css,*/*;q=0.1",
|
|
37
|
+
"script": "*/*",
|
|
38
|
+
"document": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
|
|
39
|
+
},
|
|
40
|
+
"back-end": "puppeteer",
|
|
41
|
+
"block-mixed-content": false,
|
|
42
|
+
"browser-server": "",
|
|
43
|
+
"browser-headless": true,
|
|
44
|
+
"browser-executable-path": "",
|
|
45
|
+
"browser-width": 1280,
|
|
46
|
+
"browser-height": 720,
|
|
47
|
+
"browser-load-max-time": 60000,
|
|
48
|
+
"browser-wait-delay": 0,
|
|
49
|
+
"browser-wait-until": "networkidle0",
|
|
50
|
+
"browser-wait-until-fallback": true,
|
|
51
|
+
"browser-debug": false,
|
|
52
|
+
"browser-script": [],
|
|
53
|
+
"browser-stylesheet": [],
|
|
54
|
+
"browser-args": "",
|
|
55
|
+
"browser-start-minimized": false,
|
|
56
|
+
"browser-cookie": [],
|
|
57
|
+
"browser-cookies-file": "",
|
|
58
|
+
"compress-CSS": false,
|
|
59
|
+
"compress-HTML": true,
|
|
60
|
+
"dump-content": false,
|
|
61
|
+
"emulateMediaFeature": [],
|
|
62
|
+
"filename-template": "{page-title} ({date-iso} {time-locale}).html",
|
|
63
|
+
"filename-conflict-action": "uniquify",
|
|
64
|
+
"filename-replacement-character": "_",
|
|
65
|
+
"filename-max-length": 192,
|
|
66
|
+
"filename-max-length-unit": "bytes",
|
|
67
|
+
"group-duplicate-images": true,
|
|
68
|
+
"http-header": [],
|
|
69
|
+
"include-infobar": false,
|
|
70
|
+
"insert-meta-csp": true,
|
|
71
|
+
"load-deferred-images": true,
|
|
72
|
+
"load-deferred-images-dispatch-scroll-event": false,
|
|
73
|
+
"load-deferred-images-max-idle-time": 1500,
|
|
74
|
+
"load-deferred-images-keep-zoom-level": false,
|
|
75
|
+
"max-parallel-workers": 8,
|
|
76
|
+
"max-resource-size-enabled": false,
|
|
77
|
+
"max-resource-size": 10,
|
|
78
|
+
"move-styles-in-head": false,
|
|
79
|
+
"output-directory": "",
|
|
80
|
+
"remove-hidden-elements": true,
|
|
81
|
+
"remove-unused-styles": true,
|
|
82
|
+
"remove-unused-fonts": true,
|
|
83
|
+
"remove-frames": false,
|
|
84
|
+
"remove-imports": true,
|
|
85
|
+
"block-scripts": true,
|
|
86
|
+
"block-audios": true,
|
|
87
|
+
"block-videos": true,
|
|
88
|
+
"remove-alternative-fonts": true,
|
|
89
|
+
"remove-alternative-medias": true,
|
|
90
|
+
"remove-alternative-images": true,
|
|
91
|
+
"save-original-urls": false,
|
|
92
|
+
"save-raw-page": false,
|
|
93
|
+
"web-driver-executable-path": "",
|
|
94
|
+
"user-script-enabled": true,
|
|
95
|
+
"include-BOM": false,
|
|
96
|
+
"crawl-links": false,
|
|
97
|
+
"crawl-inner-links-only": true,
|
|
98
|
+
"crawl-remove-url-fragment": true,
|
|
99
|
+
"crawl-max-depth": 1,
|
|
100
|
+
"crawl-external-links-max-depth": 1,
|
|
101
|
+
"crawl-replace-urls": false,
|
|
102
|
+
"crawl-rewrite-rule": []
|
|
103
|
+
})
|
|
104
|
+
.options("back-end", { description: "Back-end to use" })
|
|
105
|
+
.choices("back-end", ["jsdom", "puppeteer", "webdriver-chromium", "webdriver-gecko", "puppeteer-firefox", "playwright-firefox", "playwright-chromium"])
|
|
106
|
+
.options("block-mixed-content", { description: "Block mixed contents" })
|
|
107
|
+
.boolean("block-mixed-content")
|
|
108
|
+
.options("browser-server", { description: "Server to connect to (puppeteer only for now)" })
|
|
109
|
+
.string("browser-server")
|
|
110
|
+
.options("browser-headless", { description: "Run the browser in headless mode (puppeteer, webdriver-gecko, webdriver-chromium)" })
|
|
111
|
+
.boolean("browser-headless")
|
|
112
|
+
.options("browser-executable-path", { description: "Path to chrome/chromium executable (puppeteer, webdriver-gecko, webdriver-chromium)" })
|
|
113
|
+
.string("browser-executable-path")
|
|
114
|
+
.options("browser-width", { description: "Width of the browser viewport in pixels" })
|
|
115
|
+
.number("browser-width")
|
|
116
|
+
.options("browser-height", { description: "Height of the browser viewport in pixels" })
|
|
117
|
+
.number("browser-height")
|
|
118
|
+
.options("browser-load-max-time", { description: "Maximum delay of time to wait for page loading in ms (puppeteer, webdriver-gecko, webdriver-chromium)" })
|
|
119
|
+
.number("browser-load-max-time")
|
|
120
|
+
.options("browser-wait-delay", { description: "Time to wait before capturing the page in ms" })
|
|
121
|
+
.number("browser-wait-delay")
|
|
122
|
+
.options("browser-wait-until", { description: "When to consider the page is loaded (puppeteer, webdriver-gecko, webdriver-chromium)" })
|
|
123
|
+
.choices("browser-wait-until", ["networkidle0", "networkidle2", "load", "domcontentloaded"])
|
|
124
|
+
.options("browser-wait-until-fallback", { description: "Retry with the next value of --browser-wait-until when a timeout error is thrown" })
|
|
125
|
+
.boolean("browser-wait-until-fallback")
|
|
126
|
+
.options("browser-debug", { description: "Enable debug mode (puppeteer, webdriver-gecko, webdriver-chromium)" })
|
|
127
|
+
.boolean("browser-debug")
|
|
128
|
+
.options("browser-script", { description: "Path of a script executed in the page (and all the frames) before it is loaded" })
|
|
129
|
+
.array("browser-script")
|
|
130
|
+
.options("browser-stylesheet", { description: "Path of a stylesheet file inserted into the page (and all the frames) after it is loaded" })
|
|
131
|
+
.array("browser-stylesheet")
|
|
132
|
+
.options("browser-args", { description: "Arguments provided as a JSON array and passed to the browser (puppeteer, webdriver-gecko, webdriver-chromium)" })
|
|
133
|
+
.string("browser-args")
|
|
134
|
+
.options("browser-start-minimized", { description: "Minimize the browser (puppeteer)" })
|
|
135
|
+
.boolean("browser-start-minimized")
|
|
136
|
+
.options("browser-cookie", { description: "Ordered list of cookie parameters separated by a comma: name,value,domain,path,expires,httpOnly,secure,sameSite,url (puppeteer, webdriver-gecko, webdriver-chromium, jsdom)" })
|
|
137
|
+
.array("browser-cookie")
|
|
138
|
+
.options("browser-cookies-file", { description: "Path of the cookies file formatted as a JSON file or a Netscape text file (puppeteer, webdriver-gecko, webdriver-chromium, jsdom)" })
|
|
139
|
+
.string("browser-cookies-file")
|
|
140
|
+
.options("compress-CSS", { description: "Compress CSS stylesheets" })
|
|
141
|
+
.boolean("compress-CSS")
|
|
142
|
+
.options("compress-HTML", { description: "Compress HTML content" })
|
|
143
|
+
.boolean("compress-HTML")
|
|
144
|
+
.options("crawl-links", { description: "Crawl and save pages found via inner links" })
|
|
145
|
+
.boolean("crawl-links")
|
|
146
|
+
.options("crawl-inner-links-only", { description: "Crawl pages found via inner links only if they are hosted on the same domain" })
|
|
147
|
+
.boolean("crawl-inner-links-only")
|
|
148
|
+
.options("crawl-no-parent", { description: "Crawl pages found via inner links only if their URLs are not parent of the URL to crawl" })
|
|
149
|
+
.boolean("crawl-no-parent")
|
|
150
|
+
.options("crawl-load-session", { description: "Name of the file of the session to load (previously saved with --crawl-save-session or --crawl-sync-session)" })
|
|
151
|
+
.string("crawl-load-session")
|
|
152
|
+
.options("crawl-remove-url-fragment", { description: "Remove URL fragments found in links" })
|
|
153
|
+
.boolean("crawl-remove-url-fragment")
|
|
154
|
+
.options("crawl-save-session", { description: "Name of the file where to save the state of the session" })
|
|
155
|
+
.string("crawl-save-session")
|
|
156
|
+
.options("crawl-sync-session", { description: "Name of the file where to load and save the state of the session" })
|
|
157
|
+
.string("crawl-sync-session")
|
|
158
|
+
.options("crawl-max-depth", { description: "Max depth when crawling pages found in internal and external links (0: infinite)" })
|
|
159
|
+
.number("crawl-max-depth")
|
|
160
|
+
.options("crawl-external-links-max-depth", { description: "Max depth when crawling pages found in external links (0: infinite)" })
|
|
161
|
+
.number("crawl-external-links-max-depth")
|
|
162
|
+
.options("crawl-replace-urls", { description: "Replace URLs of saved pages with relative paths of saved pages on the filesystem" })
|
|
163
|
+
.boolean("crawl-replace-urls")
|
|
164
|
+
.options("crawl-rewrite-rule", { description: "Rewrite rule used to rewrite URLs of crawled pages" })
|
|
165
|
+
.array("crawl-rewrite-rule")
|
|
166
|
+
.options("dump-content", { description: "Dump the content of the processed page in the console ('true' when running in Docker)" })
|
|
167
|
+
.boolean("dump-content")
|
|
168
|
+
.options("emulate-media-feature", { description: "Emulate a media feature. The syntax is <name>:<value>, e.g. \"prefers-color-scheme:dark\" (puppeteer)" })
|
|
169
|
+
.array("emulate-media-feature")
|
|
170
|
+
.options("error-file")
|
|
171
|
+
.string("error-file")
|
|
172
|
+
.options("filename-template", { description: "Template used to generate the output filename (see help page of the extension for more info)" })
|
|
173
|
+
.string("filename-template")
|
|
174
|
+
.options("filename-conflict-action", { description: "Action when the filename is conflicting with existing one on the filesystem. The possible values are \"uniquify\" (default), \"overwrite\" and \"skip\"" })
|
|
175
|
+
.string("filename-conflict-action")
|
|
176
|
+
.options("filename-replacement-character", { description: "The character used for replacing invalid characters in filenames" })
|
|
177
|
+
.string("filename-replacement-character")
|
|
178
|
+
.options("filename-max-length", { description: "Specify the maximum length of the filename" })
|
|
179
|
+
.number("filename-max-length")
|
|
180
|
+
.options("filename-max-length-unit", { description: "Specify the unit of the maximum length of the filename ('bytes' or 'chars')" })
|
|
181
|
+
.string("filename-max-length-unit")
|
|
182
|
+
.options("group-duplicate-images", { description: "Group duplicate images into CSS custom properties" })
|
|
183
|
+
.boolean("group-duplicate-images")
|
|
184
|
+
.options("http-header", { description: "Extra HTTP header (puppeteer, jsdom)" })
|
|
185
|
+
.array("http-header")
|
|
186
|
+
.options("include-BOM", { description: "Include the UTF-8 BOM into the HTML page" })
|
|
187
|
+
.boolean("include-BOM")
|
|
188
|
+
.options("include-infobar", { description: "Include the infobar" })
|
|
189
|
+
.boolean("include-infobar")
|
|
190
|
+
.options("insert-meta-csp", { description: "Include a <meta> tag with a CSP to avoid potential requests to internet when viewing a page" })
|
|
191
|
+
.boolean("insert-meta-csp")
|
|
192
|
+
.options("load-deferred-images", { description: "Load deferred (a.k.a. lazy-loaded) images (puppeteer, webdriver-gecko, webdriver-chromium)" })
|
|
193
|
+
.boolean("load-deferred-images")
|
|
194
|
+
.options("load-deferred-images-dispatch-scroll-event", { description: "Dispatch 'scroll' event when loading deferred images" })
|
|
195
|
+
.boolean("load-deferred-images-dispatch-scroll-event")
|
|
196
|
+
.options("load-deferred-images-max-idle-time", { description: "Maximum delay of time to wait for deferred images in ms (puppeteer, webdriver-gecko, webdriver-chromium)" })
|
|
197
|
+
.number("load-deferred-images-max-idle-time")
|
|
198
|
+
.options("load-deferred-images-keep-zoom-level", { description: "Load deferred images by keeping zoomed out the page" })
|
|
199
|
+
.boolean("load-deferred-images-keep-zoom-level")
|
|
200
|
+
.options("max-parallel-workers", { description: "Maximum number of browsers launched in parallel when processing a list of URLs (cf --urls-file)" })
|
|
201
|
+
.number("max-parallel-workers")
|
|
202
|
+
.options("max-resource-size-enabled", { description: "Enable removal of embedded resources exceeding a given size" })
|
|
203
|
+
.boolean("max-resource-size-enabled")
|
|
204
|
+
.options("max-resource-size", { description: "Maximum size of embedded resources in MB (i.e. images, stylesheets, scripts and iframes)" })
|
|
205
|
+
.number("max-resource-size")
|
|
206
|
+
.options("move-styles-in-head", { description: "Move style elements outside the head element into the head element" })
|
|
207
|
+
.boolean("move-styles-in-head")
|
|
208
|
+
.options("remove-frames", { description: "Remove frames (puppeteer, webdriver-gecko, webdriver-chromium)" })
|
|
209
|
+
.boolean("remove-frames")
|
|
210
|
+
.options("remove-hidden-elements", { description: "Remove HTML elements which are not displayed" })
|
|
211
|
+
.boolean("remove-hidden-elements")
|
|
212
|
+
.options("remove-unused-styles", { description: "Remove unused CSS rules and unneeded declarations" })
|
|
213
|
+
.boolean("remove-unused-styles")
|
|
214
|
+
.options("remove-unused-fonts", { description: "Remove unused CSS font rules" })
|
|
215
|
+
.boolean("remove-unused-fonts")
|
|
216
|
+
.options("remove-imports", { description: "Remove HTML imports" })
|
|
217
|
+
.boolean("remove-imports")
|
|
218
|
+
.options("block-scripts", { description: "Block scripts" })
|
|
219
|
+
.boolean("block-scripts")
|
|
220
|
+
.options("block-audios", { description: "Block audio elements" })
|
|
221
|
+
.boolean("block-audios")
|
|
222
|
+
.options("block-videos", { description: "Block video elements" })
|
|
223
|
+
.boolean("block-videos")
|
|
224
|
+
.options("remove-alternative-fonts", { description: "Remove alternative fonts to the ones displayed" })
|
|
225
|
+
.boolean("remove-alternative-fonts")
|
|
226
|
+
.options("remove-alternative-medias", { description: "Remove alternative CSS stylesheets" })
|
|
227
|
+
.boolean("remove-alternative-medias")
|
|
228
|
+
.options("remove-alternative-images", { description: "Remove images for alternative sizes of screen" })
|
|
229
|
+
.boolean("remove-alternative-images")
|
|
230
|
+
.options("save-original-urls", { description: "Save the original URLS in the embedded contents" })
|
|
231
|
+
.boolean("save-original-urls")
|
|
232
|
+
.options("save-raw-page", { description: "Save the original page without interpreting it into the browser (puppeteer, webdriver-gecko, webdriver-chromium)" })
|
|
233
|
+
.boolean("save-raw-page")
|
|
234
|
+
.options("urls-file", { description: "Path to a text file containing a list of URLs (separated by a newline) to save" })
|
|
235
|
+
.string("urls-file")
|
|
236
|
+
.options("user-agent", { description: "User-agent of the browser (puppeteer, webdriver-gecko, webdriver-chromium)" })
|
|
237
|
+
.string("user-agent")
|
|
238
|
+
.options("user-script-enabled", { description: "Enable the event API allowing to execute scripts before the page is saved" })
|
|
239
|
+
.boolean("user-script-enabled")
|
|
240
|
+
.options("web-driver-executable-path", { description: "Path to Selenium WebDriver executable (webdriver-gecko, webdriver-chromium)" })
|
|
241
|
+
.string("web-driver-executable-path")
|
|
242
|
+
.options("output-directory", { description: "Path to where to save files, this path must exist." })
|
|
243
|
+
.string("output-directory")
|
|
244
|
+
.argv;
|
|
245
|
+
args.backgroundSave = true;
|
|
246
|
+
args.compressCSS = args.compressCss;
|
|
247
|
+
args.compressHTML = args.compressHtml;
|
|
248
|
+
args.includeBOM = args.includeBom;
|
|
249
|
+
args.crawlReplaceURLs = args.crawlReplaceUrls;
|
|
250
|
+
args.crawlRemoveURLFragment = args.crawlRemoveUrlFragment;
|
|
251
|
+
args.insertMetaCSP = args.insertMetaCsp;
|
|
252
|
+
if (args.removeScripts) {
|
|
253
|
+
args.blockScripts = true;
|
|
254
|
+
}
|
|
255
|
+
if (args.removeAudioSrc) {
|
|
256
|
+
args.blockAudios = true;
|
|
257
|
+
}
|
|
258
|
+
if (args.removeVideoSrc) {
|
|
259
|
+
args.blockVideos = true;
|
|
260
|
+
}
|
|
261
|
+
const headers = args.httpHeader;
|
|
262
|
+
delete args.httpHeader;
|
|
263
|
+
args.httpHeaders = {};
|
|
264
|
+
headers.forEach(header => {
|
|
265
|
+
const matchedHeader = header.match(/^(.*?):(.*)$/);
|
|
266
|
+
if (matchedHeader.length == 3) {
|
|
267
|
+
args.httpHeaders[matchedHeader[1].trim()] = matchedHeader[2].trimLeft();
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
const cookies = args.browserCookie;
|
|
271
|
+
delete args.browserCookie;
|
|
272
|
+
args.browserCookies = cookies.map(cookieValue => {
|
|
273
|
+
const value = cookieValue.split(/(?<!\\),/);
|
|
274
|
+
return {
|
|
275
|
+
name: value[0],
|
|
276
|
+
value: value[1],
|
|
277
|
+
domain: value[2] || undefined,
|
|
278
|
+
path: value[3] || undefined,
|
|
279
|
+
expires: value[4] && Number(value[4]) || undefined,
|
|
280
|
+
httpOnly: value[5] && value[5] == "true" || undefined,
|
|
281
|
+
secure: value[6] && value[5] == "true" || undefined,
|
|
282
|
+
sameSite: value[7] || undefined,
|
|
283
|
+
url: value[8] || undefined
|
|
284
|
+
};
|
|
285
|
+
});
|
|
286
|
+
args.browserScripts = args.browserScript;
|
|
287
|
+
delete args.browserScript;
|
|
288
|
+
args.browserStylesheets = args.browserStylesheet;
|
|
289
|
+
delete args.browserStylesheet;
|
|
290
|
+
args.crawlRewriteRules = args.crawlRewriteRule;
|
|
291
|
+
delete args.crawlRewriteRule;
|
|
292
|
+
args.emulateMediaFeatures = args.emulateMediaFeature
|
|
293
|
+
.map(value => {
|
|
294
|
+
const splitValue = value.match(/^([^:]+):(.*)$/);
|
|
295
|
+
if (splitValue.length >= 3) {
|
|
296
|
+
return { name: splitValue[1].trim(), value: splitValue[2].trim() };
|
|
297
|
+
}
|
|
298
|
+
})
|
|
299
|
+
.filter(identity => identity);
|
|
300
|
+
delete args.emulateMediaFeature;
|
|
301
|
+
Object.keys(args).filter(optionName => optionName.includes("-"))
|
|
302
|
+
.forEach(optionName => delete args[optionName]);
|
|
303
|
+
delete args["$0"];
|
|
304
|
+
delete args["_"];
|
|
305
|
+
module.exports = args;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2010-2020 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 require, exports */
|
|
25
|
+
|
|
26
|
+
const fs = require("fs");
|
|
27
|
+
|
|
28
|
+
const SCRIPTS = [
|
|
29
|
+
"lib/single-file.js",
|
|
30
|
+
"lib/single-file-bootstrap.js",
|
|
31
|
+
"lib/single-file-hooks.js",
|
|
32
|
+
"lib/single-file-hooks-frames.js"
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
const basePath = "./../../";
|
|
36
|
+
|
|
37
|
+
exports.get = async options => {
|
|
38
|
+
let scripts = "let _singleFileDefine; if (typeof define !== 'undefined') { _singleFileDefine = define; define = null }";
|
|
39
|
+
scripts += await readScriptFiles(SCRIPTS, basePath);
|
|
40
|
+
scripts += await readScriptFiles(options && options.browserScripts ? options.browserScripts : [], "");
|
|
41
|
+
if (options.browserStylesheets && options.browserStylesheets.length) {
|
|
42
|
+
scripts += "addEventListener(\"load\",()=>{const styleElement=document.createElement(\"style\");styleElement.textContent=" + JSON.stringify(await readScriptFiles(options.browserStylesheets, "")) + ";document.body.appendChild(styleElement);});";
|
|
43
|
+
}
|
|
44
|
+
scripts += "if (_singleFileDefine) { define = _singleFileDefine; _singleFileDefine = null }";
|
|
45
|
+
return scripts;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
exports.getInfobarScript = () => {
|
|
49
|
+
return readScriptFile("lib/single-file-infobar.js", basePath);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
async function readScriptFiles(paths, basePath = "../../../") {
|
|
53
|
+
return (await Promise.all(paths.map(path => readScriptFile(path, basePath)))).join("");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function readScriptFile(path, basePath) {
|
|
57
|
+
return new Promise((resolve, reject) =>
|
|
58
|
+
fs.readFile(basePath ? require.resolve(basePath + path) : path, (err, data) => {
|
|
59
|
+
if (err) {
|
|
60
|
+
reject(err);
|
|
61
|
+
} else {
|
|
62
|
+
resolve(data.toString() + "\n");
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
);
|
|
66
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2010-2020 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
|
+
const removedHeaders = ["content-security-policy"];
|
|
25
|
+
|
|
26
|
+
const browserAPI = this.browser || this.chrome;
|
|
27
|
+
|
|
28
|
+
browserAPI.webRequest.onHeadersReceived.addListener(
|
|
29
|
+
function (details) {
|
|
30
|
+
let responseHeaders = details.responseHeaders;
|
|
31
|
+
responseHeaders = responseHeaders.filter(responseHeader => !removedHeaders.includes(responseHeader.name.toLowerCase()));
|
|
32
|
+
return { responseHeaders };
|
|
33
|
+
},
|
|
34
|
+
{ urls: ["<all_urls>"] },
|
|
35
|
+
["blocking", "responseHeaders"]
|
|
36
|
+
);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bypass-csp",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"background": {
|
|
5
|
+
"scripts": [
|
|
6
|
+
"index.js"
|
|
7
|
+
]
|
|
8
|
+
},
|
|
9
|
+
"permissions": [
|
|
10
|
+
"webRequest",
|
|
11
|
+
"webRequestBlocking",
|
|
12
|
+
"<all_urls>"
|
|
13
|
+
],
|
|
14
|
+
"browser_specific_settings": {
|
|
15
|
+
"gecko": {
|
|
16
|
+
"id": "{55e2789c-817b-4d75-815b-df6921c84ed8}"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"manifest_version": 2
|
|
20
|
+
}
|