1HTTP::BrowserDetect(3)User Contributed Perl DocumentationHTTP::BrowserDetect(3)
2
3
4

NAME

6       HTTP::BrowserDetect - Determine Web browser, version, and platform from
7       an HTTP user agent string
8

VERSION

10       version 3.34
11

SYNOPSIS

13           use HTTP::BrowserDetect ();
14
15           my $user_agent_string
16               = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36';
17           my $ua = HTTP::BrowserDetect->new($user_agent_string);
18
19           # Print general information
20           print 'Browser: ' . $ua->browser_string . "\n" if $ua->browser_string;
21           print 'Version: ' . $ua->browser_version . $ua->browser_beta . "\n" if $ua->browser_version;
22           print 'OS: ' . $ua->os_string . "\n" if $ua->os_string;
23
24           # Detect operating system
25           if ( $ua->windows ) {
26               if ( $ua->winnt ) {
27                   # do something
28               }
29               if ( $ua->win95 ) {
30                   # do something
31               }
32           }
33           print "Mac\n" if $ua->macosx;
34
35           # Detect browser vendor and version
36           print "Safari\n" if $ua->safari;
37           print "MSIE\n" if $ua->ie;
38           print "Mobile\n" if $ua->mobile;
39           if ( $ua->browser_major(4) ) {
40               if ( $ua->browser_minor > .5 ) {
41                   # ...;
42               }
43           }
44           if ( $ua->browser_version > 4.5 ) {
45               # ...;
46           }
47

DESCRIPTION

49       The HTTP::BrowserDetect object does a number of tests on an HTTP user
50       agent string. The results of these tests are available via methods of
51       the object.
52
53       For an online demonstration of this module's parsing, you can check out
54       <http://www.browserdetect.org/>
55
56       This module was originally based upon the JavaScript browser detection
57       code available at
58       <http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html>.
59

CONSTRUCTOR AND STARTUP

61   new()
62           HTTP::BrowserDetect->new( $user_agent_string )
63
64       The constructor may be called with a user agent string specified.
65       Otherwise, it will use the value specified by $ENV{'HTTP_USER_AGENT'},
66       which is set by the web server when calling a CGI script.
67

SUBROUTINES/METHODS

Browser Information

70   browser()
71       Returns the browser, as one of the following values:
72
73       chrome, firefox, ie, opera, safari, adm, applecoremedia, blackberry,
74       brave, browsex, dalvik, elinks, links, lynx, emacs, epiphany, galeon,
75       konqueror, icab, lotusnotes, mosaic, mozilla, netfront, netscape, n3ds,
76       dsi, obigo, polaris, pubsub, realplayer, seamonkey, silk, staroffice,
77       ucbrowser, webtv
78
79       If the browser could not be identified (either because unrecognized or
80       because it is a robot), returns "undef".
81
82   browser_string()
83       Returns a human formatted version of the browser name. These names are
84       subject to change and are meant for display purposes. This may include
85       information additional to what's in browser() (e.g. distinguishing
86       Firefox from Iceweasel).
87
88       If the user agent could not be identified, or if it was identified as a
89       robot instead, returns "undef".
90

Browser Version

92       Please note that that the version(), major() and minor() methods have
93       been deprecated as of release 1.78 of this module. They should be
94       replaced with browser_version(), browser_major(), browser_minor(), and
95       browser_beta().
96
97       The reasoning behind this is that version() method will, in the case of
98       Safari, return the Safari/XXX numbers even when Version/XXX numbers are
99       present in the UserAgent string (i.e. it will return incorrect versions
100       for Safari in some cases).
101
102   browser_version()
103       Returns the browser version (major and minor) as a string. For example,
104       for Chrome 36.0.1985.67, this returns "36.0".
105
106   browser_major()
107       Returns the major part of the version as a string. For example, for
108       Chrome 36.0.1985.67, this returns "36".
109
110       Returns undef if no version information can be detected.
111
112   browser_minor()
113       Returns the minor part of the version as a string. This includes the
114       decimal point; for example, for Chrome 36.0.1985.67, this returns ".0".
115
116       Returns undef if no version information can be detected.
117
118   browser_beta()
119       Returns any part of the version after the major and minor version, as a
120       string. For example, for Chrome 36.0.1985.67, this returns ".1985.67".
121       The beta part of the string can contain any type of alphanumeric
122       characters.
123
124       Returns undef if no version information can be detected. Returns an
125       empty string if version information is detected but it contains only a
126       major and minor version with nothing following.
127

Operating System

129   os()
130       Returns one of the following strings, or "undef":
131
132         windows, winphone, mac, macosx, linux, android, ios, os2, unix, vms,
133         chromeos, firefoxos, ps3, psp, rimtabletos, blackberry, amiga, brew
134
135   os_string()
136       Returns a human formatted version of the OS name.  These names are
137       subject to change and are really meant for display purposes. This may
138       include information additional to what's in os() (e.g. distinguishing
139       various editions of Windows from one another) (although for a way to do
140       that that's more suitable for use in program logic, see below under "OS
141       related properties").
142
143       Returns "undef" if no OS information could be detected.
144
145   os_version(), os_major(), os_minor(), os_beta()
146       Returns version information for the OS, if any could be detected. The
147       format is the same as for the browser_version() functions.
148

Mobile Devices

150   mobile()
151       Returns true if the browser appears to belong to a mobile phone or
152       similar device (i.e. one small enough that the mobile version of a page
153       is probably preferable over the desktop version).
154
155       In previous versions, tablet devices sometimes had mobile() return
156       true. They are now mutually exclusive.
157
158   tablet()
159       Returns true if the browser appears to belong to a tablet device.
160
161   device()
162       Returns the type of mobile / tablet hardware, if it can be detected.
163
164       Currently returns one of: android, audrey, avantgo, blackberry, dsi,
165       iopener, ipad, iphone, ipod, kindle, n3ds, palm, ps3, psp, wap, webos,
166       winphone.
167
168       Returns "undef" if this is not a tablet/mobile device or no hardware
169       information can be detected.
170
171   device_string()
172       Returns a human formatted version of the hardware device name.  These
173       names are subject to change and are really meant for display purposes.
174       You should use the device() method in your logic. This may include
175       additional information (such as the model of phone if it is
176       detectable).
177
178       Returns "undef" if this is not a portable device or if no device name
179       can be detected.
180

Robots

182   robot()
183       If the user agent appears to be a robot, spider, crawler, or other
184       automated Web client, this returns one of the following values:
185
186       lwp, slurp, yahoo, bingbot, msnmobile, msn, msoffice, ahrefs,
187       altavista, apache, askjeeves, baidu, curl, facebook, getright,
188       googleadsbot, googleadsense, googlebotimage, googlebotnews,
189       googlebotvideo, googlefavicon, googlemobile, google, golib, indy,
190       infoseek, ipsagent, linkchecker, linkexchange, lycos, malware, mj12bot,
191       nutch, phplib, puf, rubylib, scooter, specialarchiver, wget, yandexbot,
192       yandeximages, java, headlesschrome, unknown
193
194       Returns "unknown" when the user agent is believed to be a robot but is
195       not identified as one of the above specific robots.
196
197       Returns "undef" if the user agent is not a robot or cannot be
198       identified.
199
200       Note that if a robot crafts a user agent designed to impersonate a
201       particular browser, we generally set properties appropriate to both the
202       actual robot, and the browser it is impersonating. For example,
203       googlebot-mobile pretends to be mobile safari so that it will get
204       mobile versions of pages. In this case, browser() will return 'safari',
205       the properties will generally be set as if for Mobile Safari, the
206       'robot' property will be set, and robot() will return 'googlemobile'.
207
208       lib()
209
210       Returns true if the user agent appears to be an HTTP library or tool
211       (e.g. LWP, curl, wget, java). Generally libraries are also classified
212       as robots, although it is impossible to tell whether they are being
213       operated by an automated system or a human.
214
215       robot_string()
216
217       Returns a human formatted version of the robot name. These names are
218       subject to change and are meant for display purposes. This may include
219       additional information (e.g. robots which return "unknown" from robot()
220       generally can be identified in a human-readable fashion by reading
221       robot_string() ).
222
223       robot_id()
224
225       This method is currently in beta.
226
227       Returns an id consisting of lower case letters, numbers and dashes.
228       This id will remain constant, so you can use it for matching against a
229       particular robot.  The ids were introduced in version 3.14.  There may
230       still be a few corrections to ids in subsequent releases.  Once this
231       method becomes stable the ids will also be frozen.
232
233       all_robot_ids()
234
235       This method returns an "ArrayRef" of all possible "robot_id" values.
236
237   robot_version(), robot_major(), robot_minor(), robot_beta()
238       Returns version information for the robot, if any could be detected.
239       The format is the same as for the browser_version() functions.
240
241       Note that if a robot crafts a user agent designed to impersonate a
242       particular browser, we generally return results appropriate to both the
243       actual robot, and the browser it is impersonating. For example,
244       googlebot-mobile pretends to be mobile safari so that it will get
245       mobile versions of pages. In this case, robot_version() will return the
246       version of googlebot-mobile, and browser_version() will return the
247       version of Safari that googlebot-mobile is impersonating.
248

Browser Properties

250       Operating systems, devices, browser names, rendering engines, and true-
251       or-false methods (e.g. "mobile" and "lib") are all browser properties.
252       For example, calling browser_properties() for Mobile Safari running on
253       an Android will return this list:
254
255       ('android', 'device', 'mobile', 'mobile_safari', 'safari', 'webkit')
256
257   browser_properties()
258       Returns all properties for this user agent, as a list. Note that
259       because a large number of cases must be considered, this will take
260       significantly more time than simply querying the particular methods you
261       care about.
262
263       A mostly complete list of properties follows (i.e. each of these
264       methods is both a method you can call, and also a property that may be
265       in the list returned by browser_properties() ). In addition to this
266       list, robot(), lib(), device(), mobile(), and tablet() are all browser
267       properties.
268
269   OS related properties
270       The following methods are available, each returning a true or false
271       value.  Some methods also test for the operating system version. The
272       indentations below show the hierarchy of tests (for example, win2k is
273       considered a type of winnt, which is a type of win32)
274
275       windows()
276
277           win16 win3x win31
278           win32
279               winme win95 win98
280               winnt
281                   win2k winxp win2k3 winvista win7
282                   win8
283                       win8_0 win8_1
284                   win10
285                       win10_0
286           wince
287           winphone
288               winphone7 winphone7_5 winphone8 winphone10
289
290       dotnet()
291
292       x11()
293
294       webview()
295
296       chromeos()
297
298       firefoxos()
299
300       mac()
301
302       mac68k macppc macosx ios
303
304       os2()
305
306       bb10()
307
308       rimtabletos()
309
310       unix()
311
312         sun sun4 sun5 suni86 irix irix5 irix6 hpux hpux9 hpux10
313         aix aix1 aix2 aix3 aix4 linux sco unixware mpras reliant
314         dec sinix freebsd bsd
315
316       vms()
317
318       amiga()
319
320       ps3gameos()
321
322       pspgameos()
323
324       It may not be possible to detect Win98 in Netscape 4.x and earlier. On
325       Opera 3.0, the userAgent string includes "Windows 95/NT4" on all Win32,
326       so you can't distinguish between Win95 and WinNT.
327
328   Browser related properties
329       The following methods are available, each returning a true or false
330       value.  Some methods also test for the browser version, saving you from
331       checking the version separately.
332
333       adm
334
335       aol aol3 aol4 aol5 aol6
336
337       applecoremedia
338
339       avantgo
340
341       browsex
342
343       chrome
344
345       dalvik
346
347       emacs
348
349       epiphany
350
351       firefox
352
353       galeon
354
355       icab
356
357       ie ie3 ie4 ie4up ie5 ie5up ie55 ie55up ie6 ie7 ie8 ie9 ie10 ie11
358
359       ie_compat_mode
360
361       The ie_compat_mode is used to determine if the IE user agent is for the
362       compatibility mode view, in which case the real version of IE is higher
363       than that detected. The true version of IE can be inferred from the
364       version of Trident in the engine_version method.
365
366       konqueror
367
368       lotusnotes
369
370       lynx links elinks
371
372       mobile_safari
373
374       mosaic
375
376       mozilla
377
378       neoplanet neoplanet2
379
380       netfront
381
382       netscape nav2 nav3 nav4 nav4up nav45 nav45up navgold nav6 nav6up
383
384       obigo
385
386       opera opera3 opera4 opera5 opera6 opera7
387
388       polaris
389
390       pubsub
391
392       realplayer
393
394       The realplayer method above tests for the presence of either the
395       RealPlayer plug-in "(r1 " or the browser "RealPlayer".
396
397       realplayer_browser
398
399       The realplayer_browser method tests for the presence of the RealPlayer
400       browser (but returns 0 for the plugin).
401
402       safari
403
404       seamonkey
405
406       silk
407
408       staroffice
409
410       ucbrowser
411
412       webtv
413
414       Netscape 6, even though it's called six, in the User-Agent string has
415       version number 5. The nav6 and nav6up methods correctly handle this
416       quirk. The Firefox test correctly detects the older-named versions of
417       the browser (Phoenix, Firebird).
418
419   Device related properties
420       The following methods are available, each returning a true or false
421       value.
422
423       android
424
425       audrey
426
427       avantgo
428
429       blackberry
430
431       dsi
432
433       iopener
434
435       iphone
436
437       ipod
438
439       ipad
440
441       kindle
442
443       kindlefire
444
445       n3ds
446
447       palm
448
449       webos
450
451       wap
452
453       Note that 'wap' indicates that the device is capable of WAP, not
454       necessarily that the device is limited to WAP only. Most modern WAP
455       devices are also capable of rendering standard HTML.
456
457       psp
458
459       ps3
460
461   Robot properties
462       These methods are now deprecated and will be removed in a future
463       release.  Please use the "robot()" and "robot_id()" methods to identify
464       the bots.  Use "robot_id()" if you need to match on a string, since the
465       value that is returned by "robot" could possibly change in a future
466       release.
467
468       The following additional methods are available, each returning a true
469       or false value. This is by no means a complete list of robots that
470       exist on the Web.
471
472       ahrefs
473
474       altavista
475
476       apache
477
478       askjeeves
479
480       baidu
481
482       bingbot
483
484       curl
485
486       facebook
487
488       getright
489
490       golib
491
492       google
493
494       googleadsbot
495
496       googleadsense
497
498       googlemobile
499
500       indy
501
502       infoseek
503
504       ipsagent
505
506       java
507
508       linkexchange
509
510       lwp
511
512       lycos
513
514       malware
515
516       mj12bot
517
518       msn
519
520       msoffice
521
522       puf
523
524       rubylib
525
526       slurp
527
528       wget
529
530       yahoo
531
532       yandex
533
534       yandeximages
535
536       headlesschrome
537
538   Engine properties
539       The following properties indicate if a particular rendering engine is
540       being used.
541
542       webkit
543
544       gecko
545
546       trident
547
548       presto
549
550       khtml
551

Other methods

553   user_agent()
554       Returns the value of the user agent string.
555
556       Calling this method with a parameter to set the user agent has now been
557       removed; please use HTTP::BrowserDetect->new() to pass the user agent
558       string.
559
560   u2f()
561       Returns true if this browser and version are known to support Universal
562       Second Factor (U2F).  This method will need future updates as more
563       browsers fully support this standard.
564
565   country()
566       Returns the country string as it may be found in the user agent string.
567       This will be in the form of an upper case 2 character code. ie: US, DE,
568       etc
569
570   language()
571       Returns the language string as it is found in the user agent string.
572       This will be in the form of an upper case 2 character code. ie: EN, DE,
573       etc
574
575   engine()
576       Returns the rendering engine, one of the following:
577
578       gecko, webkit, khtml, trident, ie, presto, netfront
579
580       Note that this returns "webkit" for webkit based browsers (including
581       Chrome/Blink). This is a change from previous versions of this library,
582       which returned "KHTML" for webkit.
583
584       Returns "undef" if none of the above rendering engines can be detected.
585
586   engine_string()
587       Returns a human formatted version of the rendering engine.
588
589       Note that this returns "WebKit" for webkit based browsers (including
590       Chrome/Blink). This is a change from previous versions of this library,
591       which returned "KHTML" for webkit.
592
593       Returns "undef" if none of the known rendering engines can be detected.
594
595   engine_version(), engine_major(), engine_minor(), engine_beta()
596       Returns version information for the rendering engine, if any could be
597       detected. The format is the same as for the browser_version()
598       functions.
599

Deprecated methods

601   device_name()
602       Deprecated alternate name for device_string()
603
604   version()
605       This is probably not what you want.  Please use either
606       browser_version() or engine_version() instead.
607
608       Returns the version (major and minor) as a string.
609
610       This function returns wrong values for some Safari versions, for
611       compatibility with earlier code. browser_version() returns correct
612       version numbers for Safari.
613
614   major()
615       This is probably not what you want. Please use either browser_major()
616       or engine_major() instead.
617
618       Returns the integer portion of the browser version as a string.
619
620       This function returns wrong values for some Safari versions, for
621       compatibility with earlier code. browser_version() returns correct
622       version numbers for Safari.
623
624   minor()
625       This is probably not what you want. Please use either browser_minor()
626       or engine_minor() instead.
627
628       Returns the decimal portion of the browser version as a string.
629
630       This function returns wrong values for some Safari versions, for
631       compatibility with earlier code. browser_version() returns correct
632       version numbers for Safari.
633
634   beta()
635       This is probably not what you want. Please use browser_beta() instead.
636
637       Returns the beta version, consisting of any characters after the major
638       and minor version number, as a string.
639
640       This function returns wrong values for some Safari versions, for
641       compatibility with earlier code. browser_version() returns correct
642       version numbers for Safari.
643
644   public_version(), public_major(), public_minor(), public_beta()
645       Deprecated.  Please use browser_version() and related functions
646       instead.
647
648   gecko_version()
649       If a Gecko rendering engine is used (as in Mozilla or Firefox), returns
650       the engine version. If no Gecko browser is being used, or the version
651       number can't be detected, returns undef.
652
653       This is an old function, preserved for compatibility; please use
654       engine_version() in new code.
655

CREDITS

657       Lee Semel, lee@semel.net (Original Author)
658
659       Peter Walsham (co-maintainer)
660
661       Olaf Alders, "olaf at wundercounter.com" (co-maintainer)
662

ACKNOWLEDGEMENTS

664       Thanks to the following for their contributions:
665
666       cho45
667
668       Leonardo Herrera
669
670       Denis F. Latypoff
671
672       merlynkline
673
674       Simon Waters
675
676       Toni Cebrin
677
678       Florian Merges
679
680       david.hilton.p
681
682       Steve Purkis
683
684       Andrew McGregor
685
686       Robin Smidsrod
687
688       Richard Noble
689
690       Josh Ritter
691
692       Mike Clarke
693
694       Marc Sebastian Pelzer
695
696       Alexey Surikov
697
698       Maros Kollar
699
700       Jay Rifkin
701
702       Luke Saunders
703
704       Jacob Rask
705
706       Heiko Weber
707
708       Jon Jensen
709
710       Jesse Thompson
711
712       Graham Barr
713
714       Enrico Sorcinelli
715
716       Olivier Bilodeau
717
718       Yoshiki Kurihara
719
720       Paul Findlay
721
722       Uwe Voelker
723
724       Douglas Christopher Wilson
725
726       John Oatis
727
728       Atsushi Kato
729
730       Ronald J. Kimball
731
732       Bill Rhodes
733
734       Thom Blake
735
736       Aran Deltac
737
738       yeahoffline
739
740       David Ihnen
741
742       Hao Wu
743
744       Perlover
745
746       Daniel Stadie
747
748       ben hengst
749
750       Andrew Moise
751
752       Atsushi Kato
753
754       Marco Fontani
755
756       Nicolas Doye
757

TO DO

759       POD coverage is not 100%.
760

SEE ALSO

762       "Browser ID (User-Agent) Strings",
763       <http://www.zytrax.com/tech/web/browser_ids.htm>
764
765       HTML::ParseBrowser.
766

SUPPORT

768       You can find documentation for this module with the perldoc command.
769
770           perldoc HTTP::BrowserDetect
771
772       You can also look for information at:
773
774       •   GitHub Source Repository
775
776           <http://github.com/oalders/http-browserdetect>
777
778       •   Reporting Issues
779
780           <https://github.com/oalders/http-browserdetect/issues>
781
782       •   CPAN Ratings
783
784           <http://cpanratings.perl.org/d/HTTP-BrowserDetect>
785
786       •   Search CPAN
787
788           <https://metacpan.org/module/HTTP::BrowserDetect>
789

BUGS AND LIMITATIONS

791       The biggest limitation at this point is the test suite, which really
792       needs to have many more UserAgent strings to test against.
793

CONTRIBUTING

795       Patches are certainly welcome, with many thanks for the excellent
796       contributions which have already been received. The preferred method of
797       patching would be to fork the GitHub repo and then send me a pull
798       request, but plain old patch files are also welcome.
799
800       If you're able to add test cases, this will speed up the time to
801       release your changes. Just edit t/useragents.json so that the test
802       coverage includes any changes you have made. Please contact me if you
803       have any questions.
804
805       This distribution uses Dist::Zilla. If you're not familiar with this
806       module, please see
807       <https://github.com/oalders/http-browserdetect/issues/5> for some
808       helpful tips to get you started.
809

AUTHORS

811       •   Lee Semel <lee@semel.net>
812
813       •   Peter Walsham
814
815       •   Olaf Alders <olaf@wundercounter.com> (current maintainer)
816
818       This software is copyright (c) 1999 by Lee Semel.
819
820       This is free software; you can redistribute it and/or modify it under
821       the same terms as the Perl 5 programming language system itself.
822
823
824
825perl v5.34.0                      2021-08-08            HTTP::BrowserDetect(3)
Impressum