Skip to main content
Version: Next

is.chrome

is.chrome(target: unknown)โ€‹

The is.chrome method is a utility function in JavaScript that is used to determine whether the current browser is a version of Google Chrome. It returns a boolean value indicating whether the browser is Chrome or not.

The is.chrome method works by examining the user agent string of the browser, which includes information about the browser's name, version, and other details. It checks for the presence of the string "Chrome" in the user agent string to determine whether the browser is Chrome.

It's worth noting that the user agent string can be spoofed or modified, so relying solely on this method to determine the browser's identity is not foolproof. However, it can be a useful tool in many cases where the user agent string is not tampered with.

In summary, is.chrome is a simple and straightforward method for detecting whether the current browser is a version of Google Chrome.

Specificationโ€‹

  • Target argument: optional.
  • Return: boolean.

Informationโ€‹

  • Unit tests: โœ…

Examplesโ€‹

is.chrome() // true if the command is executed in the chrome browser
is.chrome('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36', 'Google Inc.') // true

// Alternative
isConfig.state.userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36';
isConfig.state.vendor = 'Google Inc.';
is.chrome() // true

// Recomendation
is.browser_chrome();

is.chrome(false) // false
is.chrome(new Boolean(0)) // false
is.chrome(new Boolean()) // false
is.chrome(0) // false
is.chrome('') // false
is.chrome({}) // false
is.chrome([]) // false
// And all other known types will return false

Reversal boolean resultโ€‹

is.not_chrome() // false if the command is executed in the chrome browser
is.not_chrome('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36 Edg/93.0.961.38', 'Google Inc.') // false

// Alternative
isConfig.state.userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36';
isConfig.state.vendor = 'Google Inc.';
is.not_chrome() // false

// Recomendation
is.not_browser_chrome();

is.not_chrome(false) // false
is.not_chrome(new Boolean(0)) // false
is.not_chrome(new Boolean()) // false
is.not_chrome(0) // false
is.not_chrome('') // false
is.not_chrome({}) // false
is.not_chrome([]) // false
// And all other known types will return true