No Code Attached Yet J3 Issue
avatar photodude
photodude
5 Jun 2017

I suggest we depreciate JBrowser in favor of using the framework webclient going forward

in depreciating JBrowser for 4.0 we will need to rewrite some parts of JHtml that currently use JBrowser so they will work with the framework Joomla\Application\Web\WebClient

What is the community's thoughts on this???

Expected result

one library for one task

Actual result

we currently are (poorly) maintaining two similar libraries that do basically the same thing. The code is not the same and the function outputs are different in both classes, even though they have the same tasks.

Additional comments

duplicated code is bad, we should be DRY (do not repeat yourself)

Discussions on replacing all the browser detection with a 3rd party library should be separate from this discussion.

avatar photodude photodude - open - 5 Jun 2017
avatar joomla-cms-bot joomla-cms-bot - change - 5 Jun 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 5 Jun 2017
avatar franz-wohlkoenig franz-wohlkoenig - change - 5 Jun 2017
Category Libraries
avatar wilsonge
wilsonge - comment - 5 Jun 2017

There's a lot of options here. Joomla\Application\Web\WebClient is honestly worse than JBrowser. I'm unconvinced that many (if any) people use JBrowser parts of JHtml so honestly it comes down to the mobile detection, which is used more.

avatar photodude
photodude - comment - 5 Jun 2017

Do you think it would be worth replacing Joomla\Application\Web\WebClient with JBrowser?
note: It would make a bit of a mess in the framework since the two classes have different return values.

avatar franz-wohlkoenig franz-wohlkoenig - change - 7 Jun 2017
Status New Discussion
avatar brianteeman brianteeman - change - 8 Jun 2017
Title
[RFC] depreciate JBrowser and use framework WebClient
[RFC] deprecate JBrowser and use framework WebClient
avatar brianteeman brianteeman - change - 8 Jun 2017
Title
[RFC] depreciate JBrowser and use framework WebClient
[RFC] deprecate JBrowser and use framework WebClient
avatar brianteeman brianteeman - edited - 8 Jun 2017
avatar pixelstunde
pixelstunde - comment - 13 Jul 2017

Looking at the current state of Joomla\Application\Web\WebClient I don't think deprecating JBrowser is a very good idea. You have to use some black magic like PHP to "stringify" the return values of WebClient which are integers only, where JBrowser returns some very convenient values like "unix", "mac", "chrome", "mozilla" etc.

avatar mbabker
mbabker - comment - 13 Jul 2017

You have to use some black magic like PHP to "stringify" the return values of WebClient which are integers only

It's not an issue unique to this class. Anything which uses constants to represent values can have this issue where the constant's value doesn't necessarily align to what the code is passing. WebClient::MAC will always be integer 7 (or if we took the B/C break and changed them to strings whatever string value it's assigned), but you can use the constant to read the value versus hardcoding a 7 into your code and having to leave inline comments about what it actually represents.

avatar pixelstunde
pixelstunde - comment - 14 Jul 2017

It's not an issue unique to this class. Anything which uses constants to represent values can have this issue where the constant's value doesn't necessarily align to what the code is passing.

I do understand that it might be better to prefer constants in terms of performance, I just wanted to point out that currently there seems to be missing a method for extension-developer friendly output. Deprecating JBrowser in favor of the current verison of WebClient would easily result in developers repeating themselves (instead of DRY in the core) or even worse: using third party libraries.

Another thing: if you add some functionality e.g. in detection of browsers this might result in problems even if there are hardcoded values always staying the same (until one day they won't :) ).
Lets say an update is adding constant 42 as return value for a fork of a browser. This would force every extension/template developer to review or rework their code.
Of course you could do something like: array_shift( (new ReflectionClass( 'JApplicationWebClient' ) ) ->getConstants() ); but I guess this would not perform very well.

avatar mbabker
mbabker - comment - 14 Jul 2017

Lets say an update is adding constant 42 as return value for a fork of a browser. This would force every extension/template developer to review or rework their code.

And it'd be the same if a new return value were added into JBrowser which uses "developer friendly" strings if your code was interested in a behavior for that browser. So I don't think that scenario strengthens or weakens the case for constants versus string values that aren't declared somewhere (as in right now you basically have to reverse engineer JBrowser to know what you can get from it, at least with a list of constants you have a set of known values).

avatar pixelstunde
pixelstunde - comment - 14 Jul 2017

as in right now you basically have to reverse engineer JBrowser to know what you can get from it, at least with a list of constants you have a set of known values

I totally agree with you. I was never saying JBrowser was a better class, but it's easier to handle since it provides human-readable results. I'd be totally satisfied if there was a built in ability to resolve the name of the constants in WebClient and I guess others would be too.

In my case I'm just logging values like browser, version and OS which is hard to read if you get constants only.

avatar mbabker
mbabker - comment - 14 Jul 2017

Honestly, I don't know if that's something that's practical in PHP since constants are just a code shortcut to a value (everything internally uses that constant's value, the constant's just there for readability). You can use Reflection and come up with methods to help make that work on a class basis, but global constants would never work that well with a resolver since many share the same value.

avatar mbabker
mbabker - comment - 29 Jul 2017

At this point, I'd suggest whichever of the two classes is in better shape is the one we should move forward with and the other one deprecated and dropped with next major. Internal design decisions aside (i.e. constant values), I'd rather focus on whichever one is more functionally up to par for the task at hand and we can address the shortcomings in that class and if necessary correct design issues.

avatar mbabker
mbabker - comment - 24 Jul 2018

Anyone?

avatar wilsonge
wilsonge - comment - 24 Jul 2018

I mean JBrowser covers more cases. The question is does WebClient cover the common cases - because most people care about desktop vs mobile etc. Not what the specific browser is....

avatar photodude
photodude - comment - 24 Jul 2018

I think they both cover the same small set of browsers (at least from what I remember from the minor code fixes I've done to both of them)

both cover desktop vs mobile

avatar photodude photodude - change - 25 Jul 2018
The description was changed
avatar photodude photodude - edited - 25 Jul 2018
avatar joomla-cms-bot joomla-cms-bot - change - 25 Jul 2018
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 25 Jul 2018
avatar photodude
photodude - comment - 25 Jul 2018

Here is a quick properties comparison between the two (I think I got everything in here)
Still need to do a function comparison to get the full picture

framework Joomla\Application\Web\WebClient Description JBrowser aka Joomla\CMS\Environment Description
$platform integer The detected platform on which the web client runs. $platform string Platform the browser is running on
$mobile boolean True if the web client is a mobile device. $mobile boolean Is this a mobile browser?
$engine integer The detected rendering engine used by the web client. - -
$browser integer The detected browser used by the web client. $browser string Browser name
- - $majorVersion integer Major version number
- - $minorVersion integer Minor version number
$browserVersion string The detected browser version used by the web client. - -
$languages array The priority order detected accepted languages for the client. - -
$encodings array The priority order detected accepted encodings for the client. - -
$userAgent string The web client's user agent string. $agent string Full user agent string.
- - $lowerAgent string Lower-case user agent string
- - $accept string HTTP_ACCEPT string
- - $acceptParsed array Parsed HTTP_ACCEPT string
$acceptEncoding string The web client's accepted encoding string. - -
$acceptLanguage string The web client's accepted languages string. - -
$detection array An array of flags determining whether or not a detection routine has been run. - -
$robot boolean True if the web client is a robot - -
- - $robots array Known robots.
$headers array An array of all headers sent by client - -
- - $images List of viewable image MIME subtypes. This list of viewable images works for IE and Netscape/Mozilla.
- - $instances array Browser instances container.
avatar photodude photodude - change - 30 Jul 2018
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2018-07-30 00:17:20
Closed_By photodude
avatar photodude photodude - close - 30 Jul 2018
avatar photodude
photodude - comment - 30 Jul 2018

Here is a quick function comparison between the two (I think I got everything in here)
As best I can tell there is feature parody between the two, a few functions here and there are not in the other class. but the big things like mobile detection are in both.

framework Joomla\Application\Web\WebClient Description JBrowser aka Joomla\CMS\Environment Description
__construct($userAgent = null, $acceptEncoding = null, $acceptLanguage = null) Class constructor __construct($userAgent = null, $accept = null) Create a browser instance (constructor)
__get($name) Magic method to get an object property's value by name getInstance($userAgent = null, $accept = null) Returns the global Browser object, only creating it if it doesn't already exist
detectBrowser($userAgent) Detects the client browser and version in a user agent string. getBrowser() Retrieve the current browser
- - setBrowser($browser) Sets the current browser
detectEncoding($acceptEncoding) Method to detect the accepted response encoding by the client - -
detectEngine($userAgent) Detects the client rendering engine in a user agent string. - -
detectLanguage($acceptLanguage) Method to detect the accepted languages by the client. - -
detectPlatform($userAgent) Detects the client platform in a user agent string getPlatform() Return the currently matched platform
- - _setPlatform() Match the platform of the browser.
detectRobot($userAgent) Determines if the browser is a robot or not isRobot() Determines if the browser is a robot or not
detectHeaders() Fills internal array of headers - -
- - match($userAgent = null, $accept = null) Parses the user agent string and inititializes the object with all the known features and quirks for the given browser.
- - identifyBrowserVersion() Set browser version, not by engine version Fallback to use when no other method identify the engine version
- - getMajor() Retrieve the current browser's major version
- - getMinor() Retrieve the current browser's minor version
- - getVersion() Retrieve the current browser's version
- - getAgentString() Return the full browser agent string
- - getHTTPProtocol() Returns the server protocol in use on the current server
- - isViewable($mimetype) Determines if a browser can display a given MIME type
- - isBrowser($browser) Determine if the given browser is the same as the current
- - isMobile() Determines if the browser is mobile version or not.
- - isSSLConnection() Determine if we are using a secure (SSL) connection
avatar photodude photodude - change - 30 Jul 2018
Status Closed New
Closed_Date 2018-07-30 00:17:20
Closed_By photodude
avatar photodude photodude - reopen - 30 Jul 2018
avatar photodude
photodude - comment - 30 Jul 2018

Sorry, I fat fingered the keyboard. I didn't intend to close this, thus it's been reopened.

avatar franz-wohlkoenig franz-wohlkoenig - change - 30 Jul 2018
Status New Discussion
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 30 Jul 2018

Status changed from "New" to "Discussion".


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/16528.

avatar franz-wohlkoenig franz-wohlkoenig - change - 4 Apr 2019
Labels Added: J3 Issue
avatar franz-wohlkoenig franz-wohlkoenig - labeled - 4 Apr 2019
avatar franz-wohlkoenig franz-wohlkoenig - change - 20 Apr 2019
Title
[RFC] deprecate JBrowser and use framework WebClient
deprecate JBrowser and use framework WebClient
avatar franz-wohlkoenig franz-wohlkoenig - edited - 20 Apr 2019
avatar brianteeman
brianteeman - comment - 23 Aug 2022

Thank you for raising this issue.

Joomla 3 is now in security only mode with no further bug fixes or new features. It appears that this has already been addressed in Joomla 4 and it will now been closed.

If we are mistaken and this does apply to Joomla 4 please open a new issue (and reference this one if you wish) with updated details for testing in Joomla 4.
cc @zero-24

avatar zero-24 zero-24 - change - 23 Aug 2022
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2022-08-23 13:48:12
Closed_By zero-24
Labels Added: ? No Code Attached Yet
Removed: ? ?
avatar zero-24 zero-24 - close - 23 Aug 2022
avatar joomla-cms-bot joomla-cms-bot - change - 23 Aug 2022
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - unlabeled - 23 Aug 2022

Add a Comment

Login with GitHub to post a comment