Thank you all for your help
I tried :
const blob = await (await fetch(imageUri)).blob();
but I had some problems using asynchronous functions in my code so I rather used :
fetch(imageUri)
.then(function(response) {
return response.blob();
})
.then(function(myBlob) {
var urlTest = URL.createObjectURL(myBlob);
var dl = browser.downloads.download({
url : urlTest,
filename : "DossierCapture/test.png",
conflictAction : 'uniquify'
});
I tried “Take Screenshot” on Chrome but I didn’t manage to download a page. It scrolls down the page and open a new tab (about:blank) but I didn’t get anything after that.
The “Save Screenshot” Addon helped me a lot especially this part :
function SaveScreenshot(aLeft, aTop, aWidth, aHeight) {
// Maximum size is limited!
// https://dxr.mozilla.org/mozilla-central/source/dom/canvas/CanvasRenderingContext2D.cpp#5517
// https://dxr.mozilla.org/mozilla-central/source/gfx/2d/Factory.cpp#316
if (aHeight > 32767) aHeight = 32767;
if (aWidth > 32767) aWidth = 32767;
var canvas = document.createElementNS("http://www.w3.org/1999/xhtml", "html:canvas");
canvas.height = aHeight;
canvas.width = aWidth;
var ctx = canvas.getContext("2d");
ctx.drawWindow(window, aLeft, aTop, aWidth, aHeight, "rgb(0,0,0)");
let imgdata;
imgdata = canvas.toDataURL("image/png");
sendMessage(imgdata);
}
It took me some time to understand how to make content script and background script communicate.
I use
browser.tabs.query
and browser.tabs.sendMessage
for the background.
browser.runtime.onMessage
and browser.runtime.sendMessage
for the content.
browser.runtime.onMessage
again but for the background.
Thanks again