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

Check mobile ie11 and ie11 running compatibility mode #34

Merged
merged 2 commits into from
Oct 21, 2021

Conversation

Busfox
Copy link
Contributor

@Busfox Busfox commented Oct 18, 2021

Description

The method ie11? will return false for ie11 mobile and when ie11 is running in compatibility mode for an older browser.

For example:

Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; InfoPath.3; Tablet PC 2.0; Zoom 3.6.0)

^ this UA string is for IE11 on windows 10 running in IE7 compatibility mode. .ie11? will return false, since it's seeing the browser as IE7.

Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; Microsoft; Lumia 640 XL) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537

^ this UA string is for IE11 mobile running on Windows Phone 8.1. ie11? will return false since the browser isn't being properly captured.

This PR adds a new method called ie11_actual? that looks a little deeper to determine if the UA is for IE11. It checks:

  • that the browser is :ie and the major_browser_version is 11 - the same check in the ie11? method
    OR
  • that the engine_name is "Trident" and the major_engine_version is 7, catching any browsers using the IE11 engine
    OR
  • that the major_browser_version is 11 and the browser_name is "IEMobile"

Why this approach?

In the case that 1. apps using the ie11? method rely on having it return true for the browser version being served regardless of whether it's a compatibility view and 2. apps using the ie11? method rely on only desktop version to cause true to be returned, I opted to create a new method that will return true when ie11 is in use in any way.

@Busfox Busfox self-assigned this Oct 18, 2021
Copy link

@chrisbutcher chrisbutcher left a comment

Choose a reason for hiding this comment

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

One suggestion on the boolean checks.

lib/browser_sniffer.rb Show resolved Hide resolved
Copy link

@CelineBen CelineBen left a comment

Choose a reason for hiding this comment

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

Looks good!
I think it might be useful to add a little comment on top of ie11_actual? to explain why it is needed.

@@ -24,6 +24,14 @@ def ie11?
browser == :ie && major_browser_version == 11
end

def ie11_actual?
ie_11 = browser == :ie && major_browser_version == 11

Choose a reason for hiding this comment

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

Could we use the ie11? method instead of redefining it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about that, but there could be legitimate uses where ie11? is being relied on to return false even if it's ie11 rendering as ie7 in compatibility mode, for example. I don't want to break any apps out there.

Choose a reason for hiding this comment

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

Oh no, I meant using the existing method ie11? instead of defining this ie_11 variable here.

Copy link

@CelineBen CelineBen Oct 20, 2021

Choose a reason for hiding this comment

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

Ah I see that you have already done that! 👍

@Busfox Busfox merged commit 36767e5 into master Oct 21, 2021
@shopify-shipit shopify-shipit bot temporarily deployed to rubygems October 21, 2021 17:05 Inactive
@shopify-shipit shopify-shipit bot temporarily deployed to rubygems-backport May 24, 2022 20:26 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants