Identifying the web browser by utilizing the UserAgent detection method

How can I determine if the current browser is Chrome using TypeScript/JavaScript?

I previously used the following method:

var isChrome = !!(<any>window).chrome && !!(<any>window).chrome.webstore;

However, this doesn't work anymore. Is there a new approach I can take? I prefer not to rely on UserAgent due to past issues.

Answer №1

A similar query has already been addressed in this thread, Here is a sample code snippet:

// Chrome 1 - 71
var isChrome = !!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime);

Appreciate the help, Oliver

Answer №2

One possible solution is to utilize the navigator global variable like this:

const isChrome = /chrome/.test( navigator.userAgent.toLowerCase() );

Answer №3

If you want to check the browser being used, consider using the bowser library:

console.log("Current browser is " + bowser.name + ", version: " + bowser.version + ", operating system: " + bowser.osname);

// Verify if it's Chrome 20 or newer
const isChrome = bowser.check({chrome: "20"}, true);
console.log("Chrome Browser: ", isChrome);
<script src="https://cdnjs.cloudflare.com/ajax/libs/bowser/1.9.4/bowser.min.js"></script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Failure occurs when attempting to compare multidimensional arrays to locate the correct index for use in another multidimensional array

Hey there! I'm reaching out because I need assistance with a Javascript function: Basically, I have an input array that I want to compare to another array and based on the result, return something. However, for some reason my comparison is not yieldi ...

Looking to create a subtle border with rounded edges

https://i.sstatic.net/oFS4t.png I'm currently working on creating a smooth, fading green line using an array of points in my code. for(var i = this.trail.length - 1; i > -1 + 1; i--) { var time = this.trail[i][0]; var pos = this.trail[i][ ...

What do you notice about interactions involving 'input type=text' in HTML and JavaScript?

When a new binding is created for the value property on an input, any manual modifications by the user no longer update the value. What happens when the binding is altered? Does regular user interaction involve key press listeners? I've modified the ...

Add a document to MongoDB and then tailor the data using a separate query before insertion

My request is quite simple: I need to add a new document to my MongoDB database. However, before doing so, I must first check if the slug already exists in the database. If it does, I need to rename the slug before proceeding with the insertion. I have b ...

JSON - When an Object's Value Matches

Within my JSON file, I have an object that contains an array of nested objects. I am looking for a way to trigger a function based on the value of a specific object. If the value matches a certain number, I want to display only those objects within a desig ...

Issue with Passing 'key' Prop to React Component in a Mapped Iteration

https://i.sstatic.net/qeFKT.pngI'm struggling with adding a key prop to a React component in a mapped array within a Next.js project. The issue lies in a Slider component and an array of Image components being mapped. Even though I have provided a uni ...

Having difficulty loading the controller into my AngularJS module

I've been attempting to organize my angularjs controllers into separate files without success. Folder Structure: --public-- --js/controller/resturant.js --js/master.js --index.php Content of master.js angular.module("rsw",[ ...

Delete an element from an array after a specified timeout period

I'm currently working on a Vue component that is responsible for displaying notifications which should automatically disappear after a set time. My Alert component triggers an 'expired' event and then I handle this event in the parent compon ...

Exploring the implementation of an if condition within a button tag

Currently, I am a beginner in the field of web development and I have encountered an issue while trying to implement a certain logic. Here is the button tag that I am working with: <td> <input style="word-wrap: break-word;white-space: normal; ...

Using React to Calculate the Total Value of Child Components within the Parent Component

In this scenario, the parent component has access to the values of the child components but struggles to calculate the sum correctly. Instead of displaying the accurate total, it shows 0. https://i.sstatic.net/1etAx.png The expected behavior is for the To ...

There are two modals present on the page, however only one of them is triggered for all actions in Angular 2

I'm encountering an issue with my page where I have set up two confirmation modals - one for resetting a form and another for deleting an item. Strangely, only the reset modal is being triggered for both actions and I can't figure out why. Could ...

Randomizer File Name Maker

I was questioning the behavior of Multer Filename. If Multer stores files with random filenames, is there a possibility of two files having the same name in Multer? In other words, if I am storing files from a large number of users, could the filenames e ...

The Vue.createApp function seems to be malfunctioning, whereas using the new Vue() method is functioning correctly

When running my code, I encountered the following error message: tesyya.js:16 Uncaught TypeError: Vue.createApp is not a function. My code snippet looks like this: const app = Vue.createApp({ data() { return { count: 4 } } }) const vm ...

Disable the javascript link on small devices

I currently have a javascript link (Trustwave) on my desktop website theme that I need to deactivate when viewed on mobile devices: Located in footer.tpl: <div style="position:absolute; margin-left:100px; margin-top:50px"> <script type="text/j ...

What steps should be taken when encountering an error with fs while using ANTLR?

I have encountered an issue with antlr while using Angular in Visual Studio Code. I am familiar with including and writing a grammar in a project, but recently I ran into a problem when starting it: "ERROR in ./node_modules/antlr4/CharStreams.js Module no ...

How can Javascript or Jquery determine the specific event assigned to an object?

Is it possible to retrieve the properties of HTML elements using their name or id? For example: document.getElementById('id').value; //Accessing element property in JavaScript $('#id').attr('class'); // Accessing correspond ...

Defined interface with specific number of members

I am tasked with creating an interface that has only two members, one of which is optional and both have undefined names. Something like: interface MyInterface { [required: string]: string|number [optional: string]?: string|number } Unfortunately, ...

Halt the iteration once you reach the initial item in the array

I am encountering a challenge with this for loop. My goal is to extract the most recent order of "customers" and save it in my database. However, running this loop fetches both the failed order and the recent order. for (var i = 0; i < json.length; ...

Closing a webview completely in React JS

I am currently developing a website using React JS that will be integrated with an Android/iOS application and function like a webview. Within the website, I have implemented a cross button. When this button is clicked, I need to trigger a native bridge ...

Using Jquery to locate the next div element

I've created this code snippet, but it's not functioning as expected. However, by reviewing it, you can understand my intended outcome: $('.jfmfs-alpha-separator').filter(function() { return ($(this).next().not(".hide-filtered"). ...