thumbnail-zoom icon indicating copy to clipboard operation
thumbnail-zoom copied to clipboard

Set referrer header on image request

Open dadler opened this issue 13 years ago • 3 comments

Some sites won't send a valid image back if the referrer ("Referer" with a single 'r') header isn't correct. When TZP requests the image this header is missing since the request isn't actually sent from the site's document; it's sent from a chrome object.

A possible solution is to set the header explicitly. One way is by installing a global observer to see all http requests, recognize ours, and add the header; see https://developer.mozilla.org/en/Setting_HTTP_request_headers . But it seems like this might have security concerns.

Another way (which Hover Zoom does) is to have the image be requested from the site's document by dynamically editing it. We might do that by putting our entire popup in the document, which would be some work but which could have other benefits too. Or it might be enough to do the initial load into an invisible element in the site's document instead into the "new Image()" object we currently have.

dadler avatar May 06 '12 08:05 dadler

pixiv.net seems to be one site with this issue (at least sometimes).

dadler avatar May 06 '12 08:05 dadler

I've tried to fix this in my private "referrer" branch but it didn't work. Instead of loading the image in an Image xul node, I load it in an html img node which I add to the site's page. But Firefox still doesn't include a referer header (maybe as a security precaution Firefox blocks that header in tags added via javascript?)

A good way to check whether this is working is the "Tamper" add-on, which lets you inspect headers as or after a request is sent.

dadler avatar May 06 '12 23:05 dadler

Another approach is to use XMLHttpRequest to explicitly control the http request for the image data. Request/read the data, then manually stuff it into an image or img node via "data://".

https://developer.mozilla.org/en/DOM/XMLHttpRequest/Sending_and_Receiving_Binary_Data https://developer.mozilla.org/en/DOM/XMLHttpRequest/Using_XMLHttpRequest

Another option may be to load the image into a "Browser" object since its loadURL method lets us specify the referrer. https://developer.mozilla.org/en/XUL/browser

The greasemonkey Mouse Over Popup Image Viewer script uses a similar approach: http://userscripts.org/scripts/review/109262

dadler avatar May 06 '12 23:05 dadler