-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds fetch stream logic for networking part of PDF.js #8768
Conversation
Does this fix #6126? |
Yes, this patch is intended to add support for fetch stream. Currently it is using While testing this patch I get to know that we don't have any property named |
688ecd7
to
63b4286
Compare
While testing this PR locally, I find out that Due to this, test for range requests are failing. I am getting |
63b4286
to
84d492d
Compare
} else if (typeof Response !== 'undefined' && 'body' in Response.prototype) { | ||
var PDFFetchStream = require('./display/fetch_stream.js').PDFFetchStream; | ||
pdfjsDisplayAPI.setPDFNetworkStreamClass(PDFFetchStream); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Rob--W do you know if we can enable only fetch_stream.js for Chrome extension?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean?
- Whether
fetch_stream
is disabled for every target except for the Chrome extension build, or - Whether
fetch_stream
can be unconditionally be used in the Chrome extension, anddisplay/network
be removed?
I can't answer 1, but if you meant 2:
- The streaming feature requires Chrome 43 - Implement Fetch API for streaming PDF loads on Chrome #6126 (comment)
- I looked at the telemetry of the Chrome extension for August 2017 (this month), filtered by users with the latest version of the extension (1.8.557, released July 2017, 17th), with a user agent that contains Chrome/digits.
Based on 1.4M unique data points (i.e. pings where the client cannot be distinguished from another client in the same data set; this already happens when the user upgrades their browser version), the usage statistics are as follows:
Chrome 62 0.91%
Chrome 61 0.87%
Chrome 60 56.85% <-- Current stable (officially released July 2017, 25th)
Chrome 59 32.11%
Chrome 58 2.08%
Chrome 57 1.17%
Chrome 56 0.77%
Chrome 55 0.97%
Chrome 54 0.20%
Chrome 53 0.34%
Chrome 52 0.60%
Chrome 51 0.33%
Chrome 50 0.19%
Chrome 49 0.91% <-- last supported Chrome for Windows XP
Chrome 48 0.07%
Chrome 47 0.17%
Chrome 46 0.08%
Chrome 45 0.07%
Chrome 44 0.04%
Chrome 43 0.13% <-- First version where streams API is supported
Chrome 42 0.04%
Chrome 41 0.06%
Chrome 40 0.05%
Chrome 39 0.15%
Chrome 38 0.01%
Chrome 37 0.02%
Chrome 36 0.01%
Chrome 35 0.38% <-- mostly 35.0.1878.0, win7. Doesn't look like an official build.
Chrome 34 0.37% <-- Ubuntu https://apps.ubuntu.com/cat/applications/chromium-browser/
Chrome 33 0.02%
Chrome 32 0.01%
Chrome 31 0.01%
Chrome 100 0.01% <-- I don't know what this is...
1.13% of the users on the latest version of the extension (16k pings) use a Chrome version that does not support the streams API (Chrome 42 and earlier). For now, I'd like to keep supporting these users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for response and analysis. I was asking about (2) -- fetch_stream can be unconditionally be used in the Chrome extension. You answered my question, so we will handle Chrome extension no different than generic viewer.
@mukulmishra18 Can you rebase the commit to the current master? |
d242f17
to
4451a97
Compare
We are trying to "serialize" the reason we are not suppose too. Add makeReasonSerializable:
|
src/display/fetch_stream.js
Outdated
redirect: 'follow', | ||
}).then((response) => { | ||
if (response.status !== 200) { | ||
throw validateResponseStatus(response.status, url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change name to createResponseStatusError.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks.
src/display/fetch_stream.js
Outdated
credentials: this._withCredentials ? 'omit' : 'include', | ||
redirect: 'follow', | ||
}).then((response) => { | ||
if (response.status !== 200) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to validate status based on protocol, for http it is 200 for other protocols it's 0. I recommend to add/have/change validateResponseStatus(status, isHttp) so it will return boolean that will tell is status is valid. Use this function in the range reader as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done with new commit. Thanks.
4451a97
to
e52c0f3
Compare
/botio test |
From: Bot.io (Windows)ReceivedCommand cmd_test from @yurydelendik received. Current queue size: 0 Live output at: http://54.215.176.217:8877/b5dc6fa707adeb3/output.txt |
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @yurydelendik received. Current queue size: 0 Live output at: http://54.67.70.0:8877/d2c468ba2000d41/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.67.70.0:8877/d2c468ba2000d41/output.txt Total script time: 16.50 mins
|
From: Bot.io (Windows)FailedFull output at http://54.215.176.217:8877/b5dc6fa707adeb3/output.txt Total script time: 29.51 mins
Image differences available at: http://54.215.176.217:8877/b5dc6fa707adeb3/reftest-analyzer.html#web=eq.log |
src/display/network_utils.js
Outdated
return false; | ||
} | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!isHttp) {
return status === 0;
}
return status === 200 || status === 206;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks.
src/display/fetch_stream.js
Outdated
fetch(url, { | ||
method: 'GET', | ||
headers: this._headers, | ||
}).then((response) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
define the same options as in full reader. extract the createFetchOptions(headers)
method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created createFetchOptions
with new commit. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, with the validate and options changes.
e52c0f3
to
3516a59
Compare
/botio test |
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @yurydelendik received. Current queue size: 0 Live output at: http://54.67.70.0:8877/9cc359156484d66/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_test from @yurydelendik received. Current queue size: 0 Live output at: http://54.215.176.217:8877/cad322ff23abd42/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.67.70.0:8877/9cc359156484d66/output.txt Total script time: 16.50 mins
|
From: Bot.io (Windows)FailedFull output at http://54.215.176.217:8877/cad322ff23abd42/output.txt Total script time: 29.23 mins
Image differences available at: http://54.215.176.217:8877/cad322ff23abd42/reftest-analyzer.html#web=eq.log |
Thank you for the patch. |
Adds fetch stream logic for networking part of PDF.js
This PR adds Fetch support in networking part of PDF.js project. This PR implements IPDFStream interfaces using Fetch API to stream PDF data. Using Fetch can give us streamable response, that streams PDF data in small chunks.
P.S. fixes #6126