@jsenv/core 24.5.6 → 24.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  // https://github.com/Ahmdrza/detect-browser/blob/26254f85cf92795655a983bfd759d85f3de850c6/detect-browser.js#L1
2
2
  // https://github.com/lancedikson/bowser/blob/master/src/parser-browsers.js#L1
3
3
 
4
+ import { detectFromUserAgentData } from "./user_agent_data.js"
4
5
  import { detectAndroid } from "./detectAndroid.js"
5
6
  import { detectInternetExplorer } from "./detectInternetExplorer.js"
6
7
  import { detectOpera } from "./detectOpera.js"
@@ -25,6 +26,7 @@ const detectorCompose = (detectors) => () => {
25
26
  }
26
27
 
27
28
  const detector = detectorCompose([
29
+ detectFromUserAgentData, // keep this first
28
30
  detectOpera,
29
31
  detectInternetExplorer,
30
32
  detectEdge,
@@ -1,18 +1,6 @@
1
1
  import { userAgentToVersion, firstMatch } from "./util.js"
2
2
 
3
3
  export const detectChrome = () => {
4
- const { userAgentData } = window.navigator
5
- if (userAgentData) {
6
- const brand = userAgentData.brands.some((brand) => {
7
- return brand.brand === "chromium" || brand.brand === "Google Chrome"
8
- })
9
- if (brand) {
10
- return {
11
- name: "chrome",
12
- version: brand.version,
13
- }
14
- }
15
- }
16
4
  return userAgentToBrowser(window.navigator.userAgent)
17
5
  }
18
6
 
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Prefer window.navigator.userAgentData before resorting to
3
+ * window.navigator.userAgent because of
4
+ * https://blog.chromium.org/2021/09/user-agent-reduction-origin-trial-and-dates.html
5
+ */
6
+
7
+ export const detectFromUserAgentData = () => {
8
+ const { userAgentData } = window.navigator
9
+ if (!userAgentData) {
10
+ return null
11
+ }
12
+
13
+ const { brands } = userAgentData
14
+ let i = 0
15
+ while (i < brands.legth) {
16
+ const { brand, version } = brands[i]
17
+ i++
18
+ if (brand === "chromium" || brand === "Google Chrome") {
19
+ return {
20
+ name: "chrome",
21
+ version,
22
+ }
23
+ }
24
+ }
25
+ return null
26
+ }