Giter Site home page Giter Site logo

Comments (4)

gildas-lormeau avatar gildas-lormeau commented on June 21, 2024

Thank you. I was able to reproduce and fix the issue in SingleFile. The fix will be available in the next version.

You will have to adapt the code on your end. The fetch function passed as parameter here https://github.com/zotero/zotero-connectors/blob/d3b870f525137c79a567398b668b87ee19d60fb7/src/common/singlefile.js#L60 should try to fetch the resource via a script injected into the page (i.e. hostFetch in SingleFile, window.wrappedJSObject.fetch might work in Firefox). This script has to fetch the resource from the page itself and outside the extension world. This allows keeping the referrer and origin HTTP header values unchanged (this is the cause of the issue).

from singlefile.

gildas-lormeau avatar gildas-lormeau commented on June 21, 2024

Actually simply passing the option referrerPolicy: "strict-origin-when-cross-origin" to fetch might be sufficient. FYI, the latest version of single-file-core (v1.5.2) adds this option automatically when calling fetch.

from singlefile.

adomasven avatar adomasven commented on June 21, 2024

I've updated SF in the Connector to the latest version which uses referrerPolicy: "strict-origin-when-cross-origin", but it did not help neither in Firefox, nor in Chrome. Are you sure it works without sending the correct referrer?

from singlefile.

gildas-lormeau avatar gildas-lormeau commented on June 21, 2024

Yes, I'm sure it works but for that I have to call fetch outside the content script, in the page itself. You should just have to adapt the code below.

async function hostFetch(url, options) {
if (hostFetchSupported === undefined) {
hostFetchSupported = false;
document.addEventListener(FETCH_SUPPORTED_RESPONSE_EVENT, () => hostFetchSupported = true, false);
document.dispatchEvent(new CustomEvent(FETCH_SUPPORTED_REQUEST_EVENT));
}
if (hostFetchSupported) {
const result = new Promise((resolve, reject) => {
document.dispatchEvent(new CustomEvent(FETCH_REQUEST_EVENT, { detail: JSON.stringify({ url, options }) }));
document.addEventListener(FETCH_RESPONSE_EVENT, onResponseFetch, false);
function onResponseFetch(event) {
if (event.detail) {
if (event.detail.url == url) {
document.removeEventListener(FETCH_RESPONSE_EVENT, onResponseFetch, false);
if (event.detail.response) {
resolve({
status: event.detail.status,
headers: new Map(event.detail.headers),
arrayBuffer: async () => event.detail.response
});
} else {
reject(event.detail.error);
}
}
} else {
reject();
}
}
});
try {
return await result;
} catch (error) {
if (error && error.message == ERR_HOST_FETCH) {
return fetch(url, options);
} else {
throw error;
}
}
} else {
return fetch(url, options);
}
}

This code interacts with the following code in single-file-core.

https://github.com/gildas-lormeau/single-file-core/blob/3921d35301b2904025abbc8705f87e1279d4f52c/processors/hooks/content/content-hooks-frames-web.js#L136-L148.

from singlefile.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.