Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can binary files be requested from GreaseMonkey userscripts?
    primarykey
    data
    text
    <p><strong>Backstory</strong></p> <p>I wrote a specialized image inliner script that is intended to be used with both GreaseMonkey and Google Chrome. It is supposed to download PNG files and store them in <code>data:</code> urls in image <code>src</code> attributes. This may sound ridiculous, but a certain website sets <code>Content-Disposition</code> to <code>attachment</code> for images, and I don't want the «Save As» dialog to pop up every time.</p> <p><strong>The actual question</strong></p> <p>The script fetches data with an <code>XMLHttpRequest</code>, encodes it into base64 and stores it in a proper place. So far, good. But it only works when I run it through both Firebug and Chrome dev consoles, and does not when I use it as a proper userscript. As far as I understand, this is because Greasemonkey scripts cannot use <code>XMLHttpRequest</code> objects directly and should rely on calls to <code>GM_xmlhttpRequest</code> instead. However, I cannot set <code>responseType</code> to <code>"blob"</code> or <code>"arraybuffer"</code> that way, and the <code>binary</code> parameter seems to only work for sending data through POST requests. I only get Unicode strings.</p> <p>Just in case, the images are served from the same domain as the page that links to them. I believe it satisfies the «same origin» thingy.</p> <p><a href="http://wiki.greasespot.net/GM_xmlhttpRequest" rel="nofollow">http://wiki.greasespot.net/GM_xmlhttpRequest</a> here are the GM_xmlhttpRequest docs.</p> <p>Is there a way to fetch an <code>arraybuffer</code> from within a Greasemonkey userscript?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload