Opera's User Agent String

Detecting Opera

Question: as a Web developer, how do I detect Opera?

Answer: We strongly advise against using browser sniffing in Web pages and applications to detect feature support or work around bugs. It is more manageable and effective to use capability detection. As discussed in the linked article, browser sniffing by name rather than capability usually leads to limited scripts that cannot withstand a browser upgrade. This in turn can lead to major problems with cross-browser compatibility.

This article is aimed at the developer who already employs capability detection who nevertheless wishes to identify Opera. Situations in which this might occur would be to circumvent a bug, for example, or to insure proper counting of Opera in Web site statistics.

In some cases it is possible to detect if the bug has occurred using capability detection, and then apply a workaround. This is much more reliable than detecting specific versions, and is the preferred approach. Please report such bugs to Operas bug tracking system.

The user agent string

Opera Desktop

The generic user agent string for Opera on desktop is given below:

Opera/9.80 ($OS; U; $LANGUAGE) Presto/$PRESTO_VERSION Version/$VERSION

where VERSION is the version of Opera, OS is the operating system, LANGUAGE is the language, and PRESTO_VERSION is the version of the rendering engine. Opera/9.80 is hard coded at the beginning of the user agent string because of broken browser sniffing scripts which detect Opera/10 and above as Opera 1. This highlights the aforementioned dangers with browser sniffing.

Examples of the Opera user agent string for version 10.10 on Windows Vista and Mac OS X are given below, with English as the language:

  • Opera/9.80 (Windows NT 6.0; U; en) Presto/2.2.15 Version/10.10
  • Opera/9.80 (Macintosh; Intel Mac OS X; U; en) Presto/2.2.15 Version/10.10

Prior to Opera 10, Opera's user agent string used the true version number at the start of the string, such as the following example user agent strings for Opera 9.63 on Windows Vista and Mac OS X:

  • Opera/9.63 (Windows NT 6.0; U; en) Presto/2.1.1
  • Opera/9.63 (Macintosh; Intel Mac OS X; U; en) Presto/2.1.1

The Opera browser identifies as Opera by default, but because Opera may be configured to spoof as Internet Explorer or Firefox, some sites and statistics mistakenly count Opera as MSIE or Mozilla. To identify Opera, look for "Opera" in the user agent string. Examples of Opera spoofing the user agent string are given below:

  • Mozilla/5.0 ($OS; U; $LANGUAGE; rv:1.8.1) Gecko/20061208 Firefox/2.0.0 Opera $VERSION
  • Mozilla/4.0 (compatible; MSIE 6.0; $OS; $LANGUAGE) Opera $VERSION

where VERSION is the version of Opera, OS is the operating system.

OS Description
X11; FreeBSD 6.2-RELEASE i386 FreeBSD, Intel processor
X11; Linux i686 Linux, Intel processor
Macintosh; Intel Mac OS X Mac OS X, Intel processor
Macintosh; PPC Mac OS X Mac OS X, PPC processor
Windows NT 5.1 Windows XP
Windows NT 6.0 Windows Vista
Windows NT 6.1 Windows 7

and the LANGUAGE variable takes any of the values offered by RFC 2616.

Unless specifically detecting Opera Desktop due to a desktop-only bug, or for statistical reasons, it is recommended to detect the Presto version number. This will be the same for all browsers with the same version of the rendering engine. Common versions of the rendering engine will most likely have the same features and bugs with limited exceptions due to device limitations or profiles.

Opera Mobile

The generic user agent string for Opera Mobile is as follows:

Opera/9.80 ($OS; Opera Mobi/$BUILD_NUMBER; U; $LANGUAGE) Presto/$PRESTO_VERSION Version/$VERSION

This follows the same scheme as the desktop version, but includes Opera Mobi and the build number before the U token. Opera Mobi was chosen as Mobile triggers content adaptation scripts to detect Opera Mobile as a WAP browser.

Examples of the Opera Mobile user agent string for version 10 on Windows Mobile and Symbian S60 are given below, with English as the language:

  • Opera/9.80 (Windows Mobile; WCE; Opera Mobi/WMD-50255; U; en) Presto/2.4.13 Version/10.00
  • Opera/9.80 (S60; SymbOS; Opera Mobi/275; U; en) Presto/2.4.13 Version/10.00

The values for the OS token in Opera Mobile are as follows:

OS Description
Windows Mobile; WCE Windows Mobile, Windows CE
S60; SymbOS Symbian OS, S60

The build number for the same version of Opera Mobile is independent for each platform, just as in Opera Desktop.

Opera Mobile can be detected independently of Opera Desktop and Opera Mini by detecting Opera Mobi in the user agent string. This is present in all modern versions of Opera Mobile, unless it is removed by the device manufacturer or mobile operator. Removing Opera Mobi from the user agent string is strongly discouraged by Opera. As with Opera Desktop, unless detecting Opera Mobile due to a specific limitation or bug, or for content adaptation or statistics reasons, it is recommended to detect the Presto version number. For content adaptation it is recommended to use CSS3 Media Queries and the Viewport meta tag where at all possible.

Opera Mini

The generic user agent string for Opera Mini 5 and above is as follows:

  • Opera/9.80 (J2ME/MIDP; Opera Mini/$CLIENT_VERSION/$SERVER_VERSION; U; $LANGUAGE) Presto/$PRESTO_VERSION

Opera Mini 5 and above follows the same pattern as Opera 10 Desktop and above for consistency reasons. Opera Mini 4.2 and below follow the previous desktop pattern with the equivalent desktop version at the start of the string:

  • Opera/$VERSION (J2ME/MIDP; Opera Mini/$CLIENT_VERSION/$SERVER_VERSION; $LANGUAGE; U; ssr)

The variables in the two sets of strings above are as follows:

VERSION The equivalent Opera desktop version number
CLIENT_VERSION The build number of the Opera Mini client
SERVER_VERSION The build number of the Opera Mini transcoder server
LANGUAGE The language configured in the client

Opera Mini can be detected independently of Opera Desktop and Opera Mobile by detecting Opera Mini in the user agent string. As with Opera Desktop and Mobile, unless detecting Opera Mini due to a specific limitation or bug, or for content adaptation or statistics reasons, it is recommended to detect the Presto version number. For content adaptation it is recommended to use CSS3 Media Queries where at all possible.

Search pattern

Notice that in spoofed versions of the user agent string, "Opera" is followed by a space, whereas in defaults version of the user agent string, "Opera" is followed by a slash ("/").

The generic regexp pattern for retrieving Opera versions from a UA string is therefore:

Opera[ \/][0-9]+\.[0-9]+

This search pattern is very general, and applies to all versions of Opera on almost all devices, including Opera Mini.

The only case not covered here is the case of masking, when "Opera" does not appear in the user agent string. Masking is site-specific, and only applied in extreme cases when a Web site is not available to Opera by any other means.

JavaScript navigator properties

Note that if you use JavaScript to retrieve information about the browser, then it is advised to use the UA string and not navigator.appName and navigator.appVersion, because the application name attribute will show MSIE or Netscape if Opera spoofs or masks as IE or Firefox respectively. Other browsers, such as Firefox and Safari, will return Netscape by default, making these attributes unreliable for browser detection.

The Opera object

Opera provides a JavaScript object,window.opera, which is supplied to aid debugging. Testing for the presence of this object can be used to detect if the browser is from the Opera family of browsers:


If (window.opera) {
    //this browser is Opera
}

The opera.version method can be used to detect the browser version. In Opera 10.10 this would return the value 10.10.

Open the Web

Develop in Opera

Browser JavaScript

Download Opera - Surf the Web with lightning speed, using the fastest browser ever.