single-file-cli 1.1.53 → 2.0.2

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.
Files changed (43) hide show
  1. package/{.eslintrc.js → .eslintrc.json} +5 -6
  2. package/Dockerfile +2 -1
  3. package/README.MD +56 -60
  4. package/args.js +252 -334
  5. package/back-ends/chromium-back-end.js +223 -0
  6. package/back-ends/chromium-browser.js +89 -0
  7. package/back-ends/chromium-constants.js +157 -0
  8. package/back-ends/{common/scripts.js → single-file-script.js} +21 -49
  9. package/build-lib-dev.sh +84 -0
  10. package/build-lib.sh +80 -3
  11. package/compile.sh +13 -0
  12. package/deno-polyfill.js +223 -0
  13. package/deno.json +13 -0
  14. package/deno.lock +49 -0
  15. package/lib/single-file-bundle.js +1 -0
  16. package/package.json +9 -33
  17. package/single-file +39 -14
  18. package/single-file-cli-api.js +32 -44
  19. package/back-ends/extensions/bypass-csp/index.js +0 -36
  20. package/back-ends/extensions/bypass-csp/manifest.json +0 -20
  21. package/back-ends/extensions/disable-web-security/index.js +0 -54
  22. package/back-ends/extensions/disable-web-security/manifest.json +0 -20
  23. package/back-ends/extensions/network-idle/bg.js +0 -61
  24. package/back-ends/extensions/network-idle/content.js +0 -29
  25. package/back-ends/extensions/network-idle/manifest.json +0 -31
  26. package/back-ends/extensions/signed/bypass_csp-0.0.3-an+fx.xpi +0 -0
  27. package/back-ends/extensions/signed/disable_web_security-0.0.3-an+fx.xpi +0 -0
  28. package/back-ends/extensions/signed/network_idle-0.0.2-an+fx.xpi +0 -0
  29. package/back-ends/jsdom.js +0 -159
  30. package/back-ends/playwright-chromium.js +0 -126
  31. package/back-ends/playwright-firefox.js +0 -115
  32. package/back-ends/playwright-webkit.js +0 -126
  33. package/back-ends/puppeteer-firefox.js +0 -172
  34. package/back-ends/puppeteer.js +0 -201
  35. package/back-ends/webdriver-chromium.js +0 -172
  36. package/back-ends/webdriver-gecko.js +0 -190
  37. package/lib/single-file-bootstrap.js +0 -1
  38. package/lib/single-file-frames.js +0 -1
  39. package/lib/single-file-hooks-frames.js +0 -1
  40. package/lib/single-file-zip.min.js +0 -1
  41. package/lib/single-file.js +0 -1
  42. package/rollup.config.dev.js +0 -57
  43. package/rollup.config.js +0 -58
@@ -1,201 +0,0 @@
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 singlefile, require, exports, setTimeout */
25
-
26
- const puppeteer = require("puppeteer-core");
27
- const scripts = require("./common/scripts.js");
28
-
29
- const EXECUTION_CONTEXT_DESTROYED_ERROR = "Execution context was destroyed";
30
- const NETWORK_IDLE_STATE = "networkidle0";
31
- const NETWORK_STATES = ["networkidle0", "networkidle2", "load", "domcontentloaded"];
32
-
33
- let browser, context;
34
-
35
- exports.initialize = async options => {
36
- if (options.browserServer) {
37
- browser = await puppeteer.connect({ browserWSEndpoint: options.browserServer });
38
- } else {
39
- browser = await puppeteer.launch(getBrowserOptions(options));
40
- }
41
- return browser;
42
- };
43
-
44
- exports.getPageData = async (options, page) => {
45
- const privatePage = !page;
46
- try {
47
- if (privatePage) {
48
- const contextOptions = {};
49
- if (options.httpProxyServer) {
50
- contextOptions.proxyServer = options.httpProxyServer;
51
- }
52
- context = await browser.createBrowserContext(contextOptions);
53
- page = await context.newPage();
54
- }
55
- await setPageOptions(page, options);
56
- return await getPageData(context || browser, page, options);
57
- } finally {
58
- if (privatePage && !options.browserDebug) {
59
- await page.close();
60
- }
61
- }
62
- };
63
-
64
- exports.closeBrowser = () => {
65
- if (browser) {
66
- return browser.close();
67
- }
68
- };
69
-
70
- function getBrowserOptions(options = {}) {
71
- const browserOptions = {};
72
- if (options.browserHeadless !== undefined) {
73
- browserOptions.headless = options.browserHeadless && !options.browserDebug;
74
- }
75
- if (options.browserIgnoreInsecureCerts !== undefined) {
76
- browserOptions.ignoreHTTPSErrors = options.browserIgnoreInsecureCerts;
77
- }
78
- browserOptions.args = options.browserArgs ? JSON.parse(options.browserArgs) : [];
79
- if (options.browserDisableWebSecurity === undefined || options.browserDisableWebSecurity) {
80
- browserOptions.args.push("--disable-web-security");
81
- }
82
- browserOptions.args.push("--no-pings");
83
- if (!options.browserStartMinimized && options.browserDebug) {
84
- browserOptions.args.push("--auto-open-devtools-for-tabs");
85
- }
86
- if (options.browserWidth && options.browserHeight) {
87
- browserOptions.args.push("--window-size=" + options.browserWidth + "," + options.browserHeight);
88
- }
89
- browserOptions.executablePath = options.browserExecutablePath || "chrome";
90
- if (options.userAgent) {
91
- browserOptions.args.push("--user-agent=" + options.userAgent);
92
- }
93
- return browserOptions;
94
- }
95
-
96
- async function setPageOptions(page, options) {
97
- if (options.browserWidth && options.browserHeight) {
98
- await page.setViewport({
99
- width: options.browserWidth,
100
- height: options.browserHeight
101
- });
102
- }
103
- if (options.browserBypassCSP === undefined || options.browserBypassCSP) {
104
- await page.setBypassCSP(true);
105
- }
106
- if (options.httpHeaders) {
107
- page.setExtraHTTPHeaders(options.httpHeaders);
108
- }
109
- if (options.browserStartMinimized) {
110
- const session = await page.target().createCDPSession();
111
- const { windowId } = await session.send("Browser.getWindowForTarget");
112
- await session.send("Browser.setWindowBounds", { windowId, bounds: { windowState: "minimized" } });
113
- }
114
- if (options.browserCookies && options.browserCookies.length) {
115
- await page.setCookie(...options.browserCookies);
116
- }
117
- if (options.emulateMediaFeatures) {
118
- await page.emulateMediaFeatures(options.emulateMediaFeatures);
119
- }
120
- if (options.httpProxyServer && (options.httpProxyUsername || options.httpProxyPassword)) {
121
- await page.authenticate({
122
- username: options.httpProxyUsername,
123
- password: options.httpProxyPassword
124
- });
125
- }
126
- }
127
-
128
- async function getPageData(context, page, options) {
129
- const injectedScript = await scripts.get(options);
130
- await page.evaluateOnNewDocument(injectedScript);
131
- if (options.browserDebug) {
132
- await new Promise(resolve => setTimeout(resolve, 3000));
133
- }
134
- try {
135
- await pageGoto(page, options);
136
- } catch (error) {
137
- if (options.browserWaitUntilFallback && error.name == "TimeoutError") {
138
- const browserWaitUntil = NETWORK_STATES[(NETWORK_STATES.indexOf(options.browserWaitUntil) + 1)];
139
- if (browserWaitUntil) {
140
- options.browserWaitUntil = browserWaitUntil;
141
- return getPageData(context, page, options);
142
- } else {
143
- throw error;
144
- }
145
- } else if (error.name != "TimeoutError") {
146
- throw error;
147
- }
148
- }
149
- try {
150
- if (options.browserWaitDelay) {
151
- await new Promise(resolve => setTimeout(resolve, options.browserWaitDelay));
152
- }
153
- const pageData = await page.evaluate(async options => await singlefile.getPageData(options), options);
154
- if (options.compressContent) {
155
- pageData.content = new Uint8Array(pageData.content);
156
- }
157
- return pageData;
158
- } catch (error) {
159
- if (error.message && error.message.includes(EXECUTION_CONTEXT_DESTROYED_ERROR)) {
160
- const pageData = await handleJSRedirect(context, options);
161
- if (pageData) {
162
- return pageData;
163
- } else {
164
- throw error;
165
- }
166
- } else {
167
- throw error;
168
- }
169
- }
170
- }
171
-
172
- async function handleJSRedirect(context, options) {
173
- const pages = await context.pages();
174
- const page = pages[1] || pages[0];
175
- try {
176
- await pageGoto(page, options);
177
- } catch (error) {
178
- if (error.name != "TimeoutError") {
179
- throw error;
180
- }
181
- }
182
- const url = page.url();
183
- if (url != options.url) {
184
- options.url = url;
185
- await context.close();
186
- return exports.getPageData(options);
187
- }
188
- }
189
-
190
- async function pageGoto(page, options) {
191
- const loadOptions = {
192
- timeout: options.browserLoadMaxTime || 0,
193
- waitUntil: options.browserWaitUntil || NETWORK_IDLE_STATE
194
- };
195
- if (options.content) {
196
- await page.goto(options.url, { waitUntil: "domcontentloaded" });
197
- await page.setContent(options.content, loadOptions);
198
- } else {
199
- await page.goto(options.url, loadOptions);
200
- }
201
- }
@@ -1,172 +0,0 @@
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, setTimeout, clearTimeout */
25
-
26
- const chrome = require("selenium-webdriver/chrome");
27
- const { Builder, Capabilities } = require("selenium-webdriver");
28
-
29
- exports.initialize = async () => { };
30
-
31
- exports.getPageData = async options => {
32
- let driver;
33
- try {
34
- const builder = new Builder();
35
- if (options.webDriverExecutablePath) {
36
- builder.setChromeService(new chrome.ServiceBuilder(options.webDriverExecutablePath));
37
- }
38
- builder.setChromeOptions(getBrowserOptions(options));
39
- setBuilderCapabilities(builder, options);
40
- driver = builder.forBrowser("chrome").build();
41
- return await getPageData(driver, options);
42
- } finally {
43
- if (driver) {
44
- driver.quit();
45
- }
46
- }
47
- };
48
-
49
- exports.closeBrowser = () => { };
50
-
51
- function setBuilderCapabilities(builder, options) {
52
- if (options.browserIgnoreInsecureCerts !== undefined && options.browserIgnoreInsecureCerts) {
53
- const capabilities = new Capabilities();
54
- capabilities.setAcceptInsecureCerts(true);
55
- builder.withCapabilities(capabilities);
56
- }
57
- }
58
-
59
- function getBrowserOptions(options) {
60
- const chromeOptions = new chrome.Options();
61
- const optionHeadless = (options.browserHeadless === undefined || options.browserHeadless) && !options.browserDebug;
62
- if (optionHeadless) {
63
- chromeOptions.addArguments("--headless");
64
- }
65
- if (options.browserExecutablePath) {
66
- chromeOptions.setChromeBinaryPath(options.browserExecutablePath);
67
- }
68
- if (options.browserArgs) {
69
- const args = JSON.parse(options.browserArgs);
70
- args.forEach(argument => chromeOptions.addArguments(argument));
71
- }
72
- if (options.browserDisableWebSecurity === undefined || options.browserDisableWebSecurity) {
73
- chromeOptions.addArguments("--disable-web-security");
74
- }
75
- chromeOptions.addArguments("--no-pings");
76
- if (!optionHeadless) {
77
- if (options.browserDebug) {
78
- chromeOptions.addArguments("--auto-open-devtools-for-tabs");
79
- }
80
- const extensions = [];
81
- if (options.browserBypassCSP === undefined || options.browserBypassCSP) {
82
- extensions.push(require.resolve("./extensions/signed/bypass_csp-0.0.3-an+fx.xpi"));
83
- }
84
- if (options.browserWaitUntil === undefined || options.browserWaitUntil == "networkidle0" || options.browserWaitUntil == "networkidle2") {
85
- extensions.push(require.resolve("./extensions/signed/network_idle-0.0.2-an+fx.xpi"));
86
- }
87
- chromeOptions.addExtensions(extensions);
88
- }
89
- if (options.userAgent) {
90
- chromeOptions.addArguments("--user-agent=" + JSON.stringify(options.userAgent));
91
- }
92
- if (options.browserMobileEmulation) {
93
- chromeOptions.setMobileEmulation({
94
- deviceName: options.browserMobileEmulation
95
- });
96
- }
97
- return chromeOptions;
98
- }
99
-
100
- async function getPageData(driver, options) {
101
- const optionHeadless = (options.browserHeadless === undefined || options.browserHeadless) && !options.browserDebug;
102
- driver.manage().setTimeouts({ script: options.browserLoadMaxTime, pageLoad: options.browserLoadMaxTime, implicit: options.browserLoadMaxTime });
103
- if (options.browserWidth && options.browserHeight) {
104
- const window = driver.manage().window();
105
- if (window.setRect) {
106
- window.setRect(options.browserHeight, options.browserWidth);
107
- } else if (window.setSize) {
108
- window.setSize(options.browserWidth, options.browserHeight);
109
- }
110
- }
111
- const scripts = await require("./common/scripts.js").get(options);
112
- if (options.browserDebug) {
113
- // await driver.sleep(3000);
114
- }
115
- await driver.get(options.url);
116
- if (options.browserCookies) {
117
- await Promise.all(options.browserCookies.map(cookie => {
118
- if (cookie.expires) {
119
- cookie.expiry = cookie.expires;
120
- delete cookie.expires;
121
- }
122
- return driver.manage().addCookie(cookie);
123
- }));
124
- await driver.get(options.url);
125
- }
126
- await driver.executeScript(scripts);
127
- if (options.browserWaitUntil != "domcontentloaded") {
128
- let scriptPromise;
129
- if (!optionHeadless && (options.browserWaitUntil === undefined || options.browserWaitUntil == "networkidle0")) {
130
- scriptPromise = driver.executeAsyncScript("addEventListener(\"single-file-network-idle-0\", () => arguments[0](), true)");
131
- } else if (!optionHeadless && options.browserWaitUntil == "networkidle2") {
132
- scriptPromise = driver.executeAsyncScript("addEventListener(\"single-file-network-idle-2\", () => arguments[0](), true)");
133
- } else if (optionHeadless || options.browserWaitUntil == "load") {
134
- scriptPromise = driver.executeAsyncScript("if (document.readyState == \"loading\" || document.readyState == \"interactive\") { addEventListener(\"load\", () => arguments[0]()) } else { arguments[0](); }");
135
- }
136
- let cancelTimeout;
137
- const timeoutPromise = new Promise(resolve => {
138
- const timeoutId = setTimeout(resolve, Math.max(0, options.browserLoadMaxTime - 5000));
139
- cancelTimeout = () => {
140
- clearTimeout(timeoutId);
141
- resolve();
142
- };
143
- });
144
- await Promise.race([scriptPromise, timeoutPromise]);
145
- cancelTimeout();
146
- }
147
- if (options.browserWaitDelay) {
148
- await driver.sleep(options.browserWaitDelay);
149
- }
150
- const result = await driver.executeAsyncScript(getPageDataScript(), options);
151
- if (result.error) {
152
- throw result.error;
153
- } else {
154
- if (options.compressContent) {
155
- result.pageData.content = new Uint8Array(result.pageData.content);
156
- }
157
- return result.pageData;
158
- }
159
- }
160
-
161
- function getPageDataScript() {
162
- return `
163
- const [options, callback] = arguments;
164
- getPageData()
165
- .then(pageData => callback({ pageData }))
166
- .catch(error => callback({ error: error && error.toString() }));
167
-
168
- async function getPageData() {
169
- return await singlefile.getPageData(options);
170
- }
171
- `;
172
- }
@@ -1,190 +0,0 @@
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, process, setTimeout, clearTimeout */
25
-
26
- const firefox = require("selenium-webdriver/firefox");
27
- const { Builder, By, Key, Capabilities } = require("selenium-webdriver");
28
-
29
- exports.initialize = async () => { };
30
-
31
- exports.getPageData = async options => {
32
- let driver;
33
- try {
34
- const builder = new Builder().withCapabilities({ "pageLoadStrategy": "none" });
35
- if (options.webDriverExecutablePath) {
36
- builder.setFirefoxService(new firefox.ServiceBuilder(options.webDriverExecutablePath));
37
- }
38
- builder.setFirefoxOptions(getBrowserOptions(options));
39
- setBuilderCapabilities(builder, options);
40
- driver = builder.forBrowser("firefox").build();
41
- return await getPageData(driver, options);
42
- } finally {
43
- if (driver) {
44
- driver.quit();
45
- }
46
- }
47
- };
48
-
49
- exports.closeBrowser = () => { };
50
-
51
- function setBuilderCapabilities(builder, options) {
52
- if (options.browserIgnoreInsecureCerts !== undefined && options.browserIgnoreInsecureCerts) {
53
- const capabilities = new Capabilities();
54
- capabilities.setAcceptInsecureCerts(true);
55
- builder.withCapabilities(capabilities);
56
- }
57
- }
58
-
59
- function getBrowserOptions(options) {
60
- const firefoxOptions = new firefox.Options().setBinary(firefox.Channel.NIGHTLY);
61
- if ((options.browserHeadless === undefined || options.browserHeadless) && !options.browserDebug) {
62
- process.env["MOZ_HEADLESS"] = "1";
63
- }
64
- if (options.browserExecutablePath) {
65
- firefoxOptions.setBinary(options.browserExecutablePath);
66
- }
67
- const extensions = [];
68
- if (options.browserDisableWebSecurity === undefined || options.browserDisableWebSecurity) {
69
- extensions.push(require.resolve("./extensions/signed/disable_web_security-0.0.3-an+fx.xpi"));
70
- }
71
- if (options.browserBypassCSP === undefined || options.browserBypassCSP) {
72
- extensions.push(require.resolve("./extensions/signed/bypass_csp-0.0.3-an+fx.xpi"));
73
- }
74
- if (options.browserWaitUntil === undefined || options.browserWaitUntil == "networkidle0" || options.browserWaitUntil == "networkidle2") {
75
- extensions.push(require.resolve("./extensions/signed/network_idle-0.0.2-an+fx.xpi"));
76
- }
77
- if (extensions.length) {
78
- firefoxOptions.addExtensions(extensions);
79
- }
80
- if (options.browserArgs) {
81
- const args = JSON.parse(options.browserArgs);
82
- args.forEach(argument => firefoxOptions.addArguments(argument));
83
- }
84
- if (options.userAgent) {
85
- firefoxOptions.setPreference("general.useragent.override", options.userAgent);
86
- }
87
- return firefoxOptions;
88
- }
89
-
90
- async function getPageData(driver, options) {
91
- driver.manage().setTimeouts({ script: options.browserLoadMaxTime || 0, pageLoad: options.browserLoadMaxTime || 0, implicit: options.browserLoadMaxTime || 0 });
92
- if (options.browserWidth && options.browserHeight) {
93
- const window = driver.manage().window();
94
- if (window.setRect) {
95
- window.setRect(options.browserHeight, options.browserWidth);
96
- } else if (window.setSize) {
97
- window.setSize(options.browserWidth, options.browserHeight);
98
- }
99
- }
100
- let scripts = await require("./common/scripts.js").get(options);
101
- if (options.browserDebug) {
102
- await driver.findElement(By.css("html")).sendKeys(Key.SHIFT + Key.F5);
103
- await driver.sleep(3000);
104
- }
105
- scripts = scripts.replace(/globalThis/g, "window");
106
- await driver.get(options.url);
107
- if (options.browserCookies) {
108
- await Promise.all(options.browserCookies.map(cookie => {
109
- if (cookie.expires) {
110
- cookie.expiry = cookie.expires;
111
- }
112
- return driver.manage().addCookie(cookie);
113
- }));
114
- await driver.get("about:blank");
115
- await driver.get(options.url);
116
- while (await driver.getCurrentUrl() == "about:blank") {
117
- // do nothing
118
- }
119
- }
120
- await driver.executeScript(scripts);
121
- if (options.browserWaitUntil != "domcontentloaded") {
122
- let scriptPromise;
123
- /*
124
- if (options.browserWaitUntil == "networkidle0") {
125
- scriptPromise = driver.executeAsyncScript("addEventListener(\"single-file-network-idle-0\", () => arguments[0](), true)");
126
- } else if (options.browserWaitUntil == "networkidle2") {
127
- scriptPromise = driver.executeAsyncScript("addEventListener(\"single-file-network-idle-2\", () => arguments[0](), true)");
128
- } else if (options.browserWaitUntil === undefined || options.browserWaitUntil == "load") {
129
- */
130
- scriptPromise = driver.executeAsyncScript("if (document.readyState == \"loading\" || document.readyState == \"interactive\") { addEventListener(\"load\", () => arguments[0]()) } else { arguments[0](); }");
131
- /*
132
- }
133
- */
134
- let cancelTimeout;
135
- const timeoutPromise = new Promise(resolve => {
136
- const timeoutId = setTimeout(resolve, Math.max(0, options.browserLoadMaxTime - 5000));
137
- cancelTimeout = () => {
138
- clearTimeout(timeoutId);
139
- resolve();
140
- };
141
- });
142
- await Promise.race([scriptPromise, timeoutPromise]);
143
- cancelTimeout();
144
- }
145
- if (!options.removeFrames) {
146
- await executeScriptInFrames(driver, scripts);
147
- }
148
- if (options.browserWaitDelay) {
149
- await driver.sleep(options.browserWaitDelay);
150
- }
151
- const result = await driver.executeAsyncScript(getPageDataScript(), options);
152
- if (result.error) {
153
- throw result.error;
154
- } else {
155
- if (options.compressContent) {
156
- result.pageData.content = new Uint8Array(result.pageData.content);
157
- }
158
- return result.pageData;
159
- }
160
- }
161
-
162
- async function executeScriptInFrames(driver, scripts) {
163
- let finished = false, indexFrame = 0;
164
- while (!finished) {
165
- try {
166
- await driver.switchTo().frame(indexFrame);
167
- } catch (error) {
168
- finished = true;
169
- }
170
- if (!finished) {
171
- await driver.executeScript(scripts);
172
- await executeScriptInFrames(driver, scripts);
173
- indexFrame++;
174
- await driver.switchTo().parentFrame();
175
- }
176
- }
177
- }
178
-
179
- function getPageDataScript() {
180
- return `
181
- let [options, callback] = arguments;
182
- getPageData()
183
- .then(pageData => callback({ pageData }))
184
- .catch(error => callback({ error: error && error.toString() }));
185
-
186
- async function getPageData() {
187
- return await window.singlefile.getPageData(options);
188
- }
189
- `;
190
- }
@@ -1 +0,0 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).singlefileBootstrap={})}(this,(function(e){"use strict";const t="single-file-load-deferred-images-start",s="single-file-load-deferred-images-end",o="single-file-load-deferred-images-keep-zoom-level-start",n="single-file-load-deferred-images-keep-zoom-level-end",a="single-file-block-cookies-start",i="single-file-block-cookies-end",r="single-file-dispatch-scroll-event-start",l="single-file-dispatch-scroll-event-end",d="single-file-block-storage-start",c="single-file-block-storage-end",m="single-file-load-image",u="single-file-image-loaded",p="_singleFile_fontFaces",g=globalThis.CustomEvent,h=globalThis.document,f=globalThis.Document,E=globalThis.JSON,T=globalThis.MutationObserver;let b;function y(){h instanceof f&&(h.addEventListener("single-file-new-font-face",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,b.set(E.stringify(s),t)})),h.addEventListener("single-file-delete-font",(e=>{const t=e.detail,s=Object.assign({},t);delete s.src,b.delete(E.stringify(s))})),h.addEventListener("single-file-clear-fonts",(()=>b=new Map)))}b=window[p]?window[p]:window[p]=new Map,y(),new T(y).observe(h,{childList:!0});const I="[\\x20\\t\\r\\n\\f]",w=new RegExp("\\\\([\\da-f]{1,6}"+I+"?|("+I+")|.)","ig");const A="single-file-",v="_singleFile_waitForUserScript",S="__frameTree__::",R=A+"on-before-capture",N=A+"on-after-capture",P=A+"request-get-adopted-stylesheets",_=A+"response-get-adopted-stylesheets",M=A+"unregister-request-get-adopted-stylesheets",C=A+"user-script-init",O="data-"+A+"removed-content",L="data-"+A+"hidden-content",D="data-"+A+"kept-content",x="data-"+A+"hidden-frame",F="data-"+A+"preserved-space-element",U="data-"+A+"shadow-root-element",q="data-"+A+"win-id",k="data-"+A+"image",H="data-"+A+"poster",V="data-"+A+"video",B="data-"+A+"canvas",W="data-"+A+"movable-style",z="data-"+A+"input-value",Y="data-"+A+"lazy-loaded-src",j="data-"+A+"stylesheet",G="data-"+A+"disabled-noscript",K="data-"+A+"invalid-element",X="data-"+A+"async-script",Z="*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)",J=["NOSCRIPT","DISABLED-NOSCRIPT","META","LINK","STYLE","TITLE","TEMPLATE","SOURCE","OBJECT","SCRIPT","HEAD","BODY"],$=["SCRIPT","NOSCRIPT","META","LINK","TEMPLATE"],Q=/^'(.*?)'$/,ee=/^"(.*?)"$/,te={regular:"400",normal:"400",bold:"700",bolder:"700",lighter:"100"},se="single-file-ui-element",oe="single-file-infobar",ne="data:,",ae=(e,t,s)=>globalThis.addEventListener(e,t,s),ie=globalThis.JSON,re=globalThis.CustomEvent,le=globalThis.MutationObserver;function de(e,t,s){e.querySelectorAll("noscript:not(["+G+"])").forEach((e=>{e.setAttribute(G,e.textContent),e.textContent=""})),function(e){e.querySelectorAll("meta[http-equiv=refresh]").forEach((e=>{e.removeAttribute("http-equiv"),e.setAttribute("disabled-http-equiv","refresh")}))}(e),e.head&&e.head.querySelectorAll(Z).forEach((e=>e.hidden=!0)),e.querySelectorAll("svg foreignObject").forEach((e=>{const t=e.querySelectorAll("html > head > "+Z+", html > body > "+Z);t.length&&(Array.from(e.childNodes).forEach((e=>e.remove())),t.forEach((t=>e.appendChild(t))))}));const o=new Map;let n;return t&&e.documentElement?(e.querySelectorAll("button button, a a").forEach((t=>{const s=e.createElement("template");s.setAttribute(K,""),s.content.appendChild(t.cloneNode(!0)),o.set(t,s),t.replaceWith(s)})),n=ce(t,e,e.documentElement,s),s.moveStylesInHead&&e.querySelectorAll("body style, body ~ style").forEach((e=>{const s=be(t,e);s&&he(e,s)&&(e.setAttribute(W,""),n.markedElements.push(e))}))):n={canvases:[],images:[],posters:[],videos:[],usedFonts:[],shadowRoots:[],markedElements:[]},{canvases:n.canvases,fonts:Array.from(b.values()),stylesheets:Ee(e),images:n.images,posters:n.posters,videos:n.videos,usedFonts:Array.from(n.usedFonts.values()),shadowRoots:n.shadowRoots,referrer:e.referrer,markedElements:n.markedElements,invalidElements:o,scrollPosition:{x:t.scrollX,y:t.scrollY},adoptedStyleSheets:me(e.adoptedStyleSheets)}}function ce(e,t,s,o,n={usedFonts:new Map,canvases:[],images:[],posters:[],videos:[],shadowRoots:[],markedElements:[]},a){if(s.childNodes){Array.from(s.childNodes).filter((t=>t instanceof e.HTMLElement||t instanceof e.SVGElement||t instanceof globalThis.HTMLElement||t instanceof globalThis.SVGElement)).forEach((s=>{let i,r,l;if(!o.autoSaveExternalSave&&(o.removeHiddenElements||o.removeUnusedFonts||o.compressHTML)&&(l=be(e,s),(s instanceof e.HTMLElement||s instanceof globalThis.HTMLElement)&&o.removeHiddenElements&&(r=(a||s.closest("html > head"))&&J.includes(s.tagName.toUpperCase())||s.closest("details"),r||(i=a||he(s,l),i&&!$.includes(s.tagName.toUpperCase())&&(s.setAttribute(L,""),n.markedElements.push(s)))),!i)){if(o.compressHTML&&l){const e=l.getPropertyValue("white-space");e&&e.startsWith("pre")&&(s.setAttribute(F,""),n.markedElements.push(s))}o.removeUnusedFonts&&(ue(l,o,n.usedFonts),ue(be(e,s,":first-letter"),o,n.usedFonts),ue(be(e,s,":before"),o,n.usedFonts),ue(be(e,s,":after"),o,n.usedFonts))}!function(e,t,s,o,n,a,i){const r=s.tagName&&s.tagName.toUpperCase();if("CANVAS"==r)try{n.canvases.push({dataURI:s.toDataURL("image/png",""),backgroundColor:i.getPropertyValue("background-color")}),s.setAttribute(B,n.canvases.length-1),n.markedElements.push(s)}catch(e){}if("IMG"==r){const t={currentSrc:a?ne:o.loadDeferredImages&&s.getAttribute(Y)||s.currentSrc};if(n.images.push(t),s.setAttribute(k,n.images.length-1),n.markedElements.push(s),s.removeAttribute(Y),i=i||be(e,s)){t.size=function(e,t,s){let o=t.naturalWidth,n=t.naturalHeight;if(!o&&!n){const a=null==t.getAttribute("style");if(s=s||be(e,t)){let e,i,r,l,d,c,m,u,p=!1;if("content-box"==s.getPropertyValue("box-sizing")){const e=t.style.getPropertyValue("box-sizing"),s=t.style.getPropertyPriority("box-sizing"),o=t.clientWidth;t.style.setProperty("box-sizing","border-box","important"),p=t.clientWidth!=o,e?t.style.setProperty("box-sizing",e,s):t.style.removeProperty("box-sizing")}e=Te("padding-left",s),i=Te("padding-right",s),r=Te("padding-top",s),l=Te("padding-bottom",s),p?(d=Te("border-left-width",s),c=Te("border-right-width",s),m=Te("border-top-width",s),u=Te("border-bottom-width",s)):d=c=m=u=0,o=Math.max(0,t.clientWidth-e-i-d-c),n=Math.max(0,t.clientHeight-r-l-m-u),a&&t.removeAttribute("style")}}return{pxWidth:o,pxHeight:n}}(e,s,i);const o=i.getPropertyValue("box-shadow"),n=i.getPropertyValue("background-image");o&&"none"!=o||n&&"none"!=n||!(t.size.pxWidth>1||t.size.pxHeight>1)||(t.replaceable=!0,t.backgroundColor=i.getPropertyValue("background-color"),t.objectFit=i.getPropertyValue("object-fit"),t.boxSizing=i.getPropertyValue("box-sizing"),t.objectPosition=i.getPropertyValue("object-position"))}}if("VIDEO"==r){const o=s.currentSrc;if(o&&!o.startsWith("blob:")&&!o.startsWith("data:")){const t=be(e,s.parentNode);n.videos.push({positionParent:t&&t.getPropertyValue("position"),src:o,size:{pxWidth:s.clientWidth,pxHeight:s.clientHeight},currentTime:s.currentTime}),s.setAttribute(V,n.videos.length-1)}if(!s.getAttribute("poster")){const e=t.createElement("canvas"),o=e.getContext("2d");e.width=s.clientWidth,e.height=s.clientHeight;try{o.drawImage(s,0,0,e.width,e.height),n.posters.push(e.toDataURL("image/png","")),s.setAttribute(H,n.posters.length-1),n.markedElements.push(s)}catch(e){}}}"IFRAME"==r&&a&&o.removeHiddenElements&&(s.setAttribute(x,""),n.markedElements.push(s));"INPUT"==r&&("password"!=s.type&&(s.setAttribute(z,s.value),n.markedElements.push(s)),"radio"!=s.type&&"checkbox"!=s.type||(s.setAttribute(z,s.checked),n.markedElements.push(s)));"TEXTAREA"==r&&(s.setAttribute(z,s.value),n.markedElements.push(s));"SELECT"==r&&s.querySelectorAll("option").forEach((e=>{e.selected&&(e.setAttribute(z,""),n.markedElements.push(e))}));"SCRIPT"==r&&(s.async&&""!=s.getAttribute("async")&&"async"!=s.getAttribute("async")&&(s.setAttribute(X,""),n.markedElements.push(s)),s.textContent=s.textContent.replace(/<\/script>/gi,"<\\/script>"))}(e,t,s,o,n,i,l);const d=!(s instanceof e.SVGElement||s instanceof globalThis.SVGElement)&&pe(s);if(d&&!s.classList.contains(se)&&s.tagName.toLowerCase()!=oe){const a={};s.setAttribute(U,n.shadowRoots.length),n.markedElements.push(s),n.shadowRoots.push(a);try{if(d.adoptedStyleSheets)if(d.adoptedStyleSheets.length)a.adoptedStyleSheets=me(d.adoptedStyleSheets);else if(void 0===d.adoptedStyleSheets.length){const e=e=>a.adoptedStyleSheets=e.detail.adoptedStyleSheets;d.addEventListener(_,e),d.dispatchEvent(new re(P,{bubbles:!0})),a.adoptedStyleSheets||s.dispatchEvent(new re(P,{bubbles:!0})),d.removeEventListener(_,e)}}catch(e){}ce(e,t,d,o,n,i),a.content=d.innerHTML,a.mode=d.mode;try{d.adoptedStyleSheets&&void 0===d.adoptedStyleSheets.length&&d.dispatchEvent(new re(M,{bubbles:!0}))}catch(e){}}ce(e,t,s,o,n,i),!o.autoSaveExternalSave&&o.removeHiddenElements&&a&&(r||""==s.getAttribute(D)?s.parentElement&&(s.parentElement.setAttribute(D,""),n.markedElements.push(s.parentElement)):i&&(s.setAttribute(O,""),n.markedElements.push(s)))}))}return n}function me(e){return e?Array.from(e).map((e=>Array.from(e.cssRules).map((e=>e.cssText)).join("\n"))):[]}function ue(e,t,s){if(e){const o=e.getPropertyValue("font-style")||"normal";e.getPropertyValue("font-family").split(",").forEach((n=>{if(n=ge(n),!t.loadedFonts||t.loadedFonts.find((e=>ge(e.family)==n&&e.style==o))){const t=(a=e.getPropertyValue("font-weight"),te[a.toLowerCase().trim()]||a),i=e.getPropertyValue("font-variant")||"normal",r=[n,t,o,i];s.set(ie.stringify(r),[n,t,o,i])}var a}))}}function pe(e){const t=globalThis.chrome;if(e.openOrClosedShadowRoot)return e.openOrClosedShadowRoot;if(!(t&&t.dom&&t.dom.openOrClosedShadowRoot))return e.shadowRoot;try{return t.dom.openOrClosedShadowRoot(e)}catch(t){return e.shadowRoot}}function ge(e=""){return function(e){e=e.match(Q)?e.replace(Q,"$1"):e.replace(ee,"$1");return e.trim()}((t=e.trim(),t.replace(w,((e,t,s)=>{const o="0x"+t-65536;return o!=o||s?t:o<0?String.fromCharCode(o+65536):String.fromCharCode(o>>10|55296,1023&o|56320)})))).toLowerCase();var t}function he(e,t){let s=!1;if(t){const o=t.getPropertyValue("display"),n=t.getPropertyValue("opacity"),a=t.getPropertyValue("visibility");if(s="none"==o,!s&&("0"==n||"hidden"==a)&&e.getBoundingClientRect){const t=e.getBoundingClientRect();s=!t.width&&!t.height}}return Boolean(s)}function fe(e,t,s){if(e.querySelectorAll("["+G+"]").forEach((e=>{e.textContent=e.getAttribute(G),e.removeAttribute(G)})),e.querySelectorAll("meta[disabled-http-equiv]").forEach((e=>{e.setAttribute("http-equiv",e.getAttribute("disabled-http-equiv")),e.removeAttribute("disabled-http-equiv")})),e.head&&e.head.querySelectorAll("*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)").forEach((e=>e.removeAttribute("hidden"))),!t){const s=[O,x,L,F,k,H,V,B,z,U,j,X];t=e.querySelectorAll(s.map((e=>"["+e+"]")).join(","))}t.forEach((e=>{e.removeAttribute(O),e.removeAttribute(L),e.removeAttribute(D),e.removeAttribute(x),e.removeAttribute(F),e.removeAttribute(k),e.removeAttribute(H),e.removeAttribute(V),e.removeAttribute(B),e.removeAttribute(z),e.removeAttribute(U),e.removeAttribute(j),e.removeAttribute(X),e.removeAttribute(W)})),s&&s.forEach(((e,t)=>e.replaceWith(t)))}function Ee(e){if(e){const t=[];return e.querySelectorAll("style").forEach(((s,o)=>{try{if(!s.sheet.disabled){const n=e.createElement("style");n.textContent=s.textContent,e.body.appendChild(n);const a=n.sheet;n.remove();const i=Array.from(a.cssRules).map((e=>e.cssText)).join("\n"),r=Array.from(s.sheet.cssRules).map((e=>e.cssText)).join("\n");a&&i==r||(s.setAttribute(j,o),t[o]=Array.from(s.sheet.cssRules).map((e=>e.cssText)).join("\n"))}}catch(e){}})),t}}function Te(e,t){if(t.getPropertyValue(e).endsWith("px"))return parseFloat(t.getPropertyValue(e))}function be(e,t,s){try{return e.getComputedStyle(t,s)}catch(e){}}const ye={LAZY_SRC_ATTRIBUTE_NAME:Y,SINGLE_FILE_UI_ELEMENT_CLASS:se},Ie=10,we="attributes",Ae=globalThis.browser,ve=globalThis.document,Se=globalThis.MutationObserver,Re=new Map;let Ne;async function Pe(e){if(ve.documentElement){Re.clear();const s=ve.body?Math.max(ve.body.scrollHeight,ve.documentElement.scrollHeight):ve.documentElement.scrollHeight,n=ve.body?Math.max(ve.body.scrollWidth,ve.documentElement.scrollWidth):ve.documentElement.scrollWidth;if(s>globalThis.innerHeight||n>globalThis.innerWidth){const i=Math.max(s-1.5*globalThis.innerHeight,0),l=Math.max(n-1.5*globalThis.innerWidth,0);if(globalThis.scrollY<i||globalThis.scrollX<l)return function(e){return Ne=0,new Promise((async s=>{let n;const i=new Set,l=new Se((async t=>{if((t=t.filter((e=>e.type==we))).length){t.filter((e=>{if("src"==e.attributeName&&(e.target.setAttribute(ye.LAZY_SRC_ATTRIBUTE_NAME,e.target.src),e.target.addEventListener("load",p)),"src"==e.attributeName||"srcset"==e.attributeName||e.target.tagName&&"SOURCE"==e.target.tagName.toUpperCase())return!e.target.classList||!e.target.classList.contains(ye.SINGLE_FILE_UI_ELEMENT_CLASS)})).length&&(n=!0,await Me(l,e,T),i.size||await _e(l,e,T))}}));async function c(t){await Oe("idleTimeout",(async()=>{n?Ne<Ie&&(Ne++,De("idleTimeout"),await c(Math.max(500,t/2))):(De("loadTimeout"),De("maxTimeout"),Ce(l,e,T))}),t,e.loadDeferredImagesNativeTimeout)}function p(e){const t=e.target;t.removeAttribute(ye.LAZY_SRC_ATTRIBUTE_NAME),t.removeEventListener("load",p)}async function f(t){n=!0,await Me(l,e,T),await _e(l,e,T),t.detail&&i.add(t.detail)}async function E(t){await Me(l,e,T),await _e(l,e,T),i.delete(t.detail),i.size||await _e(l,e,T)}function T(e){l.disconnect(),ve.removeEventListener(m,f),ve.removeEventListener(u,E),s(e)}await c(2*e.loadDeferredImagesMaxIdleTime),await Me(l,e,T),l.observe(ve,{subtree:!0,childList:!0,attributes:!0}),ve.addEventListener(m,f),ve.addEventListener(u,E),function(e){e.loadDeferredImagesBlockCookies&&h.dispatchEvent(new g(a)),e.loadDeferredImagesBlockStorage&&h.dispatchEvent(new g(d)),e.loadDeferredImagesDispatchScrollEvent&&h.dispatchEvent(new g(r)),e.loadDeferredImagesKeepZoomLevel?h.dispatchEvent(new g(o)):h.dispatchEvent(new g(t))}(e)}))}(e)}}}async function _e(e,t,s){await Oe("loadTimeout",(()=>Ce(e,t,s)),t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function Me(e,t,s){await Oe("maxTimeout",(async()=>{await De("loadTimeout"),await Ce(e,t,s)}),10*t.loadDeferredImagesMaxIdleTime,t.loadDeferredImagesNativeTimeout)}async function Ce(e,t,o){await De("idleTimeout"),function(e){e.loadDeferredImagesBlockCookies&&h.dispatchEvent(new g(i)),e.loadDeferredImagesBlockStorage&&h.dispatchEvent(new g(c)),e.loadDeferredImagesDispatchScrollEvent&&h.dispatchEvent(new g(l)),e.loadDeferredImagesKeepZoomLevel?h.dispatchEvent(new g(n)):h.dispatchEvent(new g(s))}(t),await Oe("endTimeout",(async()=>{await De("maxTimeout"),o()}),t.loadDeferredImagesMaxIdleTime/2,t.loadDeferredImagesNativeTimeout),e.disconnect()}async function Oe(e,t,s,o){if(Ae&&Ae.runtime&&Ae.runtime.sendMessage&&!o){if(!Re.get(e)||!Re.get(e).pending){const o={callback:t,pending:!0};Re.set(e,o);try{await Ae.runtime.sendMessage({method:"singlefile.lazyTimeout.setTimeout",type:e,delay:s})}catch(o){Le(e,t,s)}o.pending=!1}}else Le(e,t,s)}function Le(e,t,s){const o=Re.get(e);o&&globalThis.clearTimeout(o),Re.set(e,t),globalThis.setTimeout(t,s)}async function De(e){if(Ae&&Ae.runtime&&Ae.runtime.sendMessage)try{await Ae.runtime.sendMessage({method:"singlefile.lazyTimeout.clearTimeout",type:e})}catch(t){xe(e)}else xe(e)}function xe(e){const t=Re.get(e);Re.delete(e),t&&globalThis.clearTimeout(t)}Ae&&Ae.runtime&&Ae.runtime.onMessage&&Ae.runtime.onMessage.addListener&&Ae.runtime.onMessage.addListener((e=>{if("singlefile.lazyTimeout.onTimeout"==e.method){const t=Re.get(e.type);if(t){Re.delete(e.type);try{t.callback()}catch(t){xe(e.type)}}}}));const Fe={ON_BEFORE_CAPTURE_EVENT_NAME:R,ON_AFTER_CAPTURE_EVENT_NAME:N,WIN_ID_ATTRIBUTE_NAME:q,WAIT_FOR_USERSCRIPT_PROPERTY_NAME:v,preProcessDoc:de,serialize:function(e){const t=e.doctype;let s="";return t&&(s="<!DOCTYPE "+t.nodeName,t.publicId?(s+=' PUBLIC "'+t.publicId+'"',t.systemId&&(s+=' "'+t.systemId+'"')):t.systemId&&(s+=' SYSTEM "'+t.systemId+'"'),t.internalSubset&&(s+=" ["+t.internalSubset+"]"),s+="> "),s+e.documentElement.outerHTML},postProcessDoc:fe,getShadowRoot:pe},Ue='iframe, frame, object[type="text/html"][data]',qe="*",ke="singlefile.frameTree.initRequest",He="singlefile.frameTree.ackInitRequest",Ve="singlefile.frameTree.cleanupRequest",Be="singlefile.frameTree.initResponse",We="*",ze=5e3,Ye=1e4,je=".",Ge=globalThis.window==globalThis.top,Ke=globalThis.browser,Xe=globalThis.top,Ze=globalThis.MessageChannel,Je=globalThis.document,$e=globalThis.JSON,Qe=globalThis.MutationObserver;let et,tt=globalThis.sessions;function st(){globalThis.addEventListener("message",(async e=>{if("string"==typeof e.data&&e.data.startsWith(S)){e.preventDefault(),e.stopPropagation();const t=$e.parse(e.data.substring(S.length));if(t.method==ke)e.source&&ut(e.source,{method:He,windowId:t.windowId,sessionId:t.sessionId}),Ge||(globalThis.stop(),t.options.loadDeferredImages&&Pe(t.options),await nt(t));else if(t.method==He)lt("requestTimeouts",t.sessionId,t.windowId),dt(t.sessionId,t.windowId);else if(t.method==Ve)at(t);else if(t.method==Be&&tt.get(t.sessionId)){e.ports[0].onmessage=e=>it(e.data)}}}),!0)}function ot(){return globalThis.crypto.getRandomValues(new Uint32Array(32)).join("")}async function nt(e){const t=e.sessionId,s=globalThis[Fe.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];delete globalThis._singleFile_cleaningUp,Ge||(et=globalThis.frameId=e.windowId),rt(Je,e.options,et,t),Ge||(e.options.userScriptEnabled&&s&&await s(Fe.ON_BEFORE_CAPTURE_EVENT_NAME),mt({frames:[pt(Je,globalThis,et,e.options,e.scrolling)],sessionId:t,requestedFrameId:Je.documentElement.dataset.requestedFrameId&&et}),e.options.userScriptEnabled&&s&&await s(Fe.ON_AFTER_CAPTURE_EVENT_NAME),delete Je.documentElement.dataset.requestedFrameId)}function at(e){if(!globalThis._singleFile_cleaningUp){globalThis._singleFile_cleaningUp=!0;const t=e.sessionId;ct(gt(Je),e.windowId,t)}}function it(e){e.frames.forEach((t=>lt("responseTimeouts",e.sessionId,t.windowId)));const t=tt.get(e.sessionId);if(t){e.requestedFrameId&&(t.requestedFrameId=e.requestedFrameId),e.frames.forEach((e=>{let s=t.frames.find((t=>e.windowId==t.windowId));s||(s={windowId:e.windowId},t.frames.push(s)),s.processed||(s.content=e.content,s.baseURI=e.baseURI,s.title=e.title,s.url=e.url,s.canvases=e.canvases,s.fonts=e.fonts,s.stylesheets=e.stylesheets,s.images=e.images,s.posters=e.posters,s.videos=e.videos,s.usedFonts=e.usedFonts,s.shadowRoots=e.shadowRoots,s.processed=e.processed,s.scrollPosition=e.scrollPosition,s.scrolling=e.scrolling,s.adoptedStyleSheets=e.adoptedStyleSheets)}));t.frames.filter((e=>!e.processed)).length||(t.frames=t.frames.sort(((e,t)=>t.windowId.split(je).length-e.windowId.split(je).length)),t.resolve&&(t.requestedFrameId&&t.frames.forEach((e=>{e.windowId==t.requestedFrameId&&(e.requestedFrame=!0)})),t.resolve(t.frames)))}}function rt(e,t,s,o){const n=gt(e);!function(e,t,s,o,n){const a=[];let i;tt.get(n)?i=tt.get(n).requestTimeouts:(i={},tt.set(n,{requestTimeouts:i}));t.forEach(((e,t)=>{const s=o+je+t;e.setAttribute(Fe.WIN_ID_ATTRIBUTE_NAME,s),a.push({windowId:s})})),mt({frames:a,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),t.forEach(((e,t)=>{const a=o+je+t;try{ut(e.contentWindow,{method:ke,windowId:a,sessionId:n,options:s,scrolling:e.scrolling})}catch(e){}i[a]=globalThis.setTimeout((()=>mt({frames:[{windowId:a,processed:!0}],sessionId:n})),ze)})),delete e.documentElement.dataset.requestedFrameId}(e,n,t,s,o),n.length&&function(e,t,s,o,n){const a=[];t.forEach(((e,t)=>{const i=o+je+t;let r;try{r=e.contentDocument}catch(e){}if(r)try{const t=e.contentWindow;t.stop(),lt("requestTimeouts",n,i),rt(r,s,i,n),a.push(pt(r,t,i,s,e.scrolling))}catch(e){a.push({windowId:i,processed:!0})}})),mt({frames:a,sessionId:n,requestedFrameId:e.documentElement.dataset.requestedFrameId&&o}),delete e.documentElement.dataset.requestedFrameId}(e,n,t,s,o)}function lt(e,t,s){const o=tt.get(t);if(o&&o[e]){const t=o[e][s];t&&(globalThis.clearTimeout(t),delete o[e][s])}}function dt(e,t){const s=tt.get(e);s&&s.responseTimeouts&&(s.responseTimeouts[t]=globalThis.setTimeout((()=>mt({frames:[{windowId:t,processed:!0}],sessionId:e})),Ye))}function ct(e,t,s){e.forEach(((e,o)=>{const n=t+je+o;e.removeAttribute(Fe.WIN_ID_ATTRIBUTE_NAME);try{ut(e.contentWindow,{method:Ve,windowId:n,sessionId:s})}catch(e){}})),e.forEach(((e,o)=>{const n=t+je+o;let a;try{a=e.contentDocument}catch(e){}if(a)try{ct(gt(a),n,s)}catch(e){}}))}function mt(e){e.method=Be;try{Xe.singlefile.processors.frameTree.initResponse(e)}catch(t){ut(Xe,e,!0)}}function ut(e,t,s){if(e==Xe&&Ke&&Ke.runtime&&Ke.runtime.sendMessage)Ke.runtime.sendMessage(t);else if(s){const s=new Ze;e.postMessage(S+$e.stringify({method:t.method,sessionId:t.sessionId}),We,[s.port2]),s.port1.postMessage(t)}else e.postMessage(S+$e.stringify(t),We)}function pt(e,t,s,o,n){const a=Fe.preProcessDoc(e,t,o),i=Fe.serialize(e);Fe.postProcessDoc(e,a.markedElements,a.invalidElements);return{windowId:s,content:i,baseURI:e.baseURI.split("#")[0],url:e.location.href,title:e.title,canvases:a.canvases,fonts:a.fonts,stylesheets:a.stylesheets,images:a.images,posters:a.posters,videos:a.videos,usedFonts:a.usedFonts,shadowRoots:a.shadowRoots,scrollPosition:a.scrollPosition,scrolling:n,adoptedStyleSheets:a.adoptedStyleSheets,processed:!0}}function gt(e){let t=Array.from(e.querySelectorAll(Ue));return e.querySelectorAll(qe).forEach((e=>{const s=Fe.getShadowRoot(e);s&&(t=t.concat(...s.querySelectorAll(Ue)))})),t}tt||(tt=globalThis.sessions=new Map),Ge&&(et="0",Ke&&Ke.runtime&&Ke.runtime.onMessage&&Ke.runtime.onMessage.addListener&&Ke.runtime.onMessage.addListener((e=>e.method==Be?(it(e),Promise.resolve({})):e.method==He?(lt("requestTimeouts",e.sessionId,e.windowId),dt(e.sessionId,e.windowId),Promise.resolve({})):void 0))),st(),new Qe(st).observe(Je,{childList:!0});const ht=["AREA","BASE","BR","COL","COMMAND","EMBED","HR","IMG","INPUT","KEYGEN","LINK","META","PARAM","SOURCE","TRACK","WBR"],ft=1,Et=3,Tt=8,bt=[{tagName:"HEAD",accept:e=>!e.childNodes.length||e.childNodes[0].nodeType==ft},{tagName:"BODY",accept:e=>!e.childNodes.length}],yt=[{tagName:"HTML",accept:e=>!e||e.nodeType!=Tt},{tagName:"HEAD",accept:e=>!e||e.nodeType!=Tt&&(e.nodeType!=Et||!At(e.textContent))},{tagName:"BODY",accept:e=>!e||e.nodeType!=Tt},{tagName:"LI",accept:(e,t)=>!e&&t.parentElement&&("UL"==vt(t.parentElement)||"OL"==vt(t.parentElement))||e&&["LI"].includes(vt(e))},{tagName:"DT",accept:e=>!e||["DT","DD"].includes(vt(e))},{tagName:"P",accept:e=>e&&["ADDRESS","ARTICLE","ASIDE","BLOCKQUOTE","DETAILS","DIV","DL","FIELDSET","FIGCAPTION","FIGURE","FOOTER","FORM","H1","H2","H3","H4","H5","H6","HEADER","HR","MAIN","NAV","OL","P","PRE","SECTION","TABLE","UL"].includes(vt(e))},{tagName:"DD",accept:e=>!e||["DT","DD"].includes(vt(e))},{tagName:"RT",accept:e=>!e||["RT","RP"].includes(vt(e))},{tagName:"RP",accept:e=>!e||["RT","RP"].includes(vt(e))},{tagName:"OPTGROUP",accept:e=>!e||["OPTGROUP"].includes(vt(e))},{tagName:"OPTION",accept:e=>!e||["OPTION","OPTGROUP"].includes(vt(e))},{tagName:"COLGROUP",accept:e=>!e||e.nodeType!=Tt&&(e.nodeType!=Et||!At(e.textContent))},{tagName:"CAPTION",accept:e=>!e||e.nodeType!=Tt&&(e.nodeType!=Et||!At(e.textContent))},{tagName:"THEAD",accept:e=>!e||["TBODY","TFOOT"].includes(vt(e))},{tagName:"TBODY",accept:e=>!e||["TBODY","TFOOT"].includes(vt(e))},{tagName:"TFOOT",accept:e=>!e},{tagName:"TR",accept:e=>!e||["TR"].includes(vt(e))},{tagName:"TD",accept:e=>!e||["TD","TH"].includes(vt(e))},{tagName:"TH",accept:e=>!e||["TD","TH"].includes(vt(e))}],It=["STYLE","SCRIPT","XMP","IFRAME","NOEMBED","NOFRAMES","PLAINTEXT","NOSCRIPT"];function wt(e,t,s){return e.nodeType==Et?function(e){const t=e.parentNode;let s;t&&t.nodeType==ft&&(s=vt(t));return!s||It.includes(s)?"SCRIPT"==s||"STYLE"==s?e.textContent.replace(/<\//gi,"<\\/").replace(/\/>/gi,"\\/>"):e.textContent:e.textContent.replace(/&/g,"&amp;").replace(/\u00a0/g,"&nbsp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}(e):e.nodeType==Tt?"\x3c!--"+e.textContent+"--\x3e":e.nodeType==ft?function(e,t,s){const o=vt(e),n=t&&bt.find((t=>o==vt(t)&&t.accept(e)));let a="";n&&!e.attributes.length||(a="<"+o.toLowerCase(),Array.from(e.attributes).forEach((s=>a+=function(e,t,s){const o=e.name;let n="";if(!o.match(/["'>/=]/)){let a,i=e.value;s&&"class"==o&&(i=Array.from(t.classList).map((e=>e.trim())).join(" ")),i=i.replace(/&/g,"&amp;").replace(/\u00a0/g,"&nbsp;"),i.includes('"')&&(i.includes("'")||!s?i=i.replace(/"/g,"&quot;"):a=!0);const r=!s||i.match(/[ \t\n\f\r'"`=<>]/);n+=" ",e.namespace?"http://www.w3.org/XML/1998/namespace"==e.namespaceURI?n+="xml:"+o:"http://www.w3.org/2000/xmlns/"==e.namespaceURI?("xmlns"!==o&&(n+="xmlns:"),n+=o):"http://www.w3.org/1999/xlink"==e.namespaceURI?n+="xlink:"+o:n+=o:n+=o,""!=i&&(n+="=",r&&(n+=a?"'":'"'),n+=i,r&&(n+=a?"'":'"'))}return n}(s,e,t))),a+=">");"TEMPLATE"!=o||e.childNodes.length?Array.from(e.childNodes).forEach((e=>a+=wt(e,t,s||"svg"==o))):a+=e.innerHTML;const i=t&&yt.find((t=>o==vt(t)&&t.accept(e.nextSibling,e)));(s||!i&&!ht.includes(o))&&(a+="</"+o.toLowerCase()+">");return a}(e,t,s):void 0}function At(e){return Boolean(e.match(/^[ \t\n\f\r]/))}function vt(e){return e.tagName&&e.tagName.toUpperCase()}const St={frameTree:Object.freeze({__proto__:null,getAsync:function(e){const t=ot();return e=$e.parse($e.stringify(e)),new Promise((s=>{tt.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{},resolve:e=>{e.sessionId=t,s(e)}}),nt({windowId:et,sessionId:t,options:e})}))},getSync:function(e){const t=ot();e=$e.parse($e.stringify(e)),tt.set(t,{frames:[],requestTimeouts:{},responseTimeouts:{}}),function(e){const t=e.sessionId,s=globalThis[Fe.WAIT_FOR_USERSCRIPT_PROPERTY_NAME];delete globalThis._singleFile_cleaningUp,Ge||(et=globalThis.frameId=e.windowId);rt(Je,e.options,et,t),Ge||(e.options.userScriptEnabled&&s&&s(Fe.ON_BEFORE_CAPTURE_EVENT_NAME),mt({frames:[pt(Je,globalThis,et,e.options,e.scrolling)],sessionId:t,requestedFrameId:Je.documentElement.dataset.requestedFrameId&&et}),e.options.userScriptEnabled&&s&&s(Fe.ON_AFTER_CAPTURE_EVENT_NAME),delete Je.documentElement.dataset.requestedFrameId)}({windowId:et,sessionId:t,options:e});const s=tt.get(t).frames;return s.sessionId=t,s},cleanup:function(e){tt.delete(e),at({windowId:et,sessionId:e,options:{sessionId:e}})},initResponse:it,TIMEOUT_INIT_REQUEST_MESSAGE:ze})},Rt={COMMENT_HEADER:"Page saved with SingleFile",COMMENT_HEADER_LEGACY:"Archive processed by SingleFile",ON_BEFORE_CAPTURE_EVENT_NAME:R,ON_AFTER_CAPTURE_EVENT_NAME:N,WAIT_FOR_USERSCRIPT_PROPERTY_NAME:v,preProcessDoc:de,postProcessDoc:fe,serialize:(e,t)=>function(e,t){const s=e.doctype;let o="";return s&&(o="<!DOCTYPE "+s.nodeName,s.publicId?(o+=' PUBLIC "'+s.publicId+'"',s.systemId&&(o+=' "'+s.systemId+'"')):s.systemId&&(o+=' SYSTEM "'+s.systemId+'"'),s.internalSubset&&(o+=" ["+s.internalSubset+"]"),o+="> "),o+wt(e.documentElement,t)}(e,t),getShadowRoot:pe};!function e(){ae(C,(()=>globalThis[v]=async e=>{const t=new re(e+"-request",{cancelable:!0}),s=new Promise((t=>ae(e+"-response",t)));(e=>{try{globalThis.dispatchEvent(e)}catch(e){}})(t),t.defaultPrevented&&await s})),new le(e).observe(globalThis.document,{childList:!0})}(),e.helper=Rt,e.processors=St,Object.defineProperty(e,"__esModule",{value:!0})}));