Merge pull request #1846 from fletcherhaz/snapshot
Use SingleFile to create snapshots of web pages
This commit is contained in:
commit
20c8cede4d
13 changed files with 1924 additions and 54 deletions
|
@ -47,6 +47,74 @@ async function babelWorker(ev) {
|
|||
.replace('document.body.appendChild(scrollDiv)', 'document.documentElement.appendChild(scrollDiv)')
|
||||
.replace('document.body.removeChild(scrollDiv)', 'document.documentElement.removeChild(scrollDiv)');
|
||||
}
|
||||
|
||||
// Note about Single File helper and util patching:
|
||||
// I think this has something to do with the hidden browser being an older version or possibly
|
||||
// it is an issue with the sandbox, but it fails to find addEventListener and the fetch does
|
||||
// not work even if replace it properly in initOptions.
|
||||
|
||||
// Patch single-file-helper
|
||||
else if (sourcefile === 'resource/SingleFileZ/lib/single-file/single-file-helper.js') {
|
||||
transformed = contents.replace('addEventListener("single-filez-user-script-init"',
|
||||
'window.addEventListener("single-filez-user-script-init"');
|
||||
}
|
||||
|
||||
// Patch index.js - This is a SingleFileZ issue. SingleFileZ does not typically use
|
||||
// use this code from SingleFile so the namespace is screwed up.
|
||||
else if (sourcefile === 'resource/SingleFileZ/lib/single-file/index.js') {
|
||||
transformed = contents
|
||||
.replace('this.frameTree.content.frames.getAsync',
|
||||
'this.processors.frameTree.content.frames.getAsync')
|
||||
.replace('this.lazy.content.loader.process',
|
||||
'this.processors.lazy.content.loader.process');
|
||||
}
|
||||
|
||||
// Patch single-file-core
|
||||
// This style element trick was not working in the hidden browser, so we ignore it
|
||||
else if (sourcefile === 'resource/SingleFileZ/lib/single-file/single-file-core.js') {
|
||||
transformed = contents.replace('if (workStylesheet.sheet.cssRules.length) {', 'if (true) {');
|
||||
}
|
||||
|
||||
// Patch content-lazy-loader
|
||||
else if (sourcefile === 'resource/SingleFileZ/lib/single-file/processors/lazy/content/content-lazy-loader.js') {
|
||||
transformed = contents
|
||||
.replace(
|
||||
'if (scrollY <= maxScrollY && scrollX <= maxScrollX)',
|
||||
'if (window.scrollY <= maxScrollY && window.scrollX <= maxScrollX)'
|
||||
);
|
||||
}
|
||||
|
||||
// Patch single-file
|
||||
else if (sourcefile === 'resource/SingleFileZ/lib/single-file/single-file.js') {
|
||||
// We need to add this bit that is done for the cli implementation of singleFile
|
||||
// See resource/SingleFile/cli/back-ends/common/scripts.js
|
||||
const WEB_SCRIPTS = [
|
||||
"lib/single-file/processors/hooks/content/content-hooks-web.js",
|
||||
"lib/single-file/processors/hooks/content/content-hooks-frames-web.js"
|
||||
];
|
||||
let basePath = 'resource/SingleFileZ/';
|
||||
|
||||
function readScriptFile(path, basePath) {
|
||||
return new Promise((resolve, reject) =>
|
||||
fs.readFile(basePath + path, (err, data) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(data.toString() + "\n");
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
const webScripts = {};
|
||||
await Promise.all(
|
||||
WEB_SCRIPTS.map(async path => webScripts[path] = await readScriptFile(path, basePath))
|
||||
);
|
||||
|
||||
transformed = contents + '\n\n'
|
||||
+ "this.singlefile.lib.getFileContent = filename => (" + JSON.stringify(webScripts) + ")[filename];\n";
|
||||
}
|
||||
|
||||
else if ('ignore' in options && options.ignore.some(ignoreGlob => multimatch(sourcefile, ignoreGlob).length)) {
|
||||
transformed = contents;
|
||||
isSkipped = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue