-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hide voice search icon on mobile except for select browsers (#1662)
This PR updates the SearchBar to only display the voice search icon on mobile for select browsers that are known to have support for it. Previously, the voice search icon could appear even when SpeechRecognition was not supported, for example on Chrome for iOS. Since we are now using the Bowser package for user agent sniffing, we no longer need our userAgent acceptance test suite. After this PR I can remove them from the gh-action migration feature branch. J=SLAP-1704 TEST=manual go on browserstack/personal phone use mkcert and the http-server with the `-S` flag for https, so that `navigator.mediaDevices` will exist see that voice search appears for safari ios, chrome android see that voice search does NOT appear for chrome ios, firefox android for samsung internet for android add a window.alert to show that the bowser's useragent sniffing works as expected, since this browser does not have a "visit anyway" for https sites with self signed certificates voice search icon still shows up on edge, chrome, safari desktop browsers, and does not show up on firefox desktop
- Loading branch information
Showing
11 changed files
with
79 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,23 @@ | ||
import Bowser from 'bowser'; | ||
|
||
/** | ||
* Returns whether the current browser is Microsoft Edge. | ||
* Tries to use User-Agent clients hints, and defaults to | ||
* using the User-Agent string if clients hints are not supported. | ||
* | ||
* @returns {boolean} | ||
*/ | ||
export function isMicrosoftEdge () { | ||
const brands = navigator.userAgentData?.brands; | ||
if (brands && brands.length > 0) { | ||
return !!brands.find(b => b.brand === 'Microsoft Edge'); | ||
} else if (navigator.userAgent) { | ||
return navigator.userAgent.includes('Edg'); | ||
} | ||
const browserData = Bowser.parse(navigator.userAgent); | ||
|
||
return browserData.browser.name === 'Microsoft Edge'; | ||
} | ||
|
||
/** | ||
* Returns whether the current browser is Safari. | ||
* Currently, Safari does not support User-Agent clients hints (userAgentData). | ||
* Chrome likes to pretend that it's Safari. | ||
* Edge also likes to pretend that it's Safari. | ||
* | ||
* @returns {boolean} | ||
*/ | ||
export function isSafari () { | ||
if (isChrome()) { | ||
return false; | ||
} | ||
if (isMicrosoftEdge()) { | ||
return false; | ||
} | ||
return navigator.userAgent.includes('Safari'); | ||
} | ||
const browserData = Bowser.parse(navigator.userAgent); | ||
|
||
/** | ||
* Returns whether the current browser is Chrome. | ||
* Edge likes to pretend that it is Chrome. | ||
* | ||
* @returns {boolean} | ||
*/ | ||
export function isChrome () { | ||
if (isMicrosoftEdge()) { | ||
return false; | ||
} | ||
const brands = navigator.userAgentData?.brands; | ||
if (brands && brands.length > 0) { | ||
return !!brands.find(b => b.brand === 'Google Chrome'); | ||
} else if (navigator.userAgent) { | ||
return navigator.userAgent.includes('Chrome'); | ||
} | ||
return browserData.browser.name === 'Safari'; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters