Просмотр исходного кода

moved maff2html into github.com/gildas-lormeau/SingleFile-MAFF2HTML

Former-commit-id: e4b679aaacb4c4ac3ef83ef87ec89e2665fbd425
Gildas 6 лет назад
Родитель
Сommit
8477f52de5

+ 1 - 1
README.MD

@@ -69,7 +69,7 @@ See https://addons.mozilla.org/firefox/addon/single-file/statistics/?last=90
 
 ## Command Line Interface
  - You can save web pages to HTML from the command line interface. See here for more info: https://github.com/gildas-lormeau/SingleFile/blob/master/cli/README.MD.
- - You can also convert MAFF pages to HTML. For this, you must use specific versions of SingleFile CLI and Firefox. See here for more info: https://github.com/gildas-lormeau/SingleFile/blob/master/maff2html/README.MD.
+ - You can also convert MAFF pages to HTML. For this, you must use specific versions of SingleFile CLI and Firefox. See here for more info: https://github.com/gildas-lormeau/SingleFile-MAFF2HTML.
 
 ## Known Issues
 - All browsers:

+ 1 - 1
cli/README.MD

@@ -4,7 +4,7 @@
 
 SingleFile can be launched from the command line by running it into a (headless) browser. It runs through Node.js as a standalone script injected into the web page instead of being embedded into a WebExtension. To connect to the browser, it can use [Puppeteer](https://github.com/GoogleChrome/puppeteer) or [Selenium WebDriver](https://www.npmjs.com/package/selenium-webdriver). Alternatively, it can also emulate a browser with JavaScript disabled by using [jsdom](https://github.com/jsdom/jsdom).
 
-You can also convert MAFF pages to HTML. For this, you must use specific versions of SingleFile CLI and Firefox. See here for more info: https://github.com/gildas-lormeau/SingleFile/blob/master/maff2html/README.MD.
+You can also convert MAFF pages to HTML. For this, you must use specific versions of SingleFile CLI and Firefox. See here for more info: https://github.com/gildas-lormeau/SingleFile-MAFF2HTML.
 
 This is a **work in progress**.
 

+ 0 - 63
maff2html/README.MD

@@ -1,63 +0,0 @@
-# Convert MAFF to HTML with SingleFile
-
-## Introduction
-
-SingleFile can be launched from the command line to convert MAFF files to HTML files by running it into Firefox. It runs through Node.js as a standalone script injected into the web page instead of being embedded into a WebExtension. It uses [Selenium WebDriver](https://www.npmjs.com/package/selenium-webdriver) to connect Node.js to Firefox.
-
-## Install
-
-- Unzip and install the latest Nightly version of [Firefox version 56.0.2](https://github.com/gildas-lormeau/SingleFile/tree/master/maff2html/bin/firefox/)
-
-- Make sure the executable of Firefox can be found through the `PATH` environment variable. Otherwise you will need to set the `--browser-executable-path` option to help SingleFile locating it.
-
-- Install [Node.js](https://nodejs.org)
-
-- Unzip the [master archive](https://github.com/gildas-lormeau/SingleFile/archive/master.zip) somewhere on your disk in an empty folder.
-
-  `$ unzip master.zip .`
-
-- Go into the `maff2html` folder.
-
-  `$ cd maff2html`
-  
-- Install dependencies with npm (installed with Node.js).
-
-  `$ npm install`
-  
-- Make `single-file` executable (Linux/Unix/BSD etc.).
-
-  `$ chmod +x single-file`
-
-- Unzip and copy the [Mozilla geckodriver version 0.20.1](https://github.com/gildas-lormeau/SingleFile/tree/master/maff2html/bin/geckodriver/) executable in the `maff2html` folder.
-
-## Run
-
-- Syntax
- 
-  `$ ./single-file <url> [output] [options ...]` (Linux/Unix/BSD etc.)
-
-  `> single-file <url> [output] [options ...]` (Windows)    
-
-- Display help
-
-  `$ ./single-file --help` (Linux/Unix/BSD etc.)
-
-  `> single-file --help` (Windows)
-
-- Examples
-
-  - Convert `wikipedia.maff` (located in the user folder) to `wikipedia.html`
-
-  `$ ./single-file /home/gildas/wikipedia.maff wikipedia.html` (Linux/Unix/BSD etc.)
-  
-  `> single-file "C:\Users\Gildas\wikipedia.maff" wikipedia.html` (Windows)
-
-  - Convert `wikipedia.maff` to `wikipedia.html` with Firefox installed in the folder "~/firefox-56.0.2/" (Linux/Unix/BSD etc.) or "C:\Program Files\Mozilla Firefox 56.0.2\" (Windows)
-
-  `$ ./single-file /home/gildas/wikipedia.maff wikipedia.html --browser-executable-path=~/firefox-56.0.2/firefox` (Linux/Unix/BSD etc.)
-  
-  `> single-file "C:\Users\Gildas\wikipedia.maff" wikipedia.html --browser-executable-path="C:\Program Files\Mozilla Firefox 56.0.2\firefox"` (Windows)
-  
-## License
-
-SingleFile is licensed under AGPL. Code derived from third-party projects is licensed under MIT. Please contact me at gildas.lormeau &lt;at&gt; gmail.com if you are interested in licensing the SingleFile code for a commercial service or product.

BIN
maff2html/back-ends/extensions/signed/bypass_csp-0.0.3-an+fx.xpi


BIN
maff2html/back-ends/extensions/signed/disable_web_security-0.0.3-an+fx.xpi


BIN
maff2html/back-ends/extensions/signed/mozilla_archive_format_with_mht_and_faithful_save-5.2.1-fx+sm.xpi


BIN
maff2html/back-ends/extensions/signed/network_idle-0.0.2-an+fx.xpi


+ 0 - 178
maff2html/back-ends/webdriver-gecko.js

@@ -1,178 +0,0 @@
-/*
- * Copyright 2010-2019 Gildas Lormeau
- * contact : gildas.lormeau <at> gmail.com
- * 
- * This file is part of SingleFile.
- *
- *   The code in this file is free software: you can redistribute it and/or 
- *   modify it under the terms of the GNU Affero General Public License 
- *   (GNU AGPL) as published by the Free Software Foundation, either version 3
- *   of the License, or (at your option) any later version.
- * 
- *   The code in this file is distributed in the hope that it will be useful, 
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of 
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero 
- *   General Public License for more details.
- *
- *   As additional permission under GNU AGPL version 3 section 7, you may 
- *   distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU 
- *   AGPL normally required by section 4, provided you include this license 
- *   notice and a URL through which recipients can access the Corresponding 
- *   Source.
- */
-
-/* global __dirname, require, exports, process, setTimeout, clearTimeout */
-
-const fs = require("fs");
-const path = require("path");
-
-const firefox = require("selenium-webdriver/firefox");
-const { Builder, By, Key } = require("selenium-webdriver");
-
-const SCRIPTS = [
-	"../../index.js",
-	"../../lib/hooks/content/content-hooks-frames.js",
-	"../../lib/frame-tree/content/content-frame-tree.js",
-	"../../lib/lazy/content/content-lazy-loader.js",
-	"../../lib/single-file/single-file-util.js",
-	"../../lib/single-file/single-file-helper.js",
-	"../../lib/single-file/vendor/css-tree.js",
-	"../../lib/single-file/vendor/html-srcset-parser.js",
-	"../../lib/single-file/vendor/css-minifier.js",
-	"../../lib/single-file/vendor/css-font-property-parser.js",
-	"../../lib/single-file/vendor/css-media-query-parser.js",
-	"../../lib/single-file/modules/html-minifier.js",
-	"../../lib/single-file/modules/css-fonts-minifier.js",
-	"../../lib/single-file/modules/css-fonts-alt-minifier.js",
-	"../../lib/single-file/modules/css-matched-rules.js",
-	"../../lib/single-file/modules/css-medias-alt-minifier.js",
-	"../../lib/single-file/modules/css-rules-minifier.js",
-	"../../lib/single-file/modules/html-images-alt-minifier.js",
-	"../../lib/single-file/modules/html-serializer.js",
-	"../../lib/single-file/single-file-core.js",
-	"../../lib/single-file/single-file.js"
-];
-
-exports.getPageData = async options => {
-	let driver;
-	try {
-		const builder = new Builder().withCapabilities({ "pageLoadStrategy": "eager" });
-		const firefoxOptions = new firefox.Options();
-		options.enableMaff = true;
-		if ((options.browserHeadless === undefined || options.browserHeadless) && !options.browserDebug) {
-			firefoxOptions.headless();
-		}
-		if (options.browserExecutablePath) {
-			firefoxOptions.setBinary(options.browserExecutablePath);
-		}
-		if (options.webDriverExecutablePath) {
-			process.env["webdriver.gecko.driver"] = options.webDriverExecutablePath;
-		}
-		const profile = new firefox.Profile();
-		if (options.browserDisableWebSecurity === undefined || options.browserDisableWebSecurity) {
-			profile.addExtension(require.resolve("./extensions/signed/disable_web_security-0.0.3-an+fx.xpi"));
-		}
-		if (options.browserBypassCSP === undefined || options.browserBypassCSP) {
-			profile.addExtension(require.resolve("./extensions/signed/bypass_csp-0.0.3-an+fx.xpi"));
-		}
-		if (options.browserWaitUntil === undefined || options.browserWaitUntil == "networkidle0" || options.browserWaitUntil == "networkidle2") {
-			profile.addExtension(require.resolve("./extensions/signed/network_idle-0.0.2-an+fx.xpi"));
-		}
-		if (options.browserExtensions && options.browserExtensions.length) {
-			options.browserExtensions.forEach(extensionPath => profile.addExtension(path.resolve(__dirname, "..", extensionPath)));
-		}
-		if (options.userAgent) {
-			profile.setPreference("general.useragent.override", options.userAgent);
-		}
-		profile.addExtension(require.resolve("./extensions/signed/mozilla_archive_format_with_mht_and_faithful_save-5.2.1-fx+sm.xpi"));
-		profile.setPreference("browser.tabs.remote.autostart", false);
-		profile.setPreference("browser.tabs.remote.autostart.2", false);
-		profile.setPreference("extensions.allow-non-mpc-extensions", true);
-		profile.setPreference("xpinstall.signatures.required", false);
-		firefoxOptions.setProfile(profile);
-		builder.setFirefoxOptions(firefoxOptions);
-		driver = await builder.forBrowser("firefox").build();
-		driver.manage().setTimeouts({ script: options.browserLoadMaxTime, pageLoad: options.browserLoadMaxTime, implicit: options.browserLoadMaxTime });
-		if (options.browserWidth && options.browserHeight) {
-			const window = driver.manage().window();
-			if (window.setRect) {
-				window.setRect(options.browserHeight, options.browserWidth);
-			} else if (window.setSize) {
-				window.setSize(options.browserWidth, options.browserHeight);
-			}
-		}
-		let scripts = SCRIPTS.map(scriptPath => fs.readFileSync(require.resolve(scriptPath)).toString().replace(/\n(this)\.([^ ]+) = (this)\.([^ ]+) \|\|/g, "\nwindow.$2 = window.$4 ||")).join("\n");
-		const fileContents = {
-			"../../lib/hooks/content/content-hooks-web.js": fs.readFileSync(require.resolve("../../lib/hooks/content/content-hooks-web.js")).toString(),
-			"../../lib/hooks/content/content-hooks-frames-web.js": fs.readFileSync(require.resolve("../../lib/hooks/content/content-hooks-frames-web.js")).toString(),
-		};
-		scripts = scripts + ";this.singlefile.lib.getFileContent = filename => (" + JSON.stringify(fileContents) + ")[filename];";
-		if (options.browserDebug) {
-			await driver.findElement(By.css("html")).sendKeys(Key.SHIFT + Key.F5);
-			await driver.sleep(3000);
-		}
-		await driver.get(options.url);
-		await driver.executeScript(scripts);
-		if (options.browserWaitUntil != "domcontentloaded") {
-			let scriptPromise;
-			if (options.browserWaitUntil === undefined || options.browserWaitUntil == "networkidle0") {
-				scriptPromise = driver.executeAsyncScript("addEventListener(\"single-file-network-idle-0\", () => arguments[0](), true)");
-			} else if (options.browserWaitUntil == "networkidle2") {
-				scriptPromise = driver.executeAsyncScript("addEventListener(\"single-file-network-idle-2\", () => arguments[0](), true)");
-			} else if (options.browserWaitUntil == "load") {
-				scriptPromise = driver.executeAsyncScript("if (document.readyState == \"loading\") { document.addEventListener(\"load\", () => arguments[0]()) } else { arguments[0](); }");
-			}
-			let cancelTimeout;
-			const timeoutPromise = new Promise(resolve => {
-				const timeoutId = setTimeout(resolve, Math.max(0, options.browserLoadMaxTime - 5000));
-				cancelTimeout = () => {
-					clearTimeout(timeoutId);
-					resolve();
-				};
-			});
-			await Promise.race([scriptPromise, timeoutPromise]);
-			cancelTimeout();
-		}
-		const result = await driver.executeAsyncScript(getPageDataScript(), options);
-		if (result.error) {
-			throw result.error;
-		} else {
-			return result.pageData;
-		}
-	} finally {
-		if (driver && !options.browserDebug) {
-			driver.quit();
-		}
-	}
-};
-
-function getPageDataScript() {
-	return `
-	const [options, callback] = arguments;
-	getPageData()
-		.then(pageData => callback({ pageData }))
-		.catch(error => callback({ error: error.toString() }));
-
-	async function getPageData() {
-		singlefile.lib.helper.initDoc(document);
-		options.insertSingleFileComment = true;
-		options.insertFaviconLink = true;
-		const preInitializationPromises = [];
-		if (!options.saveRawPage) {
-			if (!options.removeFrames) {
-				preInitializationPromises.push(singlefile.lib.frameTree.content.frames.getAsync(options));
-			}
-			if (options.loadDeferredImages) {
-				preInitializationPromises.push(singlefile.lib.lazy.content.loader.process(options));
-			}
-		}
-		[options.frames] = await Promise.all(preInitializationPromises);
-		options.doc = document;
-		options.win = window;
-		const SingleFile = singlefile.lib.SingleFile.getClass();
-		const singleFile = new SingleFile(options);
-		await singleFile.run();
-		return await singleFile.getPageData();
-	}
-	`;
-}

+ 0 - 1
maff2html/bin/firefox/firefox-56.0a1.en-US.linux-i686.tar.bz2.REMOVED.git-id

@@ -1 +0,0 @@
-efa73272c9de84f67113d16835871839de23e445

+ 0 - 1
maff2html/bin/firefox/firefox-56.0a1.en-US.linux-x86_64.tar.bz2.REMOVED.git-id

@@ -1 +0,0 @@
-068d2160a1f080bbe00adbe703b457af29e0397c

+ 0 - 1
maff2html/bin/firefox/firefox-56.0a1.en-US.mac.dmg.REMOVED.git-id

@@ -1 +0,0 @@
-b542da09a3c56a7bca22be8f0f963ef493435336

+ 0 - 1
maff2html/bin/firefox/firefox-56.0a1.en-US.win32.zip.REMOVED.git-id

@@ -1 +0,0 @@
-1ed9cbf37d51bce3fc2a46e1a3a14bdce87b2f7a

+ 0 - 1
maff2html/bin/firefox/firefox-56.0a1.en-US.win64.zip.REMOVED.git-id

@@ -1 +0,0 @@
-5ac8fffdb8612b141fc72fcbe0138b3ded8e15c5

BIN
maff2html/bin/geckodriver/geckodriver-v0.20.1-linux32.tar.gz


BIN
maff2html/bin/geckodriver/geckodriver-v0.20.1-linux64.tar.gz


BIN
maff2html/bin/geckodriver/geckodriver-v0.20.1-macos.tar.gz


BIN
maff2html/bin/geckodriver/geckodriver-v0.20.1-win32.zip


BIN
maff2html/bin/geckodriver/geckodriver-v0.20.1-win64.zip


+ 0 - 12
maff2html/package.json

@@ -1,12 +0,0 @@
-{
-	"name": "single-file",
-	"version": "0.0.1",
-	"description": "SingleFile",
-	"author": "Gildas Lormeau",
-	"license": "AGPL-3.0-or-later",
-	"dependencies": {
-		"selenium-webdriver": "3.*",
-		"yargs": "12.*",
-		"file-url": "2.0"
-	}
-}

+ 0 - 141
maff2html/single-file

@@ -1,141 +0,0 @@
-#!/usr/bin/env node
-
-/*
- * Copyright 2010-2019 Gildas Lormeau
- * contact : gildas.lormeau <at> gmail.com
- *
- * This file is part of SingleFile.
- *
- *   The code in this file is free software: you can redistribute it and/or
- *   modify it under the terms of the GNU Affero General Public License
- *   (GNU AGPL) as published by the Free Software Foundation, either version 3
- *   of the License, or (at your option) any later version.
- *
- *   The code in this file is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
- *   General Public License for more details.
- *
- *   As additional permission under GNU AGPL version 3 section 7, you may
- *   distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU
- *   AGPL normally required by section 4, provided you include this license
- *   notice and a URL through which recipients can access the Corresponding
- *   Source.
- */
-
-/* global require */
-
-const fileUrl = require("file-url");
-const args = require("yargs")
-	.wrap(null)
-	.command("$0 <url> [output]", "Save a page into a single HTML file.", yargs => {
-		yargs.positional("url", { description: "URL or path on the filesystem of the page to save", type: "string" });
-		yargs.positional("output", { description: "Output filename", type: "string" });
-	})
-	.default({
-		"browser-headless": true,
-		"browser-executable-path": "",
-		"browser-width": 1280,
-		"browser-height": 720,
-		"browser-load-max-time": 60000,
-		"browser-wait-until": "load",
-		"browser-debug": false,
-		"browser-extensions": [],
-		"browser-scripts": [],
-		"compress-CSS": true,
-		"compress-HTML": true,
-		"filename-template": "",
-		"group-duplicate-images": true,
-		"load-deferred-images": true,
-		"load-deferred-images-max-idle-time": 1500,
-		"max-resource-size-enabled": false,
-		"max-resource-size": 10,
-		"remove-hidden-elements": true,
-		"remove-unused-styles": true,
-		"remove-unused-fonts": true,
-		"remove-imports": true,
-		"remove-scripts": true,
-		"remove-audio-src": true,
-		"remove-video-src": true,
-		"remove-alternative-fonts": true,
-		"remove-alternative-medias": true,
-		"remove-alternative-images": true,
-		"save-raw-page": false,
-		"web-driver-executable-path": ""
-	})
-	.options("browser-headless", { description: "Run the browser in headless mode" })
-	.boolean("browser-headless")
-	.options("browser-executable-path", { description: "Path to chrome/chromium executable" })
-	.string("browser-executable-path")
-	.options("browser-width", { description: "Width of the browser viewport in pixels" })
-	.number("browser-width")
-	.options("browser-height", { description: "Height of the browser viewport in pixels" })
-	.number("browser-height")
-	.options("browser-load-max-time", { description: "Maximum delay of time to wait for page loading (in ms)" })
-	.number("browser-load-max-time")
-	.options("browser-wait-until", { description: "When to consider the page is loaded" })
-	.choices("browser-wait-until", ["networkidle0", "networkidle2", "load", "domcontentloaded"])
-	.options("browser-debug", { description: "Enable debug mode" })
-	.boolean("browser-debug")
-	.options("browser-extensions", { description: "List of extension paths separated by a space and relative to maff2html folder" })
-	.array("browser-extensions")
-	.options("compress-CSS", { description: "Compress CSS stylesheets" })
-	.boolean("compress-CSS")
-	.options("compress-HTML", { description: "Compress HTML content" })
-	.boolean("compress-HTML")
-	.options("filename-template", { description: "Template used to generate the output filename (see help page of the extension for more info)" })
-	.string("filename-template")
-	.options("group-duplicate-images", { description: "Group duplicate images into CSS custom properties" })
-	.boolean("group-duplicate-images")
-	.options("load-deferred-images", { description: "Load deferred (a.k.a. lazy-loaded) images" })
-	.boolean("load-deferred-images")
-	.options("load-deferred-images-max-idle-time", { description: "Maximum delay of time to wait for deferred images (in ms)" })
-	.number("load-deferred-images-max-idle-time")
-	.options("max-resource-size-enabled", { description: "Enable removal of embedded resources exceeding a given size" })
-	.boolean("max-resource-size-enabled")
-	.options("max-resource-size", { description: "Maximum size of embedded resources (i.e. images, stylesheets, scripts and iframes) (in MB)" })
-	.number("max-resource-size")
-	.options("remove-frames", { description: "Remove frames" })
-	.boolean("remove-frames")
-	.options("remove-hidden-elements", { description: "Remove HTML elements which are not displayed" })
-	.boolean("remove-hidden-elements")
-	.options("remove-unused-styles", { description: "Remove unused CSS rules and unneeded declarations" })
-	.boolean("remove-unused-styles")
-	.options("remove-unused-fonts", { description: "Remove unused CSS font rules" })
-	.boolean("remove-unused-fonts")
-	.options("remove-imports", { description: "Remove HTML imports" })
-	.boolean("remove-imports")
-	.options("remove-scripts", { description: "Remove JavaScript scripts" })
-	.boolean("remove-scripts")
-	.options("remove-audio-src", { description: "Remove source of audio elements" })
-	.boolean("remove-audio-src")
-	.options("remove-video-src", { description: "Remove source of video elements" })
-	.boolean("remove-video-src")
-	.options("remove-alternative-fonts", { description: "Remove alternative fonts to the ones displayed" })
-	.boolean("remove-alternative-fonts")
-	.options("remove-alternative-medias", { description: "Remove alternative CSS stylesheets" })
-	.boolean("remove-alternative-medias")
-	.options("remove-alternative-images", { description: "Remove images for alternative sizes of screen" })
-	.boolean("remove-alternative-images")
-	.options("save-raw-page", { description: "Save the original page without interpreting it into the browser" })
-	.boolean("save-raw-page")
-	.options("web-driver-executable-path", { description: "Path to Selenium WebDriver executable" })
-	.string("web-driver-executable-path")
-	.argv;
-
-args.compressCSS = args.compressCss;
-args.compressHTML = args.compressHtml;
-if (!/^(https?|file):\/\//.test(args.url)) {
-	args.url = fileUrl(args.url);
-}
-require("./back-ends/webdriver-gecko.js").getPageData(args).then(pageData => {
-	if (args.output) {
-		require("fs").writeFileSync(args.output, pageData.content);
-	} else {
-		if (args.filenameTemplate) {
-			require("fs").writeFileSync(pageData.filename, pageData.content);
-		} else {
-			console.log(pageData.content); // eslint-disable-line no-console			
-		}
-	}
-});

+ 0 - 2
maff2html/single-file.bat

@@ -1,2 +0,0 @@
-@echo off
-node %~dp0\single-file %*

+ 122 - 0
tests/back-ends/puppeteer.js

@@ -0,0 +1,122 @@
+/*
+ * Copyright 2010-2019 Gildas Lormeau
+ * contact : gildas.lormeau <at> gmail.com
+ * 
+ * This file is part of SingleFile.
+ *
+ *   The code in this file is free software: you can redistribute it and/or 
+ *   modify it under the terms of the GNU Affero General Public License 
+ *   (GNU AGPL) as published by the Free Software Foundation, either version 3
+ *   of the License, or (at your option) any later version.
+ * 
+ *   The code in this file is distributed in the hope that it will be useful, 
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of 
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero 
+ *   General Public License for more details.
+ *
+ *   As additional permission under GNU AGPL version 3 section 7, you may 
+ *   distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU 
+ *   AGPL normally required by section 4, provided you include this license 
+ *   notice and a URL through which recipients can access the Corresponding 
+ *   Source.
+ */
+
+/* global singlefile, require, exports, document, window */
+
+const fs = require("fs");
+const url = require('url');
+
+const puppeteer = require("puppeteer-core");
+
+const SCRIPTS = [
+	"../../index.js",
+	"../../lib/hooks/content/content-hooks-frames.js",
+	"../../lib/frame-tree/content/content-frame-tree.js",
+	"../../lib/lazy/content/content-lazy-loader.js",
+	"../../lib/single-file/single-file-util.js",
+	"../../lib/single-file/single-file-helper.js",
+	"../../lib/single-file/vendor/css-tree.js",
+	"../../lib/single-file/vendor/html-srcset-parser.js",
+	"../../lib/single-file/vendor/css-minifier.js",
+	"../../lib/single-file/vendor/css-font-property-parser.js",
+	"../../lib/single-file/vendor/css-media-query-parser.js",
+	"../../lib/single-file/modules/html-minifier.js",
+	"../../lib/single-file/modules/css-fonts-minifier.js",
+	"../../lib/single-file/modules/css-fonts-alt-minifier.js",
+	"../../lib/single-file/modules/css-matched-rules.js",
+	"../../lib/single-file/modules/css-medias-alt-minifier.js",
+	"../../lib/single-file/modules/css-rules-minifier.js",
+	"../../lib/single-file/modules/html-images-alt-minifier.js",
+	"../../lib/single-file/modules/html-serializer.js",
+	"../../lib/single-file/single-file-core.js",
+	"../../lib/single-file/single-file.js"
+];
+
+exports.getPageData = async options => {
+	const browserOptions = {};
+	if (options.browserHeadless !== undefined) {
+		browserOptions.headless = options.browserHeadless && !options.browserDebug;
+	}
+	browserOptions.args = [];
+	browserOptions.args.push("--disable-web-security");
+	browserOptions.args.push("--no-pings");
+	// browserOptions.args.push("--auto-open-devtools-for-tabs");
+	browserOptions.executablePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
+	options.url = "https://www.lemonde.fr";
+	let browser;
+	try {
+		browser = await puppeteer.launch(browserOptions);
+		const singleFilePage = await browser.newPage();
+		await singleFilePage.setBypassCSP(true);
+		let scripts = SCRIPTS.map(scriptPath => fs.readFileSync(require.resolve(scriptPath)).toString()).join("\n");
+		const fileContents = {
+			"/lib/hooks/content/content-hooks-web.js": fs.readFileSync(require.resolve("../../lib/hooks/content/content-hooks-web.js")).toString(),
+			"/lib/hooks/content/content-hooks-frames-web.js": fs.readFileSync(require.resolve("../../lib/hooks/content/content-hooks-frames-web.js")).toString(),
+		};
+		scripts = scripts + ";this.singlefile.lib.getFileContent = filename => (" + JSON.stringify(fileContents) + ")[filename];";
+		await singleFilePage.evaluateOnNewDocument(scripts);
+		const pageOptions = {
+			timeout: 0,
+			waitUntil: options.browserWaitUntil || "networkidle0"
+		};
+		await singleFilePage.goto(options.url, pageOptions);
+		const pageData = await singleFilePage.evaluate(async options => {
+			singlefile.lib.helper.initDoc(document);
+			options.insertSingleFileComment = true;
+			options.insertFaviconLink = true;
+			const preInitializationPromises = [];
+			if (!options.saveRawPage) {
+				if (!options.removeFrames) {
+					preInitializationPromises.push(singlefile.lib.frameTree.content.frames.getAsync(options));
+				}
+				if (options.loadDeferredImages) {
+					preInitializationPromises.push(singlefile.lib.lazy.content.loader.process(options));
+				}
+			}
+			[options.frames] = await Promise.all(preInitializationPromises);
+			options.doc = document;
+			options.win = window;
+			const SingleFile = singlefile.lib.SingleFile.getClass();
+			const singleFile = new SingleFile(options);
+			await singleFile.run();
+			return await singleFile.getPageData();
+		}, options);
+		fs.writeFileSync("__tmp__.html", pageData.content);
+		const originalPage = await browser.newPage();
+		await originalPage.evaluateOnNewDocument(scripts);
+		await Promise.all([singleFilePage.goto("file://" + fs.realpathSync("__tmp__.html"), pageOptions), async () => {
+			await originalPage.goto(options.url, pageOptions);
+			await originalPage.evaluate(async options => {
+				if (options.loadDeferredImages) {
+					await singlefile.lib.lazy.content.loader.process(options);
+				}
+			}, options);
+		}]);
+		const screenshots = await Promise.all([singleFilePage.screenshot({ fullPage: true, path: "sf.png" }), originalPage.screenshot({ fullPage: true, path: "orig.png" })]);
+		return pageData;
+	} finally {
+		if (browser && !options.browserDebug) {
+			await browser.close();
+		}
+	}
+};

+ 64 - 0
tests/single-file

@@ -0,0 +1,64 @@
+#!/usr/bin/env node
+
+/*
+ * Copyright 2010-2019 Gildas Lormeau
+ * contact : gildas.lormeau <at> gmail.com
+ *
+ * This file is part of SingleFile.
+ *
+ *   The code in this file is free software: you can redistribute it and/or
+ *   modify it under the terms of the GNU Affero General Public License
+ *   (GNU AGPL) as published by the Free Software Foundation, either version 3
+ *   of the License, or (at your option) any later version.
+ *
+ *   The code in this file is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
+ *   General Public License for more details.
+ *
+ *   As additional permission under GNU AGPL version 3 section 7, you may
+ *   distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU
+ *   AGPL normally required by section 4, provided you include this license
+ *   notice and a URL through which recipients can access the Corresponding
+ *   Source.
+ */
+
+/* global require */
+
+const config = {
+	"backEnd": "puppeteer",
+	"browserHeadless": true,
+	"browserExecutable-path": "",
+	"browserWidth": 1280,
+	"browserHeight": 720,
+	"browserLoadMaxTime": 60000,
+	"browserWaitUntil": "networkidle0",
+	"browserDebug": false,
+	"browserExtensions": [],
+	"compressCSS": true,
+	"compressHTML": true,
+	"filenameTemplate": "",
+	"groupDuplicateImages": true,
+	"loadDeferredImages": true,
+	"loadDeferredImagesMaxIdleTime": 1500,
+	"maxResourceSizeEnabled": false,
+	"maxResourceSize": 10,
+	"removeHiddenElements": true,
+	"removeUnusedStyles": true,
+	"removeUnusedFonts": true,
+	"removeFrames": false,
+	"removeImports": true,
+	"removeScripts": true,
+	"removeAudioSrc": true,
+	"removeVideoSrc": true,
+	"removeAlternativeFonts": true,
+	"removeAlternativeMedias": true,
+	"removeAlternativeImages": true,
+	"saveRawPage": false,
+	"webDriverExecutablePath": ""
+};
+
+require("./back-ends/puppeteer.js").getPageData(config).then(pageData => {	
+
+
+});