Skip to content

Commit

Permalink
[#7173] Prevent error on disabled performance API
Browse files Browse the repository at this point in the history
Signed-off-by: Knut Ahlers <knut@ahlers.me>
  • Loading branch information
Luzifer authored and akosyakov committed Feb 19, 2020
1 parent 00c1747 commit 33e1740
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/plugin-ext/src/hosted/browser/hosted-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,10 @@ export class HostedPluginSupport {
return () => {
performance.mark(endMarker);
performance.measure(name, startMarker, endMarker);
const duration = performance.getEntriesByName(name)[0].duration;

const entries = performance.getEntriesByName(name);
const duration = entries.length > 0 ? entries[0].duration : Number.NaN;

performance.clearMeasures(name);
performance.clearMarks(startMarker);
performance.clearMarks(endMarker);
Expand All @@ -594,8 +597,14 @@ export class HostedPluginSupport {
}

protected logMeasurement(prefix: string, count: number, measurement: () => number): void {
const duration = measurement();
if (duration === Number.NaN) {
// Measurement was prevented by native API, do not log NaN duration
return;
}

const pluginCount = `${count} plugin${count === 1 ? '' : 's'}`;
console.log(`[${this.clientId}] ${prefix} of ${pluginCount} took: ${measurement().toFixed(1)} ms`);
console.log(`[${this.clientId}] ${prefix} of ${pluginCount} took: ${duration.toFixed(1)} ms`);
}

protected readonly webviewsToRestore = new Set<WebviewWidget>();
Expand Down

0 comments on commit 33e1740

Please sign in to comment.