Open Bug 1902898 Opened 1 year ago Updated 5 months ago

Unexpected server response while opening local PDF on hosted PDF.js

Categories

(GeckoView :: General, defect)

Firefox 124
All
Android
defect

Tracking

(firefox127 affected, firefox128 affected, firefox129 affected)

Tracking Status
firefox127 --- affected
firefox128 --- affected
firefox129 --- affected

People

(Reporter: shivapv, Unassigned)

Details

Attachments

(1 file)

Steps to reproduce:

See: https://github.com/mozilla/pdf.js/issues/18252

Web browser and its version: Fenix 126.0 (Build #2016019898)
Operating system and its version: Android 14 arm64

Reproducible from Fenix 124.0b1 onwards. STR:

  1. Open the demo at: https://mozilla.github.io/pdf.js/web/viewer.html
  2. Open a local PDF from device via the overflow menu => Open

Actual results:

Does not open/show the PDF.

It works if you try a second time, even after a page reload.

Expected results:

Should open the PDF as normal.

This is a problem for Add-ons that uses the generic PDF.js library to host a custom viewer.

The severity field is not set for this bug.
:amejia, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(amejiamarmol)

Olivia, could this bug loading the PDF.js viewer hosted on a website be caused by some interaction with Firefox's built-in PDF reader?

Component: General → Browser Engine
Flags: needinfo?(ohall)

The bug has a release status flag that shows some version of Firefox is affected, thus it will be considered confirmed.

Status: UNCONFIRMED → NEW
Ever confirmed: true

Thanks for reporting this, Shiva!

Just echoing some of what is listed in the GitHub bug, I also saw:

07-02 11:50:33.791  2039  2912 I Gecko   : IPDL protocol Error: Received an invalid file descriptor
07-02 11:50:33.795  2039  2295 E Web Content: [JavaScript Error: "Unexpected server response.
07-02 11:50:33.795  2039  2295 E Web Content: 
07-02 11:50:33.795  2039  2295 E Web Content: PDF.js v4.5.7 (build: ccad2f889)
07-02 11:50:33.795  2039  2295 E Web Content: Message: Unexpected server response (0) while retrieving PDF "blob:https://mozilla.github.io/b14e6e40-45ff-4c07-a702-cd21866b3c10"."]
07-02 11:50:33.795  2039  2295 E Web Content: [JavaScript Error: "uncaught exception: Object"]
07-02 11:50:34.435  1857  1857 D GeckoSession: handleMessage GeckoView:StateUpdated uri=null
07-02 11:50:35.273   500  1312 E TaskPersister: File error accessing recents directory (directory doesn't exist?).

And it mysteriously works on the second attempt.

Probably where the Received an invalid file descriptor message came from.

I also see this in the logs as an error:

07-02 11:53:38.072  3268  3268 E ViewConfiguration: Tried to access UI constants from a non-visual Context:com.android.documentsui.DocumentsApplication@5a3e008UI constants, such as display metrics or window metrics, must be accessed from Activity or other visual Context. Use an Activity or a Context created with Context#createWindowContext(int, Bundle), which are adjusted to the configuration and visual bounds of an area on screen
07-02 11:53:38.072  3268  3268 E ViewConfiguration: java.lang.IllegalArgumentException: Tried to access UI constants from a non-visual Context:com.android.documentsui.DocumentsApplication@5a3e008

Just highlighting this is a regression, from the original report:

I tried with an older Fenix version and could not reproduce the issue. I then did a bisect with Fenix versions and found that the first bad version is 124.0b1.

Blob support keeps coming up around PDFs as well, like in bug 1553790 and bug 1891737. Not sure if it is related, but it is something that keeps showing up.

I think(?) this is the relevant PDF.js code that is called. So, it looks like an input to get the file and here is where the blob is made.

Calixte, does anything stand out to you?

Component: Browser Engine → PDF Viewer
Flags: needinfo?(ohall) → needinfo?(cdenizet)
Product: Fenix → GeckoView

The built-in pdf viewer isn't involved here, I mean https://mozilla.github.io/pdf.js/web/viewer.html is a normal website.
As you pointed it we create a blob url from the file and then we fetch it in using a xhr:
https://github.com/mozilla/pdf.js/blob/ccad2f889ae8e721b1a1119190f03f99c68ae763/src/display/network.js#L66

Out of curiosity, I just try in adding this code:

    const file = evt.fileInput.files[0];
    const url = URL.createObjectURL(file);
    const xhr = new XMLHttpRequest();
    xhr.open("GET", url);
    console.log({file, url, xhr});
    xhr.responseType = "arraybuffer";
    let total = 0;
    xhr.onload = function() {
        const arrayBuffer = xhr.response;
        const byteArray = new Uint8Array(arrayBuffer);
        total += byteArray.length;
        console.log(`Total bytes: ${total}`);
    };
    xhr.onerror = function(e) {
        console.log(`Error loading file: ${e}`);
    };
    xhr.send(null);

just after getting the file from the input and I got the same error.
I tried to get the arraybuffer just after getting the file in using a FileReader and it works.
So my feeling is that there is something wrong when fetching the data from the blob url.

Flags: needinfo?(cdenizet)
Flags: needinfo?(amejiamarmol)

The severity field is not set for this bug.
:calu, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(calu)
Severity: -- → S3
Flags: needinfo?(calu)
Component: PDF Viewer → General
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: