How to make difference between Opera and Opera Mini in JavaScript

643 Views Asked by At

Some of the features from my website don't work on Opera Mini, but they work on Opera. Is there a way to tell difference between these two browsers in JavaScript, so that I could prevent people from accessing certain pages of my website?

I've tried window.navigator.userAgent.indexOf('Opera Mini/') but it also works for Opera... Object.prototype.toString.call(window.operamini) === "[object OperaMini]" doesn't work at all

1

There are 1 best solutions below

1
Alex On

Opera Mini use 3 modes for major platforms(iOS, Android):

  1. Default mode - without compression
  2. High saving mode - compress content only (images, video and etc)
  3. Extreme mode - full compression using OBLM

Only extreme mode is real Opera Mini, in other cases Opera Mini uses default browser engine, but with a additional letters OPR/ in user agent string.

So you just need to check window.operamini for extreme mode and OPR/ in user agent string for other modes.

const isOperaMini = navigator.userAgent.indexOf('OPR/') !== -1;
const isOperaMiniExtreme = isOperaMini && !!window.operamini;

That's all. This is the only way.