diff --git a/chrome/content/zotero/xpcom/singlefile.js b/chrome/content/zotero/xpcom/singlefile.js index 2f163376da..0912cf8d6f 100644 --- a/chrome/content/zotero/xpcom/singlefile.js +++ b/chrome/content/zotero/xpcom/singlefile.js @@ -67,22 +67,32 @@ Zotero.SingleFile = { autoSaveLoad: false, autoSaveUnload: false, autoSaveLoadOrUnload: true, + autoSaveDiscard: false, + autoSaveRemove: false, autoSaveRepeat: false, autoSaveRepeatDelay: 10, removeAlternativeFonts: true, removeAlternativeMedias: true, removeAlternativeImages: true, + groupDuplicateImages: true, saveRawPage: false, - saveToGDrive: false, + saveToClipboard: false, + addProof: false, forceWebAuthFlow: false, extractAuthCode: true, - insertTextBody: true, resolveFragmentIdentifierURLs: false, userScriptEnabled: true, saveCreatedBookmarks: false, + allowedBookmarkFolders: [], ignoredBookmarkFolders: [], replaceBookmarkURL: true, saveFavicon: true, - includeBOM: false + includeBOM: false, + warnUnsavedPage: true, + insertMetaNoIndex: false, + insertMetaCSP: true, + passReferrerOnError: false, + insertSingleFileComment: true, + blockMixedContent: false, } }; diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js index 0858dadff8..507bdfdf39 100644 --- a/chrome/content/zotero/xpcom/utilities_internal.js +++ b/chrome/content/zotero/xpcom/utilities_internal.js @@ -564,35 +564,11 @@ Zotero.Utilities.Internal = { const SCRIPTS = [ // This first script replace in the INDEX_SCRIPTS from the single file cli loader - "lib/single-file/index.js", - - // Rest of the scripts (does not include WEB_SCRIPTS, those are handled in build process) - "lib/single-file/processors/hooks/content/content-hooks.js", - "lib/single-file/processors/hooks/content/content-hooks-frames.js", - "lib/single-file/processors/frame-tree/content/content-frame-tree.js", - "lib/single-file/processors/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-unescape.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", + "dist/single-file.js", // Web SCRIPTS - "lib/single-file/processors/hooks/content/content-hooks-frames-web.js", - "lib/single-file/processors/hooks/content/content-hooks-web.js", + "dist/web/hooks/hooks-frames-web.js", + "dist/web/hooks/hooks-web.js", ]; const { loadSubScript } = Components.classes['@mozilla.org/moz/jssubscript-loader;1'] @@ -618,11 +594,8 @@ Zotero.Utilities.Internal = { // List of scripts from: // resource/SingleFile/extension/lib/single-file/core/bg/scripts.js const frameScripts = [ - "lib/single-file/index.js", - "lib/single-file/single-file-helper.js", - "lib/single-file/vendor/css-unescape.js", - "lib/single-file/processors/hooks/content/content-hooks-frames.js", - "lib/single-file/processors/frame-tree/content/content-frame-tree.js", + "dist/web/hooks/hooks-frames-web.js", + "dist/single-file-frames.js", ]; // Create sandboxes for all the frames we find @@ -640,7 +613,7 @@ Zotero.Utilities.Internal = { // Use SingleFile to retrieve the html const pageData = await Components.utils.evalInSandbox( - `this.singlefile.lib.getPageData( + `this.singlefile.getPageData( Zotero.SingleFile.CONFIG, { fetch: ZoteroFetch } );`, @@ -666,6 +639,8 @@ Zotero.Utilities.Internal = { sandbox.window = view.window; sandbox.document = sandbox.window.document; sandbox.browser = false; + // See comment in babel-worker.js + sandbox.globalThis = view.window; sandbox.Zotero = Components.utils.cloneInto({ HTTP: {} }, sandbox); sandbox.Zotero.debug = Components.utils.exportFunction(Zotero.debug, sandbox); diff --git a/resource/SingleFile b/resource/SingleFile index da6994a142..832898055f 160000 --- a/resource/SingleFile +++ b/resource/SingleFile @@ -1 +1 @@ -Subproject commit da6994a142c12aab6fd6966f48f48307d53fdedd +Subproject commit 832898055f2d8df8254aeb46f9dccfe7f74d4768 diff --git a/scripts/babel-worker.js b/scripts/babel-worker.js index adf9601440..11c5494be2 100644 --- a/scripts/babel-worker.js +++ b/scripts/babel-worker.js @@ -49,34 +49,17 @@ async function babelWorker(ev) { } // Patch single-file - else if (sourcefile === 'resource/SingleFile/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/SingleFile/'; - - 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 (sourcefile === 'resource/SingleFile/dist/single-file.js') { + // Change for what I assume is a bug in Firefox. We create a singlefile + // sandbox which is based on a document.defaultView of a hidden browser. + // The minified single-file then uses globalThis.Set which for some reason + // doesn't properly support iterating over and throws an error. The normal + // `Set` object accessible in the sandbox does not have this problem. + // I've tried using a proxy for globalThis with a custom Set, but that + // manifest its own issues. Setting the globalThis to sandbox produced + // issues with monkey-patching that singleFile does for default interfaces. + transformed = contents.replace('globalThis.Set', 'Set') + .replace('globalThis.Map', 'Map'); } else if ('ignore' in options && options.ignore.some(ignoreGlob => multimatch(sourcefile, ignoreGlob).length)) { diff --git a/scripts/config.js b/scripts/config.js index cd39f53a29..2d10ed412f 100644 --- a/scripts/config.js +++ b/scripts/config.js @@ -33,12 +33,11 @@ const symlinkFiles = [ '!resource/react.js', '!resource/react-dom.js', '!resource/react-virtualized.js', - // Only include lib directory of singleFile + // Only include dist directory of singleFile // Also do a little bit of manipulation similar to React '!resource/SingleFile/**/*', - 'resource/SingleFile/lib/**/*', - 'resource/SingleFile/extension/lib/single-file/fetch/content/content-fetch.js', - '!resource/SingleFile/lib/single-file/single-file.js', + 'resource/SingleFile/dist/**/*', + '!resource/SingleFile/dist/single-file.js', // We only need a couple Ace Editor files '!resource/ace/**/*', 'resource/ace/ace.js', @@ -109,7 +108,7 @@ const jsFiles = [ 'resource/react.js', 'resource/react-dom.js', 'resource/react-virtualized.js', - 'resource/SingleFile/lib/single-file/single-file.js' + 'resource/SingleFile/dist/single-file.js' ]; const scssFiles = [