Skip to content

Commit 208e4b2

Browse files
committed
fix: add Chrome/ium fallback for getBrowserInfo()
1 parent 45efb68 commit 208e4b2

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

EnvironmentalOptions.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@
1212
* @module MobileOptions
1313
*/
1414

15+
/**
16+
* Return the browser's browser info or fallback to an empty object.
17+
*
18+
* This is a workaround for Chrome/ium browsers that do not support runtime.getBrowserInfo().
19+
* See https://github.com/TinyWebEx/AutomaticSettings/issues/18
20+
*
21+
* @private
22+
* @returns {Promise<bool>}
23+
*/
24+
async function getBrowserInfo() {
25+
if (!browser.runtime.getBrowserInfo) {
26+
return {};
27+
}
28+
29+
return await browser.runtime.getBrowserInfo();
30+
}
31+
1532
/**
1633
* Returns whether the current runtime is a mobile one (true) or not (false).
1734
*
@@ -33,7 +50,7 @@
3350
* @returns {Promise<bool>}
3451
*/
3552
export async function isMozilla() {
36-
const browserInfo = await browser.runtime.getBrowserInfo();
53+
const browserInfo = await getBrowserInfo();
3754

3855
// Thunderbird is explicitly checked as a workaround as Thunderbird does not return the vendor correctly
3956
// see https://bugzilla.mozilla.org/show_bug.cgi?id=1702722
@@ -50,7 +67,7 @@ export async function isMozilla() {
5067
* @returns {Promise<bool>}
5168
*/
5269
export async function isFirefox() {
53-
const browserInfo = await browser.runtime.getBrowserInfo();
70+
const browserInfo = await getBrowserInfo();
5471

5572
return browserInfo.name === "Firefox";
5673
}

0 commit comments

Comments
 (0)