Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I get the data of a cross-site <img/> tag as a blob?
    primarykey
    data
    text
    <p>I am trying to save a couple of images that are linked to by a webpage to offline storage. I'm using IndexedDB on Firefox and FileSystem API on Chrome. My code is actually an extension, so on Firefox I'm running on Greasemonkey, and on Chrome as a content script. I want this to be automated.</p> <p>I am running into problem when I retrieve the image file. I'm using example code from the article titled <a href="http://hacks.mozilla.org/2012/02/storing-images-and-files-in-IndexedDB/" rel="nofollow noreferrer">Storing images and files in IndexedDB</a>, but I get an error: the images I'm trying to download are on a different subdomain and the XHR fails. </p> <pre><code>XMLHttpRequest cannot load http://...uxgk.JPG. Origin http://subdomain.domain.com is not allowed by Access-Control-Allow-Origin. </code></pre> <p>On Firefox I could probably use <code>GM_xmlhttpRequest</code> and it'd work (the code works on both browsers when I'm in same-origin URLs), but I still need to solve the problem for Chrome, in which other constraints (namely, needing to interact with frames on the host page) require me to incorporate my script in the page and forfeit my privileges.</p> <p>So it comes back to that I'm trying to figure out a way to save images that are linked to (and may appear in) the page to IndexedDB and/or FileSystem API. I either need to realize how to solve the cross-origin problem in Chrome (and if it requires privileges, then I need to fix the way I'm interacting with jQuery) or some kind of reverse <a href="https://developer.mozilla.org/en/Document_Object_Model_%28DOM%29/window.URL.createObjectURL" rel="nofollow noreferrer">createObjectURL</a>. At the end of the day I need a blob (<code>File</code> object, as far as I understand) to put into the IndexedDB (Firefox) or to write to FileSystem API (Chrome)</p> <p>Help, anyone?</p> <hr> <p>Edit: my question may actually really come down to how I can use jQuery the way I want without losing my content script privileges on Chrome. If I do, <a href="http://code.google.com/chrome/extensions/xhr.html" rel="nofollow noreferrer">I could use cross-origin XHRs on Chrome</a> as well. Though I'd much rather get a solution that doesn't rely on that. Specifically since I'd like this solution if I get the script incorporated into the webpage, and not require it to be a content script/userscript.</p> <hr> <p>Edit: I realized that the question is <em>only about cross-site requests</em>. Right now I have one of three ways to get the image blob, with the help of @chris-sobolewski, <a href="https://stackoverflow.com/questions/8778863/downloading-an-image-using-xmlhttprequest-in-a-userscript">these</a> <a href="https://stackoverflow.com/questions/5511378/security-err-dom-exception-18-on-using-getimagedata-in-a-chrome-extension">questions</a> and some other pages (like <a href="http://code.google.com/p/chromium/issues/detail?id=52486#c27" rel="nofollow noreferrer">this</a>), which can be seen in <a href="http://jsfiddle.net/KEnVR/" rel="nofollow noreferrer">this fiddle</a>. However, all of these require special privileges in order to run. Alas, since I'm running on a page with frames, because of <a href="https://code.google.com/p/chromium/issues/detail?id=20773" rel="nofollow noreferrer">a known defect in Chrome</a>, I can't access the frames. So I can load a script into each frame by using <code>all_frames: true</code>, but I really want to avoid loading the script with every frame load. Otherwise, <a href="http://blog.afterthedeadline.com/2010/05/14/how-to-jump-through-hoops-and-make-a-chrome-extension/" rel="nofollow noreferrer">according to this article</a>, I need to escape the sandbox, but then it comes back to privileges.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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