1# NAME
2
3HTTP::BrowserDetect - Determine Web browser, version, and platform from an HTTP user agent string
4
5# VERSION
6
7version 3.35
8
9# SYNOPSIS
10
11    use HTTP::BrowserDetect ();
12
13    my $user_agent_string
14        = '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';
15    my $ua = HTTP::BrowserDetect->new($user_agent_string);
16
17    # Print general information
18    print 'Browser: ' . $ua->browser_string . "\n" if $ua->browser_string;
19    print 'Version: ' . $ua->browser_version . $ua->browser_beta . "\n" if $ua->browser_version;
20    print 'OS: ' . $ua->os_string . "\n" if $ua->os_string;
21
22    # Detect operating system
23    if ( $ua->windows ) {
24        if ( $ua->winnt ) {
25            # do something
26        }
27        if ( $ua->win95 ) {
28            # do something
29        }
30    }
31    print "Mac\n" if $ua->macosx;
32
33    # Detect browser vendor and version
34    print "Safari\n" if $ua->safari;
35    print "MSIE\n" if $ua->ie;
36    print "Mobile\n" if $ua->mobile;
37    if ( $ua->browser_major(4) ) {
38        if ( $ua->browser_minor > .5 ) {
39            # ...;
40        }
41    }
42    if ( $ua->browser_version > 4.5 ) {
43        # ...;
44    }
45
46# DESCRIPTION
47
48The HTTP::BrowserDetect object does a number of tests on an HTTP user agent
49string. The results of these tests are available via methods of the object.
50
51For an online demonstration of this module's parsing, you can check out
52[http://www.browserdetect.org/](http://www.browserdetect.org/)
53
54This module was originally based upon the JavaScript browser detection
55code available at
56[http://www.mozilla.org/docs/web-developer/sniffer/browser\_type.html](http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html).
57
58# CONSTRUCTOR AND STARTUP
59
60## new()
61
62    HTTP::BrowserDetect->new( $user_agent_string )
63
64The constructor may be called with a user agent string specified. Otherwise, it
65will use the value specified by $ENV{'HTTP\_USER\_AGENT'}, which is set by the
66web server when calling a CGI script.
67
68# SUBROUTINES/METHODS
69
70# Browser Information
71
72## browser()
73
74Returns the browser, as one of the following values:
75
76chrome, firefox, ie, opera, safari, adm, applecoremedia, blackberry,
77brave, browsex, dalvik, elinks, links, lynx, emacs, epiphany, galeon,
78konqueror, icab, lotusnotes, mosaic, mozilla, netfront, netscape,
79n3ds, dsi, obigo, polaris, pubsub, realplayer, seamonkey, silk,
80staroffice, ucbrowser, webtv, samsung
81
82If the browser could not be identified (either because unrecognized
83or because it is a robot), returns `undef`.
84
85## browser\_string()
86
87Returns a human formatted version of the browser name. These names are
88subject to change and are meant for display purposes. This may include
89information additional to what's in browser() (e.g. distinguishing
90Firefox from Iceweasel).
91
92If the user agent could not be identified, or if it was identified as
93a robot instead, returns `undef`.
94
95# Browser Version
96
97Please note that that the version(), major() and minor() methods have been
98deprecated as of release 1.78 of this module. They should be replaced
99with browser\_version(), browser\_major(), browser\_minor(), and browser\_beta().
100
101The reasoning behind this is that version() method will, in the case of Safari,
102return the Safari/XXX numbers even when Version/XXX numbers are present in the
103UserAgent string (i.e. it will return incorrect versions for Safari in
104some cases).
105
106## browser\_version()
107
108Returns the browser version (major and minor) as a string. For
109example, for Chrome 36.0.1985.67, this returns "36.0".
110
111## browser\_major()
112
113Returns the major part of the version as a string. For example, for
114Chrome 36.0.1985.67, this returns "36".
115
116Returns undef if no version information can be detected.
117
118## browser\_minor()
119
120Returns the minor part of the version as a string. This includes the
121decimal point; for example, for Chrome 36.0.1985.67, this returns
122".0".
123
124Returns undef if no version information can be detected.
125
126## browser\_beta()
127
128Returns any part of the version after the major and minor version, as
129a string. For example, for Chrome 36.0.1985.67, this returns
130".1985.67". The beta part of the string can contain any type of
131alphanumeric characters.
132
133Returns undef if no version information can be detected. Returns an
134empty string if version information is detected but it contains only
135a major and minor version with nothing following.
136
137# Operating System
138
139## os()
140
141Returns one of the following strings, or `undef`:
142
143    windows, winphone, mac, macosx, linux, android, ios, os2, unix, vms,
144    chromeos, firefoxos, ps3, psp, rimtabletos, blackberry, amiga, brew
145
146## os\_string()
147
148Returns a human formatted version of the OS name.  These names are
149subject to change and are really meant for display purposes. This may
150include information additional to what's in os() (e.g. distinguishing
151various editions of Windows from one another) (although for a way to
152do that that's more suitable for use in program logic, see below under
153"OS related properties").
154
155Returns `undef` if no OS information could be detected.
156
157## os\_version(), os\_major(), os\_minor(), os\_beta()
158
159Returns version information for the OS, if any could be detected. The
160format is the same as for the browser\_version() functions.
161
162# Mobile Devices
163
164## mobile()
165
166Returns true if the browser appears to belong to a mobile phone or
167similar device (i.e. one small enough that the mobile version of a
168page is probably preferable over the desktop version).
169
170In previous versions, tablet devices sometimes had mobile() return
171true. They are now mutually exclusive.
172
173## tablet()
174
175Returns true if the browser appears to belong to a tablet device.
176
177## device()
178
179Returns the type of mobile / tablet hardware, if it can be detected.
180
181Currently returns one of: android, audrey, avantgo, blackberry, dsi, iopener, ipad,
182iphone, ipod, kindle, n3ds, palm, ps3, psp, wap, webos, winphone.
183
184Returns `undef` if this is not a tablet/mobile device or no hardware
185information can be detected.
186
187## device\_string()
188
189Returns a human formatted version of the hardware device name.  These names are
190subject to change and are really meant for display purposes.  You should use
191the device() method in your logic. This may include additional
192information (such as the model of phone if it is detectable).
193
194Returns `undef` if this is not a portable device or if no device name
195can be detected.
196
197# Robots
198
199## robot()
200
201If the user agent appears to be a robot, spider, crawler, or other
202automated Web client, this returns one of the following values:
203
204lwp, slurp, yahoo, bingbot, msnmobile, msn, msoffice, ahrefs,
205altavista, apache, askjeeves, baidu, curl, facebook, getright,
206googleadsbot, googleadsense, googlebotimage, googlebotnews,
207googlebotvideo, googlefavicon, googlemobile, google, golib, indy,
208infoseek, ipsagent, linkchecker, linkexchange, lycos, malware,
209mj12bot, nutch, phplib, puf, rubylib, scooter, specialarchiver,
210wget, yandexbot, yandeximages, java, headlesschrome, unknown
211
212Returns "unknown" when the user agent is believed to be a robot but
213is not identified as one of the above specific robots.
214
215Returns `undef` if the user agent is not a robot or cannot be
216identified.
217
218Note that if a robot crafts a user agent designed to impersonate a
219particular browser, we generally set properties appropriate to both
220the actual robot, and the browser it is impersonating. For example,
221googlebot-mobile pretends to be mobile safari so that it will get
222mobile versions of pages. In this case, browser() will return
223'safari', the properties will generally be set as if for Mobile
224Safari, the 'robot' property will be set, and robot() will return
225'googlemobile'.
226
227### lib()
228
229Returns true if the user agent appears to be an HTTP library or tool
230(e.g. LWP, curl, wget, java). Generally libraries are also classified
231as robots, although it is impossible to tell whether they are being
232operated by an automated system or a human.
233
234### robot\_string()
235
236Returns a human formatted version of the robot name. These names are
237subject to change and are meant for display purposes. This may include
238additional information (e.g. robots which return "unknown" from
239robot() generally can be identified in a human-readable fashion by
240reading robot\_string() ).
241
242### robot\_id()
243
244This method is currently in beta.
245
246Returns an id consisting of lower case letters, numbers and dashes.  This id
247will remain constant, so you can use it for matching against a particular
248robot.  The ids were introduced in version 3.14.  There may still be a few
249corrections to ids in subsequent releases.  Once this method becomes stable the
250ids will also be frozen.
251
252### all\_robot\_ids()
253
254This method returns an `ArrayRef` of all possible `robot_id` values.
255
256## robot\_version(), robot\_major(), robot\_minor(), robot\_beta()
257
258Returns version information for the robot, if any could be
259detected. The format is the same as for the browser\_version()
260functions.
261
262Note that if a robot crafts a user agent designed to impersonate a
263particular browser, we generally return results appropriate to both
264the actual robot, and the browser it is impersonating. For example,
265googlebot-mobile pretends to be mobile safari so that it will get
266mobile versions of pages. In this case, robot\_version() will return
267the version of googlebot-mobile, and browser\_version() will return the
268version of Safari that googlebot-mobile is impersonating.
269
270# Browser Properties
271
272Operating systems, devices, browser names, rendering engines, and
273true-or-false methods (e.g. "mobile" and "lib") are all browser
274properties. For example, calling browser\_properties() for Mobile
275Safari running on an Android will return this list:
276
277('android', 'device', 'mobile', 'mobile\_safari', 'safari', 'webkit')
278
279## browser\_properties()
280
281Returns all properties for this user agent, as a list. Note that
282because a large number of cases must be considered, this will take
283significantly more time than simply querying the particular methods
284you care about.
285
286A mostly complete list of properties follows (i.e. each of these
287methods is both a method you can call, and also a property that may
288be in the list returned by browser\_properties() ). In addition to this
289list, robot(), lib(), device(), mobile(), and tablet() are all
290browser properties.
291
292## OS related properties
293
294The following methods are available, each returning a true or false value.
295Some methods also test for the operating system version. The indentations
296below show the hierarchy of tests (for example, win2k is considered a type of
297winnt, which is a type of win32)
298
299### windows()
300
301    win16 win3x win31
302    win32
303        winme win95 win98
304        winnt
305            win2k winxp win2k3 winvista win7
306            win8
307                win8_0 win8_1
308            win10
309                win10_0
310    wince
311    winphone
312        winphone7 winphone7_5 winphone8 winphone10
313
314### dotnet()
315
316### x11()
317
318### webview()
319
320### chromeos()
321
322### firefoxos()
323
324### mac()
325
326mac68k macppc macosx ios
327
328### os2()
329
330### bb10()
331
332### rimtabletos()
333
334### unix()
335
336    sun sun4 sun5 suni86 irix irix5 irix6 hpux hpux9 hpux10
337    aix aix1 aix2 aix3 aix4 linux sco unixware mpras reliant
338    dec sinix freebsd bsd
339
340### vms()
341
342### amiga()
343
344### ps3gameos()
345
346### pspgameos()
347
348It may not be possible to detect Win98 in Netscape 4.x and earlier. On Opera
3493.0, the userAgent string includes "Windows 95/NT4" on all Win32, so you can't
350distinguish between Win95 and WinNT.
351
352## Browser related properties
353
354The following methods are available, each returning a true or false value.
355Some methods also test for the browser version, saving you from checking the
356version separately.
357
358### adm
359
360### aol aol3 aol4 aol5 aol6
361
362### applecoremedia
363
364### avantgo
365
366### browsex
367
368### chrome
369
370### dalvik
371
372### emacs
373
374### epiphany
375
376### firefox
377
378### galeon
379
380### icab
381
382### ie ie3 ie4 ie4up ie5 ie5up ie55 ie55up ie6 ie7 ie8 ie9 ie10 ie11
383
384### ie\_compat\_mode
385
386The ie\_compat\_mode is used to determine if the IE user agent is for
387the compatibility mode view, in which case the real version of IE is
388higher than that detected. The true version of IE can be inferred from
389the version of Trident in the engine\_version method.
390
391### konqueror
392
393### lotusnotes
394
395### lynx links elinks
396
397### mobile\_safari
398
399### mosaic
400
401### mozilla
402
403### neoplanet neoplanet2
404
405### netfront
406
407### netscape nav2 nav3 nav4 nav4up nav45 nav45up navgold nav6 nav6up
408
409### obigo
410
411### opera opera3 opera4 opera5 opera6 opera7
412
413### polaris
414
415### pubsub
416
417### realplayer
418
419The realplayer method above tests for the presence of either the RealPlayer
420plug-in "(r1 " or the browser "RealPlayer".
421
422### realplayer\_browser
423
424The realplayer\_browser method tests for the presence of the RealPlayer
425browser (but returns 0 for the plugin).
426
427### safari
428
429### samsung
430
431### seamonkey
432
433### silk
434
435### staroffice
436
437### ucbrowser
438
439### webtv
440
441Netscape 6, even though it's called six, in the User-Agent string has version
442number 5. The nav6 and nav6up methods correctly handle this quirk. The Firefox
443test correctly detects the older-named versions of the browser (Phoenix,
444Firebird).
445
446## Device related properties
447
448The following methods are available, each returning a true or false value.
449
450### android
451
452### audrey
453
454### avantgo
455
456### blackberry
457
458### dsi
459
460### iopener
461
462### iphone
463
464### ipod
465
466### ipad
467
468### kindle
469
470### kindlefire
471
472### n3ds
473
474### palm
475
476### webos
477
478### wap
479
480Note that 'wap' indicates that the device is capable of WAP, not
481necessarily that the device is limited to WAP only. Most modern WAP
482devices are also capable of rendering standard HTML.
483
484### psp
485
486### ps3
487
488## Robot properties
489
490These methods are now deprecated and will be removed in a future release.
491Please use the `robot()` and `robot_id()` methods to identify the bots.  Use
492`robot_id()` if you need to match on a string, since the value that is
493returned by `robot` could possibly change in a future release.
494
495The following additional methods are available, each returning a true or false
496value. This is by no means a complete list of robots that exist on the Web.
497
498### ahrefs
499
500### altavista
501
502### apache
503
504### askjeeves
505
506### baidu
507
508### bingbot
509
510### curl
511
512### facebook
513
514### getright
515
516### golib
517
518### google
519
520### googleadsbot
521
522### googleadsense
523
524### googlemobile
525
526### indy
527
528### infoseek
529
530### ipsagent
531
532### java
533
534### linkexchange
535
536### lwp
537
538### lycos
539
540### malware
541
542### mj12bot
543
544### msn
545
546### msoffice
547
548### puf
549
550### rubylib
551
552### slurp
553
554### wget
555
556### yahoo
557
558### yandex
559
560### yandeximages
561
562### headlesschrome
563
564## Engine properties
565
566The following properties indicate if a particular rendering engine is
567being used.
568
569### webkit
570
571### gecko
572
573### trident
574
575### presto
576
577### khtml
578
579# Other methods
580
581## user\_agent()
582
583Returns the value of the user agent string.
584
585Calling this method with a parameter to set the user agent has now
586been removed; please use HTTP::BrowserDetect->new() to pass the user
587agent string.
588
589## u2f()
590
591Returns true if this browser and version are known to support Universal Second
592Factor (U2F).  This method will need future updates as more browsers fully
593support this standard.
594
595## country()
596
597Returns the country string as it may be found in the user agent string. This
598will be in the form of an upper case 2 character code. ie: US, DE, etc
599
600## language()
601
602Returns the language string as it is found in the user agent string. This will
603be in the form of an upper case 2 character code. ie: EN, DE, etc
604
605## engine()
606
607Returns the rendering engine, one of the following:
608
609gecko, webkit, khtml, trident, ie, presto, netfront
610
611Note that this returns "webkit" for webkit based browsers (including
612Chrome/Blink). This is a change from previous versions of this
613library, which returned "KHTML" for webkit.
614
615Returns `undef` if none of the above rendering engines can be
616detected.
617
618## engine\_string()
619
620Returns a human formatted version of the rendering engine.
621
622Note that this returns "WebKit" for webkit based browsers (including
623Chrome/Blink). This is a change from previous versions of this
624library, which returned "KHTML" for webkit.
625
626Returns `undef` if none of the known rendering engines can be
627detected.
628
629## engine\_version(), engine\_major(), engine\_minor(), engine\_beta()
630
631Returns version information for the rendering engine, if any could be
632detected. The format is the same as for the browser\_version()
633functions.
634
635# Deprecated methods
636
637## device\_name()
638
639Deprecated alternate name for device\_string()
640
641## version()
642
643This is probably not what you want.  Please use either browser\_version() or
644engine\_version() instead.
645
646Returns the version (major and minor) as a string.
647
648This function returns wrong values for some Safari versions, for
649compatibility with earlier code. browser\_version() returns correct
650version numbers for Safari.
651
652## major()
653
654This is probably not what you want. Please use either browser\_major()
655or engine\_major() instead.
656
657Returns the integer portion of the browser version as a string.
658
659This function returns wrong values for some Safari versions, for
660compatibility with earlier code. browser\_version() returns correct
661version numbers for Safari.
662
663## minor()
664
665This is probably not what you want. Please use either browser\_minor()
666or engine\_minor() instead.
667
668Returns the decimal portion of the browser version as a string.
669
670This function returns wrong values for some Safari versions, for
671compatibility with earlier code. browser\_version() returns correct
672version numbers for Safari.
673
674## beta()
675
676This is probably not what you want. Please use browser\_beta() instead.
677
678Returns the beta version, consisting of any characters after the major
679and minor version number, as a string.
680
681This function returns wrong values for some Safari versions, for
682compatibility with earlier code. browser\_version() returns correct
683version numbers for Safari.
684
685## public\_version(), public\_major(), public\_minor(), public\_beta()
686
687Deprecated.  Please use browser\_version() and related functions
688instead.
689
690## gecko\_version()
691
692If a Gecko rendering engine is used (as in Mozilla or Firefox), returns the
693engine version. If no Gecko browser is being used, or the version
694number can't be detected, returns undef.
695
696This is an old function, preserved for compatibility; please use
697engine\_version() in new code.
698
699# CREDITS
700
701Lee Semel, lee@semel.net (Original Author)
702
703Peter Walsham (co-maintainer)
704
705Olaf Alders, `olaf at wundercounter.com` (co-maintainer)
706
707# ACKNOWLEDGEMENTS
708
709Thanks to the following for their contributions:
710
711cho45
712
713Leonardo Herrera
714
715Denis F. Latypoff
716
717merlynkline
718
719Simon Waters
720
721Toni Cebrin
722
723Florian Merges
724
725david.hilton.p
726
727Steve Purkis
728
729Andrew McGregor
730
731Robin Smidsrod
732
733Richard Noble
734
735Josh Ritter
736
737Mike Clarke
738
739Marc Sebastian Pelzer
740
741Alexey Surikov
742
743Maros Kollar
744
745Jay Rifkin
746
747Luke Saunders
748
749Jacob Rask
750
751Heiko Weber
752
753Jon Jensen
754
755Jesse Thompson
756
757Graham Barr
758
759Enrico Sorcinelli
760
761Olivier Bilodeau
762
763Yoshiki Kurihara
764
765Paul Findlay
766
767Uwe Voelker
768
769Douglas Christopher Wilson
770
771John Oatis
772
773Atsushi Kato
774
775Ronald J. Kimball
776
777Bill Rhodes
778
779Thom Blake
780
781Aran Deltac
782
783yeahoffline
784
785David Ihnen
786
787Hao Wu
788
789Perlover
790
791Daniel Stadie
792
793ben hengst
794
795Andrew Moise
796
797Atsushi Kato
798
799Marco Fontani
800
801Nicolas Doye
802
803# TO DO
804
805POD coverage is not 100%.
806
807# SEE ALSO
808
809"Browser ID (User-Agent) Strings", [http://www.zytrax.com/tech/web/browser\_ids.htm](http://www.zytrax.com/tech/web/browser_ids.htm)
810
811[HTML::ParseBrowser](https://metacpan.org/pod/HTML%3A%3AParseBrowser).
812
813# SUPPORT
814
815You can find documentation for this module with the perldoc command.
816
817    perldoc HTTP::BrowserDetect
818
819You can also look for information at:
820
821- GitHub Source Repository
822
823    [http://github.com/oalders/http-browserdetect](http://github.com/oalders/http-browserdetect)
824
825- Reporting Issues
826
827    [https://github.com/oalders/http-browserdetect/issues](https://github.com/oalders/http-browserdetect/issues)
828
829- Search CPAN
830
831    [https://metacpan.org/module/HTTP::BrowserDetect](https://metacpan.org/module/HTTP::BrowserDetect)
832
833# CONTRIBUTING
834
835Patches are certainly welcome, with many thanks for the excellent contributions
836which have already been received. The preferred method of patching would be to
837fork the GitHub repo and then send a pull request.
838
839Please include a test case as this will speed up the time to release your
840changes. Just edit t/useragents.json so that the test coverage includes any
841changes you have made. Please open a GitHub issue if you have any questions.
842
843# AUTHORS
844
845- Lee Semel <lee@semel.net>
846- Peter Walsham
847- Olaf Alders <olaf@wundercounter.com> (current maintainer)
848
849# COPYRIGHT AND LICENSE
850
851This software is copyright (c) 1999 by Lee Semel.
852
853This is free software; you can redistribute it and/or modify it under
854the same terms as the Perl 5 programming language system itself.
855