refactor(docs-infra): remove code that prints debug info (#46987)

In #41106, code was added in angular.io to print info that would help us
investigate and debug a ServiceWorker issue (#28114). Since the fix for
the issue was deployed on October 6th, 2021, the related error rate has
dropped dramatically:

![ChunkLoadError rate](https://user-images.githubusercontent.com/8604205/181502119-64ffb5de-f38e-4414-abcd-0fada29fd6d5.png)

Additionally, there have been no known occurrences or reports of the
issue in the last several months.

The remaining occurrences could be attributed to older versions still
being around on people's devices (due to the ServiceWorker caching) and
other circumstances not related to the ServiceWorker, for which there is
not much we can do. For example, a user could keep a tab open with an
older version of the app, which requests hashed files that no longer
exist on the server. If the ServiceWorker is not activated on such a tab
(either because the browser does not support it or because the user has
disabled it, for example), then it is expected that these requests would
fail.

This commit removes the code that prints ServiceWorker-related debug
info to reduce the payload size of the app.

Fixes #41117

PR Close #46987
This commit is contained in:
George Kalpakas
2022-07-28 15:01:42 +03:00
committed by Andrew Kushnir
parent 996071035b
commit f386cdb499
2 changed files with 2 additions and 90 deletions
@@ -156,13 +156,6 @@ export class DocViewerComponent implements OnDestroy {
this.nextViewContainer.textContent = '';
this.setNoIndex(true);
// TODO(gkalpak): Remove this once gathering debug info is no longer needed.
if (/loading chunk \S+ failed/i.test(errorMessage)) {
// Print some info to help with debugging.
// (There is no reason to wait for this async call to complete before continuing.)
printSwDebugInfo();
}
return this.void$;
}),
);
@@ -268,84 +261,3 @@ export class DocViewerComponent implements OnDestroy {
);
}
}
// Helpers
/**
* Print some info regarding the ServiceWorker and the caches contents to help debugging potential
* issues with failing to find resources in the cache.
* (See https://github.com/angular/angular/issues/28114.)
*/
async function printSwDebugInfo(): Promise<void> {
const sep = '\n----------';
const swState = navigator.serviceWorker?.controller?.state ?? 'N/A';
console.log(`\nServiceWorker: ${swState}`);
if (typeof caches === 'undefined') {
console.log(`${sep}\nCaches: N/A`);
} else {
const allCacheNames = await caches.keys();
const swCacheNames = allCacheNames.filter(name => name.startsWith('ngsw:/:'));
await findCachesAndPrintEntries(swCacheNames, 'db:control', true, ['manifests']);
await findCachesAndPrintEntries(swCacheNames, 'assets:app-shell:cache', false);
await findCachesAndPrintEntries(swCacheNames, 'assets:app-shell:meta', true);
}
if (swState === 'activated') {
console.log(sep);
await fetchAndPrintSwInternalDebugInfo();
}
console.warn(
`${sep}\nIf you see this error, please report an issue at ` +
'https://github.com/angular/angular/issues/new?template=3-docs-bug.md including the above logs.');
// Internal helpers
async function fetchAndPrintSwInternalDebugInfo() {
try {
const res = await fetch('/ngsw/state');
if (!res.ok) {
throw new Error(`Response ${res.status} ${res.statusText}`);
}
console.log(await res.text());
} catch (err) {
console.log(
`Failed to retrieve debug info from '/ngsw/state': ${(err as Error).message || err}`);
}
}
async function findCachesAndPrintEntries(
swCacheNames: string[], nameSuffix: string, includeValues: boolean,
ignoredKeys: string[] = []): Promise<void> {
const cacheNames = swCacheNames.filter(name => name.endsWith(nameSuffix));
for (const cacheName of cacheNames) {
const cacheEntries = await getCacheEntries(cacheName, includeValues, ignoredKeys);
await printCacheEntries(cacheName, cacheEntries);
}
}
async function getCacheEntries(name: string, includeValues: boolean, ignoredKeys: string[] = []):
Promise<{key: string, value?: unknown}[]> {
const ignoredUrls = new Set(ignoredKeys.map(key => new Request(key).url));
const cache = await caches.open(name);
const keys = (await cache.keys()).map(req => req.url).filter(url => !ignoredUrls.has(url));
const entries = await Promise.all(
keys.map(async key => ({
key,
value: !includeValues ? undefined : await (await cache.match(key))?.json(),
})));
return entries;
}
function printCacheEntries(name: string, entries: {key: string, value?: unknown}[]): void {
const entriesStr =
entries.map(({key, value}) => ` - ${key}${!value ? '' : `: ${JSON.stringify(value)}`}`)
.join('\n');
console.log(`\nCache: ${name} (${entries.length} entries)\n${entriesStr}`);
}
}
+2 -2
View File
@@ -2,7 +2,7 @@
"aio": {
"uncompressed": {
"runtime": 4325,
"main": 457028,
"main": 454820,
"polyfills": 33814,
"styles": 73640,
"light-theme": 78276,
@@ -12,7 +12,7 @@
"aio-local": {
"uncompressed": {
"runtime": 4325,
"main": 457651,
"main": 455179,
"polyfills": 33922,
"styles": 73640,
"light-theme": 78045,