Skip to content

Commit ebeec8f

Browse files
committed
Automatically fetch latest Chrome version
1 parent a3b18b7 commit ebeec8f

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

.github/workflows/gh-pages.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ jobs:
2323
- name: Setup Node.js environment
2424
uses: actions/setup-node@v4
2525
with:
26-
node-version: '20'
26+
node-version: '22'
2727

2828
- run: npm ci
29+
30+
- name: Set Environment Variables
31+
run: echo "CHROME_VERSION=$(node scripts/get-chrome-version.mjs)" >> $GITHUB_ENV
32+
2933
- run: npm run build:production
3034

3135
- name: Deploy
32-
uses: peaceiris/actions-gh-pages@v3.9.3
36+
uses: peaceiris/actions-gh-pages@v4
3337
if: github.ref == 'refs/heads/main'
3438
with:
3539
github_token: ${{ secrets.GITHUB_TOKEN }}

global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
declare const __DEBUG__: boolean;
22
declare const __VERSION__: string;
3+
declare const __CHROME_VERSION__: string;
34

45
declare module "friendly-time" {
56
export default function friendlyTime(date: Date): string;

scripts/get-chrome-version.mjs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @returns {Promise<ChromeVersionsInfo>}
3+
*/
4+
async function getChromeVersionsInfo() {
5+
const response = await fetch(
6+
"https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json",
7+
{ mode: "cors" }
8+
);
9+
10+
if (!response.ok) {
11+
return Promise.reject(
12+
new Error(`Failed to fetch chrome versions info (status ${response.status})`)
13+
);
14+
}
15+
16+
return response.json();
17+
}
18+
19+
/**
20+
* @typedef {Object} ChromeVersionsInfo
21+
* @property {string} timestamp - The timestamp of the version info.
22+
* @property {Object} channels - A record of Chrome channels.
23+
* @property {ChromeChannelInfo} channels.Stable - Stable channel info.
24+
* @property {ChromeChannelInfo} channels.Beta - Beta channel info.
25+
* @property {ChromeChannelInfo} channels.Dev - Dev channel info.
26+
* @property {ChromeChannelInfo} channels.Canary - Canary channel info.
27+
*/
28+
29+
/**
30+
* @typedef {Object} ChromeChannelInfo
31+
* @property {"Stable" | "Beta" | "Dev" | "Canary"} channel - The name of the channel.
32+
* @property {string} version - The version string in the format "X.X.X.X".
33+
* @property {string} revision - The revision number.
34+
* @property {unknown} downloads - Download links (structure not relevant).
35+
*/
36+
37+
await getChromeVersionsInfo()
38+
.then(
39+
(info) => info.channels.Stable.version,
40+
() => "133.0.6943.126" // fallback (19.02.2025)
41+
)
42+
.then(console.log);

vite.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import process from "node:process";
12
import { defineConfig } from "vite";
23

4+
// https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json
5+
const CHROME_VERSION = process.env.CHROME_VERSION ?? "133.0.6943.126";
6+
37
export default defineConfig({
48
server: {
59
port: 3000,
@@ -9,7 +13,8 @@ export default defineConfig({
913
},
1014
define: {
1115
__VERSION__: JSON.stringify(process.env.npm_package_version),
12-
__DEBUG__: JSON.stringify(true)
16+
__DEBUG__: JSON.stringify(true),
17+
__CHROME_VERSION__: JSON.stringify(CHROME_VERSION),
1318
},
1419
css: {
1520
modules: {

0 commit comments

Comments
 (0)