Closed Bug 1715580 Opened 3 years ago Closed 2 years ago

Firefox extension can not download files from whatsapp web

Categories

(WebExtensions :: Untriaged, defect)

Firefox 88
defect

Tracking

(firefox89 affected, firefox90 affected, firefox91 affected)

RESOLVED INVALID
Tracking Status
firefox89 --- affected
firefox90 --- affected
firefox91 --- affected

People

(Reporter: andrey2013, Unassigned)

Details

Attachments

(3 files)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36

Steps to reproduce:

In the code of the browser extension (background.js):

  1. Add listener to downloads.onCreatedEvent
    browser.downloads.onCreated.addListener((downloadItem)=>{...
  2. Try to download the file from the url downloadItem.url via the following simple code:
    var xhr = new XMLHttpRequest();
    xhr.open("GET", download.url, true);
    xhr.withCredentials = true;
    xhr.timeout = 1000000;
    xhr.responseType = "arraybuffer";
    xhr.onload = function() {
    console.log('on load');
    }
    xhr.ontimeout = function(e) {
    console.log('on timeout');
    }
    xhr.onerror = function(e) {
    console.log('error');
    console.log(e);
    }
    xhr.onprogress = function(evt) {
    console.log(evt);
    }
    xhr.onreadystatechange = function() {
    console.log('onreadystatechange');
    }
    xhr.send();
  3. Enter whatsapp web and try to download an attached document

Actual results:

When background.js will try to download the file, the following error will be shown:
Security Error: Content at moz-extension://.../_generated_background_page.html may not load data from blob:https://web.whatsapp.com/...

The same error occurs if I do F12 in whatsappweb.com and I try to run that code from the console:
Security Error: Content at https://web.whatsapp.com/ may not load data from blob:https://web.whatsapp.com/d29b58ca-5d29-4355-9e04-bb575d7ce872.

Expected results:

The ajax request which is used to download the file should work

The Bugbug bot thinks this bug should belong to the 'WebExtensions::Untriaged' component, and is moving the bug to that component. Please revert this change in case you think the bot is wrong.

Product: Firefox → WebExtensions

Hello,

I’ve attempted to reproduce the issue, however I’m having some trouble with building a working extension. Could you please attach the test extension you used here?

Furthermore, as per the actual results, I’ve tried accessing a conversation on whatsappweb.com which has several attachments, opening the web console (F12) and running the code from Step 2. Nothing happens, except for a reference error being printed in the console (Uncaught ReferenceError: download is not defined).

I’ve also tried accessing an attachment from said conversation and running the code and opening the attachment in a new tab and running the code. Nothing happens once more in both cases, except for the reference error.

Could you provide some more specific steps to reproduce?

Thank you !

Flags: needinfo?(andrey2013)

Could you share reproduction steps, consisting of an extension and a publicly available test page, independent of Whatsapp web?

Attached file simple_extension.zip

A simple extension in which the issue can reproduced

Flags: needinfo?(andrey2013)

Hello,

The issue can be reproduced in the attached simple extension (simple_extension.zip which contains only basic code that is relevant for the bug. Please load it via about:debugging).
Unfortunetly, I don't know how to reproduce it outside whatsapp web. I suspect that the problem is with download in which the url of the download starts with blob:.. and i'm not fimiliar with other sites that use such links.

Attached image background_console.PNG

I also attached background_console.png.
After I loaded simple_extension.zip and pressed "Inspect" and got to the console of the background.
This is the image after the issue was recreated.
You can see there the following error:
Security Error: Content at moz-extension://b9ca3200-8f06-4ac1-bfb5-dc2faf7ebbd0/_generated_background_page.html may not load data from blob:https://web.whatsapp.com/f7be7816-e611-4621-b748-cf3e1d985f6d.

Thank you very much for your assistance.

Hello and thank you for the additional info and extension !

I reproduced the issue on the latest Nightly (91.0a1/2021061421540), Beta (90.0b7/20210613190011) and Release (89.0/20210527174632) under Windows 10 x64 and Ubuntu 16.04 LTS.

Attempting to download an image from whatsapp web while the test add-on is loaded will produce the mentioned error in the console. For further details, please see the attached screenshot.

However, I would like to mention that I could download the image in question using “Save Image As…” from the right click context menu or by using the whatsapp download button on the page.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Attached image 2021-06-15_11h34_10.png
Flags: needinfo?(rob)

The behavior is expected. There are two potential reasons for the observed error:

  1. The page does not have permission to request the requested blob:-URL.
  2. The requested blob URL no longer exists.

When you request a blob:https... URL from an extension page, the request is expected to fail because blob:-URLs can only be requested by the origin that created the URL.

The same error occurs if I do F12 in whatsappweb.com and I try to run that code from the console:

This is probably issue 2.

Status: NEW → RESOLVED
Closed: 2 years ago
Flags: needinfo?(rob)
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: