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.21
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"
21               if $ua->browser_string;
22           print "Version: $ua->browser_version$ua->browser_beta\n"
23               if $ua->browser_version;
24           print "OS: $ua->os_string\n"
25               if $ua->os_string;
26
27           # Detect operating system
28           if ( $ua->windows ) {
29               if ( $ua->winnt ) {
30                   # do something
31               }
32               if ( $ua->win95 ) {
33                   # do something
34               }
35           }
36           print "Mac\n" if $ua->macosx;
37
38           # Detect browser vendor and version
39           print "Safari\n" if $ua->safari;
40           print "MSIE\n" if $ua->ie;
41           print "Mobile\n" if $ua->mobile;
42           if ( $ua->browser_major(4) ) {
43               if ( $ua->browser_minor() > .5 ) {
44                   # ...;
45               }
46           }
47           if ( $ua->browser_version() > 4.5 ) {
48               # ...;
49           }
50

DESCRIPTION

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

CONSTRUCTOR AND STARTUP

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

SUBROUTINES/METHODS

Browser Information

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

Browser Version

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

Operating System

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

Mobile Devices

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

Robots

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

Browser Properties

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

Other methods

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

Deprecated methods

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

CREDITS

653       Lee Semel, lee@semel.net (Original Author)
654
655       Peter Walsham (co-maintainer)
656
657       Olaf Alders, "olaf at wundercounter.com" (co-maintainer)
658

ACKNOWLEDGEMENTS

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

TO DO

755       POD coverage is not 100%.
756

SEE ALSO

758       "Browser ID (User-Agent) Strings",
759       <http://www.zytrax.com/tech/web/browser_ids.htm>
760
761       HTML::ParseBrowser.
762
763

SUPPORT

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

BUGS AND LIMITATIONS

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

CONTRIBUTING

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

AUTHORS

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