GoogleChrome/lighthouse: Auditing, performance metrics, and best practices for Progressive Web Apps に
この中の、
[TOC]
Lighthouse pwmetrics とは
lighthouse の
ドキュメントを
インストール
npm install -g yarn
CLI で
yarn global add pwmetrics
使い方
README.md
を
オプションなし 通常実行
Command
pwmetrics https://www.monotalk.xyz
Output
コンソール上にグラフが 出力され、 指標と して 以下が 表示されます。 - Time to Consistently Interactive (vBeta)
- First Interactive (vBeta)
- First Meaningful Paint
- First Contentful Paint
各指標の
Web クライアントサイドの
3回測定を 実行
Command
--runs=n
でn回計測に なります。 pwmetrics https://www.monotalk.xyz --runs=3
Output
3回測定した、平均値が 出力されます。
測定結果を JSON形式で 出力する
Command
--json
をつけると 測定結果が JSON 形式で 出力できます。 pwmetrics https://www.monotalk.xyz/ --json
Output
Launching Chrome ✓ Success: Run 1 of 1 finished successfully. { "runs": [ { "timings": [ { "title": "First Contentful Paint", "id": "ttfcp", "timestamp": 1717590041, "timing": 1620.424, "color": "green" }, { "title": "First Meaningful Paint", "id": "ttfmp", "timestamp": 1717590041, "timing": 1620.424, "color": "green" }, { "title": "Perceptual Speed Index", "id": "psi", "timestamp": 1718506565, "timing": 2536.948, "color": "blue" }, { "title": "First Visual Change", "id": "fv", "timestamp": 1718505617, "timing": 2536, "color": "blue" }, { "title": "Visually Complete 85%", "id": "vc85", "timestamp": 1718506565, "timing": 2536.948, "color": "blue" }, { "title": "Visually Complete 100%", "id": "vc100", "timestamp": 1718505617, "timing": 2536, "color": "blue" }, { "title": "First Interactive (vBeta)", "id": "ttfi", "timestamp": 1719493952, "timing": 3524.335, "color": "yellow" }, { "title": "Time to Consistently Interactive (vBeta)", "id": "ttci", "timestamp": 1719493952, "timing": 3524.335, "color": "yellow" } ], "timestamps": [ { "title": "Navigation Start", "id": "navstart", "timestamp": 1715969617 } ], "generatedTime": "2017-12-18T21:23:10.370Z", "lighthouseVersion": "2.7.0", "initialUrl": "https://www.monotalk.xyz/", "url": "https://www.monotalk.xyz/" } ] }
Google スプレッドシートに 測定結果を 書き込む際の 設定
pwmetrics/readme.md at master · paulirish/pwmetrics を
- スプレッドシートの
テンプレートを コピーする - スプレッドシートの
ID を コピーして、 pwmetrics-config.js
のsheets.options.spreadsheetId
にID を 設定する - Google Developer Console から、
キー を 取得する - キー の
client_secret を pwmetrics-config.js
に設定する
以下それぞれ
1. スプレッドシートの
readme.md
に
2. スプレッドシートのpwmetrics-config.js
のsheets.options.spreadsheetId
に
以下のような pwmetrics-config.js
を
module.exports = { url: 'http://www.monotalk.xyz/', flags: { // AKA feature flags runs: '3', // 測定回数 submit: true, // スプレッドシートに書き込むだけならここをtrue upload: false // これをtrueにすると、Google Drive 上に json ファイルがアップロードされます。 }, sheets: { type: 'GOOGLE_SHEETS', // sheets service type. Available types: GOOGLE_SHEETS options: { spreadsheetId: 'your_spreadsheetId', // ここにはスプレッドシートIDを記載 tableName: 'data' // テンプレートを使うと、書き込み先シート名は変えなくてOK } }, clientSecret: { // ここは取得した client_id.json の中身を転記すればOK } }
3. Google Developer Console から、
OAuth 2 認証 の
Node.js Quickstart | Drive REST API | Google Developers にthis wizard
と
4. キー のpwmetrics-config.js
に
3.
のpwmetrics-config.js
のclientSecret
に
以上で、pwmetrics-config.js
の
設定後に pwmetrics を 実行する
pwmetrics-config.js
が--config
を
Command
pwmetrics --config=pwmetrics-config.js
初回起動時の
メッセージ
初回起動時は、OAuth2 の コードを 入力する 必要が あり、 以下のような メッセージが 表示されます。 Launching Chrome Uploading trace to Google Drive... Authorize this app by visiting this url: https://accounts.google.com/o/oauth2/auth?access_type=offline.... Enter the code from that page here:
Google スプレッドシートに
アクセス権が なかった 場合の メッセージ
私の発行した キーは Google Drive の アクセス権だけを つけたので、 スプレッドシートへの 書き込みの 際に 以下の エラーが 発生していました。 メッセージにThe API returned an error: Error: Google Sheets API has not been used in project xxxxxxxxxxxxx before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/sheets.googleapis.com/overview?project=xxxxxxxxxxxxx then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry. Error: Error: Google Sheets API has not been used in project xxxxxxxxxxxxx before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/sheets.googleapis.com/overview?project=xxxxxxxxxxxxxx then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry. at Object.<anonymous> (/Users/xxxxxxxxxxxx/.config/yarn/global/node_modules/pwmetrics/lib/sheets/gsheets.js:60:19) at Generator.throw (<anonymous>) at rejected (/Users/xxxxxxxxxx/.config/yarn/global/node_modules/pwmetrics/lib/sheets/gsheets.js:7:65) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7)
含まれる https://console.developers.google.com/apis/api/sheets.googleapis.com/overview?project=xxxxxxxxxxxxxx
にアクセスすると、 Google スプレッドシート API 権限を 付与する ことができます。 正常終了時
3回測定され、測定結果が スプレッドシートに 書き込まれます。 % pwmetrics --config=pwmetrics-config.js Launching Chrome ✓ Success: Run 1 of 3 finished successfully. Launching Chrome ✓ Success: Run 2 of 3 finished successfully. Launching Chrome ✓ Success: Run 3 of 3 finished successfully. Appending... 2018.436 2018.436 3214.0139999980925 3214 3214 4150.379 4150.379 3214.0139999980925 1952.018 1952.018 3106.813 3105.999999998093 3105.999999998093 4303.783 4303.782999998092 3106.813 1960.176 1960.177 3013.5169999980926 3013.000000001907 3013.000000001907 4096.176 4096.176 3013.5169999980926 Appended 2018.436 2018.436 3214.014 3214 3214 4150.379 4150.379 3214.014 1952.018 1952.018 3106.813 3106 3106 4303.783 4303.783 3106.813 1960.176 1960.177 3013.517 3013 3013 4096.176 4096.176 3013.517
スプレッドシートの 記録結果
テンプレートには、
以下、
複数回実行後の
スプレッドシートの 内容 グラフ表示結果
対象画面を
以上です。
trace と
記述されてました ↩
コメント