Skip to content
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

disable range request in iPhone #7824

Closed
wants to merge 1 commit into from
Closed

Conversation

godwin668
Copy link

Better way but NOT necessarily best way to solve the IOS webview APP error: Unexpected server response (206) while retrieving PDF...

Details:

  1. At the beginning, I only found the Error in IOS WeChat APP, so I solved it by checking WeChat:
    godwin668@9ad57d4

  2. But I found this error in other IOS app, so I checked UA details of them as follow:

a) iPhone WeChat APP UserAgent (Fail):
Mozilla/5.0 (iPhone; CPU iPhone OS 10_1_1 like Mac OS X) AppleWebKit/602.2.14 (KHTML, like Gecko) Mobile/14B100 MicroMessenger/6.3.30 NetType/WIFI Language/zh_CN

b) iPhone Other APP UserAgent (Fail):
Mozilla/5.0 (iPhone; CPU iPhone OS 10_1_1 like Mac X) AppleWebKit/602.2.14 (KHTML, like Gecko) Mobile/14B100 QYZone

Maybe all webview app in IOS 10 have this problem, and since Safari & Chrome in IOS also does NOT support range request in IOS, so I think it's a better way to disable range request in iPhone by this regex:
var isIPhone = /iPhone/.test(navigator.userAgent);
if (isIPhone) {
PDFJS.disableRange = true;
PDFJS.disableStream = true;
}

solve issues:
#7815
#7754
#7800

Better way but NOT necessarily best way to solve the IOS webview APP error: Unexpected server response (206) while retrieving PDF...

Details:
1. At the beginning, I only found the Error in IOS WeChat APP, so I solved it by checking WeChat:
9ad57d4

2. But I found this error in other IOS app, so I checked UA details of them as follow:

a) iPhone WeChat APP UserAgent (Fail):
Mozilla/5.0 (iPhone; CPU iPhone OS 10_1_1 like Mac OS X) AppleWebKit/602.2.14 (KHTML, like Gecko) Mobile/14B100 MicroMessenger/6.3.30 NetType/WIFI Language/zh_CN

b) iPhone Other APP UserAgent (Fail):
Mozilla/5.0 (iPhone; CPU iPhone OS 10_1_1 like Mac X) AppleWebKit/602.2.14 (KHTML, like Gecko) Mobile/14B100 QYZone

Maybe all webview app in IOS 10 have this problem, and since Safari & Chrome in IOS also does NOT support range request in IOS, so I think it's a better way to disable range request in iPhone by this regex:
var isIPhone = /iPhone/.test(navigator.userAgent);
if (isIPhone) {
    PDFJS.disableRange = true;
    PDFJS.disableStream = true;
}

solve issues:
mozilla#7815
mozilla#7754
mozilla#7800
@@ -469,8 +469,10 @@ if (typeof PDFJS === 'undefined') {

// Range requests are broken in Chrome 39 and 40, https://crbug.com/442318
var isChromeWithRangeBug = /Chrome\/(39|40)\./.test(navigator.userAgent);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace on this line.

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't the same problem apply to e.g. iPads as well?

Also, as mentioned in http://stackoverflow.com/questions/9038625/detect-if-device-is-ios: just checking for iPhone can incorrectly match some versions of Internet Explorer too, which we should avoid.

@godwin668
Copy link
Author

@Snuffleupagus

I tested on iPad & iPhone respectively with following result:


-- iPad test UserAgent

iPad Safari (OK)
Mozilla/5.0(iPad; CPU OS 9_3_4 like Mac OS X) AppleWebKit/601.1.46(KHTML, like Gecko)Version/9.0 Mobile/13G35 Safari/601.1

iPad Chrome (OK)
Mozilla/5.0(iPad; CPU OS 9_3_4 like Mac OS X) AppleWebKit/601.1.46(KHTML, like Gecko)CriOS/54.0.2840.91 Mobile/13G35 Safari/601.1.46

iPad QQ APP (Fail)
Mozilla/5.0(iPad; CPU OS 9_3_4 like Mac OS X) AppleWebKit/601.1.46(KHTML, like Gecko)Mobile/13G35 IPadQQ/6.3.1.5 QQ/6.3.1.5

iPad WeChat APP (Fail)
Mozilla/5.0(iPad; CPU OS 9_3_4 like Mac OS X) AppleWebKit/601.1.46(KHTML, like Gecko)Mobile/13G35 MicroMessenger/6.3.25 NetType/WIFI Language/zh_CN


-- iPhone test UserAgent

iPhone WeChat APP (Fail):
Mozilla/5.0 (iPhone; CPU iPhone OS 10_1_1 like Mac OS X) AppleWebKit/602.2.14 (KHTML, like Gecko) Mobile/14B100 MicroMessenger/6.3.30 NetType/WIFI Language/zh_CN

iPhone Other APP (Fail):
Mozilla/5.0 (iPhone; CPU iPhone OS 10_1_1 like Mac X) AppleWebKit/602.2.14 (KHTML, like Gecko) Mobile/14B100 QYZone

@yurydelendik
Copy link
Contributor

@godwin668 how about /\b(iPhone|iPad)(?=;)/.test(...) ?

@Snuffleupagus
Copy link
Collaborator

Snuffleupagus commented Nov 21, 2016

@godwin668 how about /\b(iPhone|iPad)(?=;)/.test(...) ?

Since http://stackoverflow.com/questions/9038625/detect-if-device-is-ios/9039885#9039885 mentions iPod too, it might a good idea to include that as well, like this instead:

var isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(navigator.userAgent);

Edit: Updated, since the (?=;) part should ensure that that we don't accidentally match an IE version.

@yurydelendik
Copy link
Contributor

yurydelendik commented Nov 21, 2016

I don't think we need window.MSStream

The about does not match: Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 930) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537

@timvandermeij
Copy link
Contributor

Superseded by #7841.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants