Since starting the Session Inspector module I have been busy adding features to improve how the module functions.
One of these additions is the module now being able to retrieve and store the browser that the user is current using to access the session (also known as user agent string). This just uses a hook_user_login() hook and stores the browser using the standard session storage system built into Drupal. This browser string is then pulled out of the session metadata and presented to the user in the session inspector interface.
Whilst this provides the user with more information, the one big downside is that when accessing the session inspector page the user sees a browser string that looks something like this.
Mozilla/5.0 (Macintosh; Intel Mac OS X 12_2_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36
For most of users this really isn’t helpful or useful in any way. This is from me visiting a testing site using Safari, but I can also see references to Chrome and Mozilla, including a reference to the type of computer I’m using.
After seeing this I decided to implement a feature I talked about in my last article where I said that plugins could be used to allow the formatting of browser strings without developers needing to create custom themes or alter any code. As it turns out there are lots of packages that can process browser strings into something useful for the user. What I didn’t want to do is hard code one of these packages into the module since that ties the module to be a dependency of the package. To my mind, separate modules containing plugins for different formatting options makes sense and allows for changes in the future if another package is needed.