source: node_modules/baseline-browser-mapping/README.md@ 2058e5c

Last change on this file since 2058e5c was 2058e5c, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Working / before login

  • Property mode set to 100644
File size: 20.9 KB
RevLine 
[2058e5c]1# [`baseline-browser-mapping`](https://github.com/web-platform-dx/web-features/packages/baseline-browser-mapping)
2
3By the [W3C WebDX Community Group](https://www.w3.org/community/webdx/) and contributors.
4
5`baseline-browser-mapping` provides:
6
7- An `Array` of browsers compatible with Baseline Widely available and Baseline year feature sets via the [`getCompatibleVersions()` function](#get-baseline-widely-available-browser-versions-or-baseline-year-browser-versions).
8- An `Array`, `Object` or `CSV` as a string describing the Baseline feature set support of all browser versions included in the module's data set via the [`getAllVersions()` function](#get-data-for-all-browser-versions).
9
10You can use `baseline-browser-mapping` to help you determine minimum browser version support for your chosen Baseline feature set; or to analyse the level of support for different Baseline feature sets in your site's traffic by joining the data with your analytics data.
11
12## Install for local development
13
14To install the package, run:
15
16`npm install --save-dev baseline-browser-mapping`
17
18`baseline-browser-mapping` depends on `web-features` and `@mdn/browser-compat-data` for core browser version selection, but the data is pre-packaged and minified. This package checks for updates to those modules and the supported [downstream browsers](#downstream-browsers) on a daily basis and is updated frequently. Consider adding a script to your `package.json` to update `baseline-browser-mapping` and using it as part of your build process to ensure your data is as up to date as possible:
19
20```javascript
21"scripts": [
22 "refresh-baseline-browser-mapping": "npm i --save-dev baseline-browser-mapping@latest"
23]
24```
25
26The minimum supported NodeJS version for `baseline-browser-mapping` is v8 in alignment with `browserslist`. For NodeJS versions earlier than v13.2, the [`require('baseline-browser-mapping')`](https://nodejs.org/api/modules.html#requireid) syntax should be used to import the module.
27
28## Keeping `baseline-browser-mapping` up to date
29
30If you are only using this module to generate minimum browser versions for Baseline Widely available or Baseline year feature sets, you don't need to update this module frequently, as the backward looking data is reasonably stable.
31
32However, if you are targeting Newly available, using the [`getAllVersions()`](#get-data-for-all-browser-versions) function or heavily relying on the data for downstream browsers, you should update this module more frequently. If you target a feature cut off date within the last two months and your installed version of `baseline-browser-mapping` has data that is more than 2 months old, you will receive a console warning advising you to update to the latest version when you call `getCompatibleVersions()` or `getAllVersions()`.
33
34If you want to suppress these warnings you can use the `suppressWarnings: true` option in the configuration object passed to `getCompatibleVersions()` or `getAllVersions()`. Alternatively, you can use the `BASELINE_BROWSER_MAPPING_IGNORE_OLD_DATA=true` environment variable when running your build process. This module also respects the `BROWSERSLIST_IGNORE_OLD_DATA=true` environment variable. Environment variables can also be provided in a `.env` file from Node 20 onwards; however, this module does not load .env files automatically to avoid conflicts with other libraries with different requirements. You will need to use `process.loadEnvFile()` or a library like `dotenv` to load .env files before `baseline-browser-mapping` is called.
35
36If you want to ensure [reproducible builds](https://www.wikiwand.com/en/articles/Reproducible_builds), we strongly recommend using the `widelyAvailableOnDate` option to fix the Widely available date on a per build basis to ensure dependent tools provide the same output and you do not produce data staleness warnings. If you are using [`browserslist`](https://github.com/browserslist/browserslist) to target Baseline Widely available, consider automatically updating your `browserslist` configuration in `package.json` or `.browserslistrc` to `baseline widely available on {YYYY-MM-DD}` as part of your build process to ensure the same or sufficiently similar list of minimum browsers is reproduced for historical builds.
37
38## Importing `baseline-browser-mapping`
39
40This module exposes two functions: `getCompatibleVersions()` and `getAllVersions()`, both which can be imported directly from `baseline-browser-mapping`:
41
42```javascript
43import {
44 getCompatibleVersions,
45 getAllVersions,
46} from "baseline-browser-mapping";
47```
48
49If you want to load the script and data directly in a web page without hosting it yourself, consider using a CDN:
50
51```html
52<script type="module">
53 import {
54 getCompatibleVersions,
55 getAllVersions,
56 } from "https://cdn.jsdelivr.net/npm/baseline-browser-mapping";
57</script>
58```
59
60## Get Baseline Widely available browser versions or Baseline year browser versions
61
62To get the current list of minimum browser versions compatible with Baseline Widely available features from the core browser set, call the `getCompatibleVersions()` function:
63
64```javascript
65getCompatibleVersions();
66```
67
68Executed on 7th March 2025, the above code returns the following browser versions:
69
70```javascript
71[
72 { browser: "chrome", version: "105", release_date: "2022-09-02" },
73 {
74 browser: "chrome_android",
75 version: "105",
76 release_date: "2022-09-02",
77 },
78 { browser: "edge", version: "105", release_date: "2022-09-02" },
79 { browser: "firefox", version: "104", release_date: "2022-08-23" },
80 {
81 browser: "firefox_android",
82 version: "104",
83 release_date: "2022-08-23",
84 },
85 { browser: "safari", version: "15.6", release_date: "2022-09-02" },
86 {
87 browser: "safari_ios",
88 version: "15.6",
89 release_date: "2022-09-02",
90 },
91];
92```
93
94> [!NOTE]
95> The minimum versions of each browser are not necessarily the final release before the Widely available cutoff date of `TODAY - 30 MONTHS`. Some earlier versions will have supported the full Widely available feature set.
96
97### `getCompatibleVersions()` configuration options
98
99`getCompatibleVersions()` accepts an `Object` as an argument with configuration options. The defaults are as follows:
100
101```javascript
102{
103 targetYear: undefined,
104 widelyAvailableOnDate: undefined,
105 includeDownstreamBrowsers: false,
106 listAllCompatibleVersions: false,
107 suppressWarnings: false
108}
109```
110
111#### `targetYear`
112
113The `targetYear` option returns the minimum browser versions compatible with all **Baseline Newly available** features at the end of the specified calendar year. For example, calling:
114
115```javascript
116getCompatibleVersions({
117 targetYear: 2020,
118});
119```
120
121Returns the following versions:
122
123```javascript
124[
125 { browser: "chrome", version: "87", release_date: "2020-11-19" },
126 {
127 browser: "chrome_android",
128 version: "87",
129 release_date: "2020-11-19",
130 },
131 { browser: "edge", version: "87", release_date: "2020-11-19" },
132 { browser: "firefox", version: "83", release_date: "2020-11-17" },
133 {
134 browser: "firefox_android",
135 version: "83",
136 release_date: "2020-11-17",
137 },
138 { browser: "safari", version: "14", release_date: "2020-09-16" },
139 { browser: "safari_ios", version: "14", release_date: "2020-09-16" },
140];
141```
142
143> [!NOTE]
144> The minimum version of each browser is not necessarily the final version released in that calendar year. In the above example, Firefox 84 was the final version released in 2020; however Firefox 83 supported all of the features that were interoperable at the end of 2020.
145> [!WARNING]
146> You cannot use `targetYear` and `widelyAavailableDate` together. Please only use one of these options at a time.
147
148#### `widelyAvailableOnDate`
149
150The `widelyAvailableOnDate` option returns the minimum versions compatible with Baseline Widely available on a specified date in the format `YYYY-MM-DD`:
151
152```javascript
153getCompatibleVersions({
154 widelyAvailableOnDate: `2023-04-05`,
155});
156```
157
158> [!TIP]
159> This option is useful if you provide a versioned library that targets Baseline Widely available on each version's release date and you need to provide a statement on minimum supported browser versions in your documentation.
160
161#### `includeDownstreamBrowsers`
162
163Setting `includeDownstreamBrowsers` to `true` will include browsers outside of the Baseline core browser set where it is possible to map those browsers to an upstream Chromium or Gecko version:
164
165```javascript
166getCompatibleVersions({
167 includeDownstreamBrowsers: true,
168});
169```
170
171For more information on downstream browsers, see [the section on downstream browsers](#downstream-browsers) below.
172
173#### `includeKaiOS`
174
175KaiOS is an operating system and app framework based on the Gecko engine from Firefox. KaiOS is based on the Gecko engine and feature support can be derived from the upstream Gecko version that each KaiOS version implements. However KaiOS requires other considerations beyond feature compatibility to ensure a good user experience as it runs on device types that do not have either mouse and keyboard or touch screen input in the way that all the other browsers supported by this module do.
176
177```javascript
178getCompatibleVersions({
179 includeDownstreamBrowsers: true,
180 includeKaiOS: true,
181});
182```
183
184> [!NOTE]
185> Including KaiOS requires you to include all downstream browsers using the `includeDownstreamBrowsers` option.
186
187#### `listAllCompatibleVersions`
188
189Setting `listAllCompatibleVersions` to true will include the minimum versions of each compatible browser, and all the subsequent versions:
190
191```javascript
192getCompatibleVersions({
193 listAllCompatibleVersions: true,
194});
195```
196
197#### `suppressWarnings`
198
199Setting `suppressWarnings` to `true` will suppress the console warning about old data:
200
201```javascript
202getCompatibleVersions({
203 suppressWarnings: true,
204});
205```
206
207## Get data for all browser versions
208
209You may want to obtain data on all the browser versions available in this module for use in an analytics solution or dashboard. To get details of each browser version's level of Baseline support, call the `getAllVersions()` function:
210
211```javascript
212import { getAllVersions } from "baseline-browser-mapping";
213
214getAllVersions();
215```
216
217By default, this function returns an `Array` of `Objects` and excludes downstream browsers:
218
219```javascript
220[
221 ...
222 {
223 browser: "firefox_android", // Browser name
224 version: "125", // Browser version
225 release_date: "2024-04-16", // Release date
226 year: 2023, // Baseline year feature set the version supports
227 wa_compatible: true // Whether the browser version supports Widely available
228 },
229 ...
230]
231```
232
233For browser versions in `@mdn/browser-compat-data` that were released before Baseline can be defined, i.e. Baseline 2015, the `year` property is always the string: `"pre_baseline"`.
234
235### Understanding which browsers support Newly available features
236
237You may want to understand which recent browser versions support all Newly available features. You can replace the `wa_compatible` property with a `supports` property using the `useSupport` option:
238
239```javascript
240getAllVersions({
241 useSupports: true,
242});
243```
244
245The `supports` property is optional and has two possible values:
246
247- `widely` for browser versions that support all Widely available features.
248- `newly` for browser versions that support all Newly available features.
249
250Browser versions that do not support Widely or Newly available will not include the `support` property in the `array` or `object` outputs, and in the CSV output, the `support` column will contain an empty string. Browser versions that support all Newly available features also support all Widely available features.
251
252### `getAllVersions()` Configuration options
253
254`getAllVersions()` accepts an `Object` as an argument with configuration options. The defaults are as follows:
255
256```javascript
257{
258 includeDownstreamBrowsers: false,
259 outputFormat: "array",
260 suppressWarnings: false
261}
262```
263
264#### `includeDownstreamBrowsers` (in `getAllVersions()` output)
265
266As with `getCompatibleVersions()`, you can set `includeDownstreamBrowsers` to `true` to include the Chromium and Gecko downstream browsers [listed below](#list-of-downstream-browsers).
267
268```javascript
269getAllVersions({
270 includeDownstreamBrowsers: true,
271});
272```
273
274Downstream browsers include the same properties as core browsers, as well as the `engine`they use and `engine_version`, for example:
275
276```javascript
277[
278 ...
279 {
280 browser: "samsunginternet_android",
281 version: "27.0",
282 release_date: "2024-11-06",
283 engine: "Blink",
284 engine_version: "125",
285 year: 2023,
286 supports: "widely"
287 },
288 ...
289]
290```
291
292#### `includeKaiOS` (in `getAllVersions()` output)
293
294As with `getCompatibleVersions()` you can include KaiOS in your output. The same requirement to have `includeDownstreamBrowsers: true` applies.
295
296```javascript
297getAllVersions({
298 includeDownstreamBrowsers: true,
299 includeKaiOS: true,
300});
301```
302
303#### `suppressWarnings` (in `getAllVersions()` output)
304
305As with `getCompatibleVersions()`, you can set `suppressWarnings` to `true` to suppress the console warning about old data:
306
307```javascript
308getAllVersions({
309 suppressWarnings: true,
310});
311```
312
313#### `outputFormat`
314
315By default, this function returns an `Array` of `Objects` which can be manipulated in Javascript or output to JSON.
316
317To return an `Object` that nests keys , set `outputFormat` to `object`:
318
319```javascript
320getAllVersions({
321 outputFormat: "object",
322});
323```
324
325In thise case, `getAllVersions()` returns a nested object with the browser [IDs listed below](#list-of-downstream-browsers) as keys, and versions as keys within them:
326
327```javascript
328{
329 "chrome": {
330 "53": {
331 "year": 2016,
332 "release_date": "2016-09-07"
333 },
334 ...
335}
336```
337
338Downstream browsers will include extra fields for `engine` and `engine_versions`
339
340```javascript
341{
342 ...
343 "webview_android": {
344 "53": {
345 "year": 2016,
346 "release_date": "2016-09-07",
347 "engine": "Blink",
348 "engine_version": "53"
349 },
350 ...
351}
352```
353
354To return a `String` in CSV format, set `outputFormat` to `csv`:
355
356```javascript
357getAllVersions({
358 outputFormat: "csv",
359});
360```
361
362`getAllVersions` returns a `String` with a header row and comma-separated values for each browser version that you can write to a file or pass to another service. Core browsers will have "NULL" as the value for their `engine` and `engine_version`:
363
364```csv
365"browser","version","year","supports","release_date","engine","engine_version"
366...
367"chrome","24","pre_baseline","","2013-01-10","NULL","NULL"
368...
369"chrome","53","2016","","2016-09-07","NULL","NULL"
370...
371"firefox","135","2024","widely","2025-02-04","NULL","NULL"
372"firefox","136","2024","newly","2025-03-04","NULL","NULL"
373...
374"ya_android","20.12","2020","year_only","2020-12-20","Blink","87"
375...
376```
377
378> [!NOTE]
379> The above example uses `"includeDownstreamBrowsers": true`
380
381### Static resources
382
383The outputs of `getAllVersions()` are available as JSON or CSV files generated on a daily basis and hosted on GitHub pages:
384
385- Core browsers only
386 - [Array](https://web-platform-dx.github.io/baseline-browser-mapping/all_versions_array.json)
387 - [Object](https://web-platform-dx.github.io/baseline-browser-mapping/all_versions_object.json)
388 - [CSV](https://web-platform-dx.github.io/baseline-browser-mapping/all_versions.csv)
389- Core browsers only, with `supports` property
390 - [Array](https://web-platform-dx.github.io/baseline-browser-mapping/all_versions_array_with_supports.json)
391 - [Object](https://web-platform-dx.github.io/baseline-browser-mapping/all_versions_object_with_supports.json)
392 - [CSV](https://web-platform-dx.github.io/baseline-browser-mapping/all_versions_with_supports.csv)
393- Including downstream browsers
394 - [Array](https://web-platform-dx.github.io/baseline-browser-mapping/with_downstream/all_versions_array.json)
395 - [Object](https://web-platform-dx.github.io/baseline-browser-mapping/with_downstream/all_versions_object.json)
396 - [CSV](https://web-platform-dx.github.io/baseline-browser-mapping/with_downstream/all_versions.csv)
397- Including downstream browsers with `supports` property
398 - [Array](https://web-platform-dx.github.io/baseline-browser-mapping/with_downstream/all_versions_array_with_supports.json)
399 - [Object](https://web-platform-dx.github.io/baseline-browser-mapping/with_downstream/all_versions_object_with_supports.json)
400 - [CSV](https://web-platform-dx.github.io/baseline-browser-mapping/with_downstream/all_versions_with_supports.csv)
401
402These files are updated on a daily basis.
403
404## CLI
405
406`baseline-browser-mapping` includes a command line interface that exposes the same data and options as the `getCompatibleVersions()` function. To learn more about using the CLI, run:
407
408```sh
409npx baseline-browser-mapping --help
410```
411
412## Downstream browsers
413
414### Limitations
415
416The browser versions in this module come from two different sources:
417
418- MDN's `browser-compat-data` module.
419- Parsed user agent strings provided by [useragents.io](https://useragents.io/)
420
421MDN `browser-compat-data` is an authoritative source of information for the browsers it contains. The release dates for the Baseline core browser set and the mapping of downstream browsers to Chromium versions should be considered accurate.
422
423Browser mappings from useragents.io are provided on a best effort basis. They assume that browser vendors are accurately stating the Chromium version they have implemented. The initial set of version mappings was derived from a bulk export in November 2024. This version was iterated over with a Regex match looking for a major Chrome version and a corresponding version of the browser in question, e.g.:
424
425`Mozilla/5.0 (Linux; U; Android 10; en-US; STK-L21 Build/HUAWEISTK-L21) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/100.0.4896.58 UCBrowser/13.8.2.1324 Mobile Safari/537.36`
426
427Shows UC Browser Mobile 13.8 implementing Chromium 100, and:
428
429`Mozilla/5.0 (Linux; arm_64; Android 11; Redmi Note 8 Pro) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.6613.123 YaBrowser/24.10.2.123.00 SA/3 Mobile Safari/537.36`
430
431Shows Yandex Browser Mobile 24.10 implementing Chromium 128. The Chromium version from this string is mapped to the corresponding Chrome version from MDN `browser-compat-data`.
432
433> [!NOTE]
434> Where possible, approximate release dates have been included based on useragents.io "first seen" data. useragents.io does not have "first seen" dates prior to June 2020. However, these browsers' Baseline compatibility is determined by their Chromium or Gecko version, so their release dates are more informative than critical.
435
436This data is updated on a daily basis using a [script](https://github.com/web-platform-dx/web-features/tree/main/scripts/refresh-downstream.ts) triggered by a GitHub [action](https://github.com/web-platform-dx/web-features/tree/main/.github/workflows/refresh_downstream.yml). Useragents.io provides a private API for this module which exposes the last 7 days of newly seen user agents for the currently tracked browsers. If a new major version of one of the tracked browsers is encountered with a Chromium version that meets or exceeds the previous latest version of that browser, it is added to the [src/data/downstream-browsers.json](src/data/downstream-browsers.json) file with the date it was first seen by useragents.io as its release date.
437
438KaiOS is an exception - its upstream version mappings are handled separately from the other browsers because they happen very infrequently.
439
440### List of downstream browsers
441
442| Browser | ID | Core | Source |
443| --------------------- | ------------------------- | ------- | ------------------------- |
444| Chrome | `chrome` | `true` | MDN `browser-compat-data` |
445| Chrome for Android | `chrome_android` | `true` | MDN `browser-compat-data` |
446| Edge | `edge` | `true` | MDN `browser-compat-data` |
447| Firefox | `firefox` | `true` | MDN `browser-compat-data` |
448| Firefox for Android | `firefox_android` | `true` | MDN `browser-compat-data` |
449| Safari | `safari` | `true` | MDN `browser-compat-data` |
450| Safari on iOS | `safari_ios` | `true` | MDN `browser-compat-data` |
451| Opera | `opera` | `false` | MDN `browser-compat-data` |
452| Opera Android | `opera_android` | `false` | MDN `browser-compat-data` |
453| Samsung Internet | `samsunginternet_android` | `false` | MDN `browser-compat-data` |
454| WebView Android | `webview_android` | `false` | MDN `browser-compat-data` |
455| QQ Browser Mobile | `qq_android` | `false` | useragents.io |
456| UC Browser Mobile | `uc_android` | `false` | useragents.io |
457| Yandex Browser Mobile | `ya_android` | `false` | useragents.io |
458| KaiOS | `kai_os` | `false` | Manual |
459| Facebook for Android | `facebook_android` | `false` | useragents.io |
460| Instagram for Android | `instagram_android` | `false` | useragents.io |
461
462> [!NOTE]
463> All the non-core browsers currently included implement Chromium or Gecko. Their inclusion in any of the above methods is based on the Baseline feature set supported by the Chromium or Gecko version they implement, not their release date.
Note: See TracBrowser for help on using the repository browser.