Reputation: 364
I'm trying to pass large binary data (e.g. new Uint8Array(10000000)) from web page's JavaScript (JS) to extension's JS. I want these data to be saved from extension to a file by nsIBinaryOutputStream/nsIFile (which I can't call from my page). [ATM I don't know about any other method how to save (large/binary) data from page's JS on local machine.]
I've red about an Interaction between privileged and non-privileged pages, but it is useful only for passing strings. I don't think that converting 10MB from/to base64 is good idea.
Thank you for suggestions.
Upvotes: 1
Views: 415
Reputation: 364
OK, I've solved how to pass any object from webpage to extension.
In web page JavaScript (JS):
var element = document.createElement("foo");
document.documentElement.appendChild(element);
var event = document.createEvent("CustomEvent");
event.initCustomEvent("bar", true, false, anyObject);
element.dispatchEvent(event);
In extension JS:
document.addEventListener("bar", function(e) {
// use e.detail here
}, false, true);
Upvotes: 1
Reputation: 3897
If you have data in file, you can use nsIWebBrowserPersist
and download data directly to a file. This file can be zipped, and it's possible to unzip it. A lot of informations (with examples) you can find on these pages:
download file using nsiWebBrowserPersist
Upvotes: 0