smoothscroll-for-websites icon indicating copy to clipboard operation
smoothscroll-for-websites copied to clipboard

Repo needs updating to pass Chrome's user agent reduction campaign

Open summercms opened this issue 1 year ago • 16 comments

@gblazex Are you around as this repo hasn't been updated for a long time?

I'll jump dive right in to the issue, here's a screenshot of the problem:

image

Chrome's User-Agent Reduction Info can be found here: https://www.chromium.org/updates/ua-reduction/

This has been going for quite a while and I'm surprised this repo hasn't been updated to pass it.

Code issues

https://github.com/gblazex/smoothscroll-for-websites/blob/7d13cd2ea3c8796cb4f7ba78a115a8d212803f87/SmoothScroll.js#L59

and

https://github.com/gblazex/smoothscroll-for-websites/blob/7d13cd2ea3c8796cb4f7ba78a115a8d212803f87/SmoothScroll.js#L739-L746

The API in the near future will be Deprecated and this repo should migrate to navigator.userAgentData

e.g.

image

Deadline

Link: https://blog.chromium.org/2021/09/user-agent-reduction-origin-trial-and-dates.html

This started way back in Chrome 92 and currently we are in Chrome 111.

Reduction Completion
Phase 7: Chrome 113

So time is running out for this repo to update.

summercms avatar Jan 15 '23 13:01 summercms

As far as I can see most (if not all) changes don’t affect our code

  • there will still be a userAgent property for now
  • ismobile info will still be there
  • isMac will still be able to determine the Boolean
  • safari major version check should still run (because it only affects old safari versions that won’t have UA changes)
  • IE Win7 UA wont change either

If you can see a point where it breaks we can work on a fix

gblazex avatar Jan 16 '23 10:01 gblazex

@gblazex I'll list the issues

1

var isMac = /^Mac/.test(navigator.platform); 

becomes

var isMac = /^Mac/.test(navigator.userAgentData.platform);

Because navigator.platform will be deprecated soon!

2

var userAgent = window.navigator.userAgent;

API to become deprecated soon! Migrate to navigator.userAgentData API.

3

var isMobile  = /mobile/i.test(userAgent); 

becomes

var isMobile  = navigator.userAgentData.mobile;

4

var isIEWin7  = /Windows NT 6.1/i.test(userAgent) && /rv:11/i.test(userAgent);

I'm guessing that stands for "Is Internet Explorer Windows 7".

Will not work anymore, because Phase 5 locks it to Windows 10 on Windows 7, 8 and 8.1 devices. Internet Explorer is dead and not supported by Client hints, see here as proof: https://learn.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11#browsers-that-support-user-agent-client-hints

Browser Supports differentiation via User-Agent Client Hints?
Microsoft Edge 94+ Yes
Chrome 95+ Yes
Opera Yes
Firefox No
Internet Explorer 11 No

Therefore this code line is dead in the water and becomes useless.

5

var isEnabledForBrowser = (isChrome || isSafari || isIEWin7) && !isMobile;

becomes

var isEnabledForBrowser = (isChrome || isSafari) && !isMobile;

Due to Phase 5.

6

var isChrome

Will loop through the navigator.userAgentData.brands for the keyword Google Chrome (not Chrome).

7

var isSafari

Will loop through the navigator.userAgentData.brands for the keyword Safari.

8

var isEdge

Will loop through the navigator.userAgentData.brands for the keyword Microsoft Edge (not Edge).

9

var isOldSafari

Will loop through the navigator.userAgentData.brands for the keyword Safari and check the corresponding version number.

summercms avatar Jan 16 '23 12:01 summercms

10

var isEdge    = /Edge/.test(userAgent); // thank you MS

You could remove this line and throw it in the bin. Because User Agent Client Hints API, will give the correct result for Google Chrome and Safari browsers and they won't be mixed with Microsoft Edge browsers. So this code line is not needed now.

summercms avatar Jan 16 '23 13:01 summercms

UserAgentData has 70% support https://caniuse.com/mdn-api_navigator_useragentdata

Meanwhile the current code works virtually everywhere right now

I don’t see any indication that the above Nav.userAgent property code breaks.

Navigator.platform is deprecated and may be removed in the future that can be swapped for a feature detected alternative.

PR is welcome

Blaze

gblazex avatar Jan 16 '23 13:01 gblazex

@gblazex

Want to ask you something:

I was thinking why does the repo search for Chrome browsers to add the smooth slider too.

Would it not be better to search for Chromium instead. Then this repo can apply the smooth scroll to browsers like: Yandex, Samsung Internet, Brave, Google Chrome etc. (as they all Chromium based).

Yah can submit a pr.

summercms avatar Jan 16 '23 14:01 summercms

I’m not familiar with their user agents I would assume they pretend to be chrome as much as Edge does at least

Blaze

gblazex avatar Jan 16 '23 14:01 gblazex

Edge Browser

Versions: EdgeHTML 12.10240 - 18.19041 (are non-chromium based)

Link: https://en.wikipedia.org/wiki/Microsoft_Edge#EdgeHTML

Versions: Edge 79.0.309 onwards (are chromium based)

Therefore Edge 79.0.309 onwards could be grouped with Yandex, Samsung Internet, Brave, Google Chrome etc. (as they all Chromium based).

And EdgeHTML 12-18 versions by itself as I'm guessing there was a conflict with smooth scrolling.

summercms avatar Jan 16 '23 14:01 summercms

To be honest I don’t remember which Edge is detecting the old or the new

The isEdge can be removed if it is not broken in modern edge versions Old IE checks can be removed as well

Blaze

gblazex avatar Jan 16 '23 14:01 gblazex

  • EdgeHTML stopped in mid 2020 (better to keep support up to 3 years - so end support end of 2024).

  • IE11 or lower agree to drop it.

  • Windows under version 10 should be dropped, as Microsoft ended support for Windows 7, 8 and 8.1 recently. Link: https://www.microsoft.com/en-us/windows/end-of-support And link: https://learn.microsoft.com/en-US/lifecycle/faq/extended-security-updates

  • Was reading the issues and seems like Firefox is not supported, could try and add support for desktop and mobile iOS/Android detection.

summercms avatar Jan 16 '23 14:01 summercms

We shouldn’t really follow official support rather real world usage

Blaze

gblazex avatar Jan 16 '23 14:01 gblazex

Just going to dump some data here, for anyone that wants to look it up in the future.

(this data correct as of Jan 2023)

Can I Use

image

image

Firefox Position

image

Neutral - therefore high chance of support in near future.

Safari Position

No signal

Conclsuion

All browser support except for IE (dead), Safari and iOS in near future. Apple sucks!

summercms avatar Jan 16 '23 15:01 summercms

Safari no signal so we don’t know how near that future is

Also even with intent from Firefox that is going to take time to land in the stable channel

Blaze

gblazex avatar Jan 16 '23 15:01 gblazex

UserAgentData.platform reports it as “macOS”

//i flag for the regex might be the safest There

Blaze

gblazex avatar Jan 16 '23 15:01 gblazex

It looks like Edge can be removed

Its not even Edge anymore, But Edg in useragent strings

Blaze

gblazex avatar Jan 16 '23 15:01 gblazex

There are hundreds of chromium browsers that I know are active!

But I'm just going to add the most common ones found here: https://en.wikipedia.org/wiki/Chromium_(web_browser)#Active

At least then it adds smooth scrolling to many commonly used browsers.

summercms avatar Jan 16 '23 15:01 summercms

If you look at them Im 99% Sure This project already supports them as They report Chrome in user agent

Blaze

gblazex avatar Jan 16 '23 15:01 gblazex