Changes for updated SingleFile submodule

This commit is contained in:
Adomas Venčkauskas 2022-07-20 14:23:28 +03:00
parent a297692487
commit d822da4c06
3 changed files with 17 additions and 13 deletions

View file

@ -570,11 +570,10 @@ Zotero.Utilities.Internal = {
const SCRIPTS = [
// This first script replace in the INDEX_SCRIPTS from the single file cli loader
"dist/single-file.js",
"lib/single-file.js",
// Web SCRIPTS
"dist/web/hooks/hooks-frames-web.js",
"dist/web/hooks/hooks-web.js",
"lib/single-file-hooks-frames.js",
];
const { loadSubScript } = Components.classes['@mozilla.org/moz/jssubscript-loader;1']
@ -600,8 +599,8 @@ Zotero.Utilities.Internal = {
// List of scripts from:
// resource/SingleFile/extension/lib/single-file/core/bg/scripts.js
const frameScripts = [
"dist/web/hooks/hooks-frames-web.js",
"dist/single-file-frames.js",
"lib/single-file-hooks-frames.js",
"lib/single-file-frames.js",
];
// Create sandboxes for all the frames we find
@ -653,7 +652,7 @@ Zotero.Utilities.Internal = {
// Mostly copied from:
// resources/SingleFile/extension/lib/single-file/fetch/bg/fetch.js::fetchResource
sandbox.coFetch = Components.utils.exportFunction(
function (url, onDone) {
function (url, options, onDone) {
const xhrRequest = new XMLHttpRequest();
xhrRequest.withCredentials = true;
xhrRequest.responseType = "arraybuffer";
@ -679,6 +678,11 @@ Zotero.Utilities.Internal = {
}
};
xhrRequest.open("GET", url, true);
if (options && options.headers) {
for (const entry of Object.entries(options.headers)) {
xhrRequest.setRequestHeader(entry[0], entry[1]);
}
}
xhrRequest.send();
},
sandbox
@ -689,14 +693,14 @@ Zotero.Utilities.Internal = {
// resources/SingleFile/extension/lib/single-file/fetch/content/content-fetch.js::fetch
Components.utils.evalInSandbox(
`
ZoteroFetch = async function (url) {
ZoteroFetch = async function (url, options) {
try {
let response = await fetch(url, { cache: "force-cache" });
let response = await fetch(url, { cache: "force-cache", headers: options.headers });
return response;
}
catch (error) {
let response = await new Promise((resolve, reject) => {
coFetch(url, (response) => {
coFetch(url, { headers: options.headers }, (response) => {
if (response.error) {
Zotero.debug("Error retrieving url: " + url);
Zotero.debug(response);

View file

@ -48,7 +48,7 @@ async function babelWorker(ev) {
.replace('document.body.removeChild(scrollDiv)', 'document.documentElement.removeChild(scrollDiv)');
}
// Patch single-file
else if (sourcefile === 'resource/SingleFile/dist/single-file.js') {
else if (sourcefile === 'resource/SingleFile/lib/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

View file

@ -37,8 +37,8 @@ const symlinkFiles = [
// Only include dist directory of singleFile
// Also do a little bit of manipulation similar to React
'!resource/SingleFile/**/*',
'resource/SingleFile/dist/**/*',
'!resource/SingleFile/dist/single-file.js',
'resource/SingleFile/lib/**/*',
'!resource/SingleFile/lib/single-file.js',
// We only need a couple Ace Editor files
'!resource/ace/**/*',
'resource/ace/ace.js',
@ -112,7 +112,7 @@ const jsFiles = [
'resource/react.js',
'resource/react-dom.js',
'resource/react-virtualized.js',
'resource/SingleFile/dist/single-file.js',
'resource/SingleFile/lib/single-file.js',
'resource/citeproc_rs_wasm.js',
];