Feature No Code Attached Yet
avatar brianteeman
brianteeman
14 Apr 2025

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

if (
strpos($this->agent, 'MOT-') !== false
|| strpos($this->lowerAgent, 'j-') !== false
|| preg_match('/(mobileexplorer|openwave|opera mini|opera mobi|operamini|avantgo|wap|elaine)/i', $this->agent)
|| preg_match('/(iPhone|iPod|iPad|Android|Mobile|Phone|BlackBerry|Xiino|Palmscape|palmsource)/i', $this->agent)
|| preg_match('/(Nokia|Ericsson|docomo|digital paths|portalmmm|CriOS[\/ ]([0-9.]+))/i', $this->agent)
|| preg_match('/(UP|UP.B|UP.L)/', $this->agent)
|| preg_match('/; (120x160|240x280|240x320|320x320)\)/', $this->agent)
) {
$this->mobile = true;

isRobot is almost the only one that is used in core but again the list used has not been updated since 2018

avatar brianteeman brianteeman - open - 14 Apr 2025
avatar joomla-cms-bot joomla-cms-bot - change - 14 Apr 2025
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 14 Apr 2025
avatar QuyTon QuyTon - change - 17 Apr 2025
Labels Added: Feature
avatar QuyTon QuyTon - labeled - 17 Apr 2025
avatar Hackwar
Hackwar - comment - 17 Apr 2025

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.

avatar brianteeman
brianteeman - comment - 17 Apr 2025

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

avatar HLeithner
HLeithner - comment - 18 Apr 2025

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.

avatar brianteeman
brianteeman - comment - 18 Apr 2025

Anything is better than what we currently have

avatar HLeithner
HLeithner - comment - 18 Apr 2025

Removing it would also be an option.

  • many bots hiding them self (see the AI bots)
  • having separate js/css files for browsers is also not relevant anymore, we have 2 (3) browser engines, firefox (Gecko), chrome (webkit/blink) and Safari (Webkit) which is also mostly compatible to chrome/blink

So it's a (expensive) waste of resources (I/O) trying to load a specific file for the browser.

avatar brianteeman
brianteeman - comment - 18 Apr 2025

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).

avatar Hackwar
Hackwar - comment - 18 Apr 2025

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.

avatar Hackwar
Hackwar - comment - 18 Apr 2025

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.

avatar brianteeman
brianteeman - comment - 18 Apr 2025

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.

avatar Hackwar
Hackwar - comment - 18 Apr 2025

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.

avatar Fedik
Fedik - comment - 18 Apr 2025

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.

avatar HLeithner
HLeithner - comment - 18 Apr 2025

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

avatar Fedik
Fedik - comment - 18 Apr 2025

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

avatar Hackwar
Hackwar - comment - 21 Apr 2025

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.

avatar brianteeman
brianteeman - comment - 21 Apr 2025

That's what happens when those with the position to make a decision take the option to do nothing

avatar Fedik
Fedik - comment - 22 Apr 2025

... 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.

if ($detectBrowser) {
$navigator = Browser::getInstance();
$browser = $navigator->getBrowser();
$major = $navigator->getMajor();
$minor = $navigator->getMinor();
$minExt = '';
if (\strlen($strip) > 4 && preg_match('#\.min$#', $strip)) {
$minExt = '.min';
$strip = preg_replace('#\.min$#', '', $strip);
}
// Try to include files named filename.ext, filename_browser.ext, filename_browser_major.ext, filename_browser_major_minor.ext
// where major and minor are the browser version names
$potential = [
$strip . $minExt,
$strip . '_' . $browser . $minExt,
$strip . '_' . $browser . '_' . $major . $minExt,
$strip . '_' . $browser . '_' . $major . '_' . $minor . $minExt,
];
} else {

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.

avatar QuyTon
QuyTon - comment - 10 May 2025

Related #42474

avatar QuyTon
QuyTon - comment - 10 May 2025

Related PR #42474

avatar StefanSTS
StefanSTS - comment - 25 Jun 2025

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.

avatar brianteeman
brianteeman - comment - 25 Jun 2025

Yes https://github.com/serbanghita/Mobile-Detect does look a suitable solution

Add a Comment

Login with GitHub to post a comment