Skip to content

Commit f7b6d06

Browse files
committed
Fix browser detection for the extension button.
1 parent 96dad35 commit f7b6d06

File tree

5 files changed

+15
-31
lines changed

5 files changed

+15
-31
lines changed

src/website/extension.js

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,7 @@
11
import { extensionButton, extensionButtonText } from './dom-elements.js';
2+
import { isChrome } from './utils.js';
23
import strings from '../strings.js';
34

4-
// https://stackoverflow.com/questions/4565112/javascript-how-to-find-out-if-the-user-browser-is-chrome
5-
function isChrome() {
6-
// please note,
7-
// that IE11 now returns undefined again for window.chrome
8-
// and new Opera 30 outputs true for window.chrome
9-
// and new IE Edge outputs to true now for window.chrome
10-
// and if not iOS Chrome check
11-
// so use the below updated condition
12-
const isChromium = window.chrome,
13-
winNav = window.navigator,
14-
vendorName = winNav.vendor,
15-
isOpera = winNav.userAgent.indexOf("OPR") > -1,
16-
isIEedge = winNav.userAgent.indexOf("Edge") > -1,
17-
isIOSChrome = winNav.userAgent.match("CriOS");
18-
19-
if (isIOSChrome) {
20-
return false;
21-
} else if (isChromium !== null &&
22-
isChromium !== undefined &&
23-
vendorName === "Google Inc." &&
24-
isOpera == false &&
25-
isIEedge == false) {
26-
return true;
27-
} else {
28-
return false;
29-
}
30-
}
31-
325
function setInstalledText() {
336
if (extensionButton.classList.contains('is-installed')) {
347
extensionButtonText.firstChild.textContent =

src/website/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { setupJwtCounter } from './counter.js';
66
import { setupSmoothScrolling } from './smooth-scrolling.js';
77
import { setupHighlighting } from './highlighting.js';
88
import { getParameterByName } from '../utils.js';
9+
import { isChrome, isFirefox } from './utils.js';
910
import {
1011
publicKeyTextArea,
1112
codeElements,
@@ -41,7 +42,7 @@ function parseLocationQuery() {
4142
}
4243

4344
function pickEbookOrExtensionBanner() {
44-
if(Math.random() >= 0.5) {
45+
if((isChrome() || isFirefox()) && (Math.random() >= 0.5)) {
4546
extensionSection.style.display = 'block';
4647
} else {
4748
ebookSection.style.display = 'block';

src/website/utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,13 @@ export function isInViewport(elem) {
1919
bounding.right <= (window.innerWidth || document.documentElement.clientWidth)
2020
);
2121
};
22+
23+
//From:
24+
// https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser
25+
export function isChrome() {
26+
return !!window.chrome && !!window.chrome.webstore;
27+
}
28+
29+
export function isFirefox() {
30+
return typeof InstallTrigger !== 'undefined';
31+
}

views/website/ebook.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
section.jtw-ebook-banner
22
span
33
strong Get the JWT Handbook for free!
4-
| Spread the word and download it now.
4+
| &nbsp;Spread the word and download it now.
55
a.btn.btn-download-ebook(href='https://auth0.com/e-books/jwt-handbook?utm_source=jwtio&utm_medium=sc&utm_campaign=rotating_banner', target='_blank') Download Ebook

views/website/extension.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
section.update-site
22
span
33
strong Love JWT.IO?
4-
| Bring the debugger to your favorite browser with our new chrome extension.
4+
| Bring the debugger to your favorite browser with our new browser extension.
55
a#extension-button.extension-button
66
svg(width='14px', height='13px', viewbox='24 11 14 13', version='1.1', xmlns='http://www.w3.org/2000/svg', xmlns:xlink='http://www.w3.org/1999/xlink')
77
defs

0 commit comments

Comments
 (0)