This file is from the dark ages and should be deprecated and replaced with an updated external library.
Most of the functions are not used in core joomla and even those that are so old as to be almost useless.
If we have code to detect isMobile for example then it should do what it says and not test for devices that have not existed for 15+ years
joomla-cms/libraries/src/Environment/Browser.php
Lines 545 to 554 in d01ed85
isRobot is almost the only one that is used in core but again the list used has not been updated since 2018
Labels |
Added:
No Code Attached Yet
|
Labels |
Added:
Feature
|
Core only uses 2 things but extensions might be using more.
@HLeithner found this one which looks like it could almost be a drop in direct replacement https://github.com/hisorange/browser-detect
Finding a good maintained 3rd party lib would be a good solution, but I have the feeling that 3rd party is area is not good maintained, at least the 3 libs I looked at have releases/commits 6-12 Month ago which sounds a long time in the browser/user-agent market.
I think I would prefer to create a joomla-framework/browser abstraction layer which allows us to leverage the work to a 3rd party library but have a stable api if we need to switch.
Anything is better than what we currently have
Removing it would also be an option.
So it's a (expensive) waste of resources (I/O) trying to load a specific file for the browser.
Removing it would also be an option.
But that couldnt happen until j7/8 as it is used by 3pd and meanwhile we have crazy outdated code (where we use it).
We could remove the feature of loading browser specific files in 6.0 if the team decides on this and the other code from com_banners, deprecate it now and then remove it in 7.0.
I can't find this feature documented anywhere... Anybody got an idea if this is docummented somehow? Because if not, I would vote even more so to remove this in 6.0.
Not aware of anywhere that the core uses it for loading browser specific anything but I do know that it used in com_banners for bot detection and I know that extensions use various parts of browser.php.
I'm not saying to remove it right away, but to remove the feature from HTMLHelper::script() and ::stylesheet() with 6.0 to load browser specific files. We don't use that in the core and as Harald wrote, it seems to be an unnecessary feature anyway in todays time and age.
There is already Joomla\Application\Web\WebClient
, available with $app->client
.
Need to find a way to transition from Browser
to WebClient
, and then deprecate Browser
class.
Not sure if the Webclient
is really better and a bit strange that it is in the application but ok, warping the Browser around WebClient
should be possible and allows to remove it in 7
Not sure if the Webclient is really better
Me too, but it is seems much newest than Browser class.
I just wanted to point that we already have something for it, to avoid libraries Zoo
Just for reference: #16528 (Discussion on deprecating JBrowser and moving to WebClient from the framework instead)
And: joomla-framework/application#38 (Discussion to move the WebClient class to its own package)
To be honest, this is extremely frustrating, that we have a discussion about moving this in its own package for 11!! years and a discussion on how to deprecate JBrowser for 8 years and now we are discussing this yet again. Don't get me wrong, the discussions have to be made and all your work is appreciated, but it is frustrating that 11 people have wasted their time several times over the last 11 years to clear this up and instead of finally fixing this, we are now discussing the same stuff again.
That's what happens when those with the position to make a decision take the option to do nothing
... take the option to do nothing
It is more about human resources, and priorities. I would say, this issue has lowest priority.
From what I found in code, the Browser only used in HTMLHelper::includeRelativeFiles()
for $detectBrowser
, which is false
by default.
joomla-cms/libraries/src/HTML/HTMLHelper.php
Lines 418 to 438 in 7830236
I suggesting to deprecate $detectBrowser
feature and Joomla\CMS\Environment\Browser
class in Joomla 5.4 without replacement.
Only feature that is missing in WebClient, is detecting for Robots. But not idea how much it is actually needed.
Just for reference, there were two suggestions for libs:
GH: hisorange/browser-detect
packagist.org/packages/donatj/phpuseragentparser
I have been seeing the following one in J3 templates of one dev for years:
GH: serbanghita/Mobile-Detect
This one is pretty old, but maintained well, the last change was 2 month ago.
Some 10k github stars.
I guess it's a good one for consideration too.
I've decided to use this one for a template update to J5/6.
I subscribed to this issue, so I might be able to comment on how the new version 4.8.2 behaves, if there is the need in future.
Yes https://github.com/serbanghita/Mobile-Detect does look a suitable solution
We are using this class for exactly 2 things: If we have browser-specific assets (like JS and CSS files), the class detects the browser and the HTMLHelper class then tries to load assets specific for that browser. The other thing is in com_banners. There it tries to find out if the user is a bot and if yes, it does not track that user.
A popular library to parse the useragent string seems to be https://packagist.org/packages/donatj/phpuseragentparser
I've not found a library right away to discover bots.