-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
report(psi): stub out locale swapping #13885
Changes from all commits
24450e5
d36998d
dfb8fef
819c687
b81975f
6dade11
b3e7f9f
3e398ee
5ed960b
68935ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,12 @@ const wait = (ms = 100) => new Promise(resolve => setTimeout(resolve, ms)); | |
(async function __initPsiReports__() { | ||
renderLHReport(); | ||
|
||
document.querySelector('button')?.addEventListener('click', () => { | ||
document.querySelector('button#reanalyze')?.addEventListener('click', () => { | ||
renderLHReport(); | ||
}); | ||
|
||
document.querySelector('button#translate')?.addEventListener('click', async () => { | ||
await swapLhrLocale('es'); | ||
renderLHReport(); | ||
}); | ||
})(); | ||
|
@@ -82,6 +87,22 @@ async function renderLHReport() { | |
} | ||
} | ||
|
||
/** | ||
* @param {LH.Locale} locale | ||
*/ | ||
async function swapLhrLocale(locale) { | ||
const response = await fetch(`https://www.gstatic.com/pagespeed/insights/ui/locales/${locale}.json`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the real thing, is the list of locales suggested in the UI generated from the actual locales available so it's not going to 404? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ideally, but there's no certainty the locales obj we have matches what's published here. but.. it should. I think what you may be pointing out is that we should do a |
||
/** @type {import('../../shared/localization/locales').LhlMessages} */ | ||
const lhlMessages = await response.json(); | ||
console.log(lhlMessages); | ||
if (!lhlMessages) throw new Error(`could not fetch data for locale: ${locale}`); | ||
|
||
lighthouseRenderer.format.registerLocaleData(locale, lhlMessages); | ||
// @ts-expect-error LHR global | ||
window.__LIGHTHOUSE_JSON__ = lighthouseRenderer.swapLocale(window.__LIGHTHOUSE_JSON__, locale) | ||
.lhr; | ||
} | ||
|
||
|
||
/** | ||
* Tweak the LHR to make the desktop and mobile reports easier to identify. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you do what build-bundle does instead? https://github.com/GoogleChrome/lighthouse/blob/master/build/build-bundle.js#L112
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I guess you need some dummy functions exported here.