Skip to content

Commit

Permalink
feat(ua): add better Pale Moon handling
Browse files Browse the repository at this point in the history
  • Loading branch information
wessberg committed May 19, 2021
1 parent f6406de commit 74b1d74
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/browserslist-generator/browserslist-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1033,16 +1033,24 @@ function getCaniuseBrowserForUseragentBrowser(parser: UaParserWrapper): Partial<
}
}

else {
// Then, from v27, it was based on a re-fork of Firefox 38.
// Unfortunately, there has been no re-forks since, so we'll
// have to assume it is still equivalent to Firefox 38 for
// the time being
// Unfortunately, we don't have fresh data as for the versions
// in between 27 and 29, so we'll have to stay at version 38 in
// this range
else if (lt(semver, "29.0.0")) {
return {
browser: "firefox",
version: "38"
}
}

// We know that v29 points to Firefox 68 in some of its user agents
else {
return {
browser: "firefox",
version: "68"
}
}
}

// For the MIUIBrowser, there are some rare instances for major versions 8 and 9 where they'll have no declared Chromium engine.
Expand Down Expand Up @@ -1268,7 +1276,7 @@ function getCaniuseBrowserForUseragentBrowser(parser: UaParserWrapper): Partial<
case "Gecko":
return {
browser: "firefox",
version: browser.version
version: engine.version
};
case "Presto":
return {
Expand Down
11 changes: 11 additions & 0 deletions src/browserslist-generator/ua-parser-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {UAParser} from "ua-parser-js";
import isbot from "isbot";
import {UseragentBrowser, UseragentDevice, UseragentEngine, UseragentOs} from "./useragent/useragent-typed";

const FIREFOX_MATCH = /Firefox\/([\d.]+)/i;

// These extension provide ua-parser-js with support for additional browsers
// such as Sogou Explorer
const PARSER_EXTENSIONS = {
Expand Down Expand Up @@ -121,6 +123,15 @@ export class UaParserWrapper {
delete result.blink;
}

// The User Agent may hold additional information, such as the equivalent Firefox version
if (result.name === "Goanna") {
const ffMatch = this.userAgent.match(FIREFOX_MATCH);
if (ffMatch != null) {
result.name = "Gecko";
result.version = ffMatch[1];
}
}

return result;
}
}
4 changes: 4 additions & 0 deletions test/browserslist-generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ test("matchBrowserslistOnUserAgent() => Will match Pale Moon, but treat it as Fi
t.true(matchBrowserslistOnUserAgent(`Mozilla/5.0 (Windows NT 5.1; rv:4.8) Goanna/20210507 PaleMoon/28.10.3a1`, ["firefox >= 38"]));
});

test("matchBrowserslistOnUserAgent() => Will match Pale Moon, but treat it as Firefox. #2", t => {
t.true(matchBrowserslistOnUserAgent(`Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Goanna/4.8 Firefox/68.0 PaleMoon/29.1.1`, ["firefox >= 68"]));
});

test("matchBrowserslistOnUserAgent() => Will match Sogou Explorer, but treat it as Chrome. #1", t => {
t.true(
matchBrowserslistOnUserAgent(`Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.33 Safari/534.3 SE 2.X MetaSr 1.0`, [
Expand Down

0 comments on commit 74b1d74

Please sign in to comment.