Skip to content

Commit 52c54ce

Browse files
committed
fix(docs-infra): log more SW debug info
This commit expands the info printed to the console to help diagnose ServiceWorker issues to include the [internal debug info][1] retrieved from `/ngsw/state`. This will provide more useful data, such as the activated SW's version, state, clients, recent operations and any recent errors. NOTE: This temporarily increases the payload size. Removing this code and reclaiming the payload size is being tracked in #41117. [1]: https://angular.io/guide/service-worker-devops#locating-and-analyzing-debugging-information
1 parent ce1b25e commit 52c54ce

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

aio/src/app/layout/doc-viewer/doc-viewer.component.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,13 @@ export class DocViewerComponent implements OnDestroy {
260260
* (See https://github.com/angular/angular/issues/28114.)
261261
*/
262262
async function printSwDebugInfo(): Promise<void> {
263-
console.log(`\nServiceWorker: ${navigator.serviceWorker?.controller?.state ?? 'N/A'}`);
263+
const sep = '\n----------';
264+
const swState = navigator.serviceWorker?.controller?.state ?? 'N/A';
265+
266+
console.log(`\nServiceWorker: ${swState}`);
264267

265268
if (typeof caches === 'undefined') {
266-
console.log('\nCaches: N/A');
269+
console.log(`${sep}\nCaches: N/A`);
267270
} else {
268271
const allCacheNames = await caches.keys();
269272
const swCacheNames = allCacheNames.filter(name => name.startsWith('ngsw:/:'));
@@ -273,11 +276,28 @@ async function printSwDebugInfo(): Promise<void> {
273276
await findCachesAndPrintEntries(swCacheNames, 'assets:app-shell:meta', true);
274277
}
275278

279+
if (swState === 'activated') {
280+
console.log(sep);
281+
await fetchAndPrintSwInternalDebugInfo();
282+
}
283+
276284
console.warn(
277-
'\nIf you see this error, please report an issue at ' +
285+
`${sep}\nIf you see this error, please report an issue at ` +
278286
'https://github.com/angular/angular/issues/new?template=3-docs-bug.md including the above logs.');
279287

280288
// Internal helpers
289+
async function fetchAndPrintSwInternalDebugInfo() {
290+
try {
291+
const res = await fetch('/ngsw/state');
292+
if (!res.ok) {
293+
throw new Error(`Response ${res.status} ${res.statusText}`);
294+
}
295+
console.log(await res.text());
296+
} catch (err) {
297+
console.log(`Failed to retrieve debug info from '/ngsw/state': ${err.message || err}`);
298+
}
299+
}
300+
281301
async function findCachesAndPrintEntries(
282302
swCacheNames: string[], nameSuffix: string, includeValues: boolean,
283303
ignoredKeys: string[] = []): Promise<void> {

goldens/size-tracking/aio-payloads.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"master": {
44
"uncompressed": {
55
"runtime-es2017": 4841,
6-
"main-es2017": 458609,
6+
"main-es2017": 459014,
77
"polyfills-es2017": 55235,
88
"styles": 69213,
99
"light-theme": 79025,
@@ -15,7 +15,7 @@
1515
"master": {
1616
"uncompressed": {
1717
"runtime-es2017": 4841,
18-
"main-es2017": 458748,
18+
"main-es2017": 459153,
1919
"polyfills-es2017": 55373,
2020
"styles": 69213,
2121
"light-theme": 79025,

0 commit comments

Comments
 (0)