Skip to content
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

[#7173] Prevent error on disabled performance API #7175

Merged
merged 1 commit into from
Feb 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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