{"record":{"id":"822d9aca775761fa","repo":"dotnet/runtime","slug":"no-active-js-diagnostic-session-822d9a","errorCode":null,"errorMessage":"No active JS diagnostic session","messagePattern":"No active JS diagnostic session","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mono/browser/runtime/diagnostics/dotnet-cpu-profiler.ts","lineNumber":14,"sourceCode":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n\nimport type { DiagnosticCommandOptions } from \"../types\";\n\nimport { commandStopTracing, commandSampleProfiler } from \"./client-commands\";\nimport { loaderHelpers, Module, runtimeHelpers } from \"./globals\";\nimport { serverSession, setupJsClient } from \"./diagnostics-js\";\nimport { IDiagnosticSession } from \"./common\";\n\nexport function collectCpuSamples (options?:DiagnosticCommandOptions):Promise<Uint8Array[]> {\n    if (!options) options = {};\n    if (!serverSession) {\n        throw new Error(\"No active JS diagnostic session\");\n    }\n    if (!runtimeHelpers.config.environmentVariables![\"DOTNET_WasmPerformanceInstrumentation\"]) {\n        throw new Error(\"method instrumentation is not enabled, please enable it with WasmPerformanceInstrumentation MSBuild property\");\n    }\n\n    const onClosePromise = loaderHelpers.createPromiseController<Uint8Array[]>();\n    function onSessionStart (session: IDiagnosticSession): void {\n        // stop tracing after period of monitoring\n        Module.safeSetTimeout(() => {\n            session.sendCommand(commandStopTracing(session.session_id));\n        }, 1000 * (options?.durationSeconds ?? 60));\n    }\n\n    setupJsClient({\n        onClosePromise:onClosePromise.promise_control,\n        skipDownload:options.skipDownload,\n        commandOnAdvertise: () => commandSampleProfiler(options),\n        onSessionStart,","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/mono/browser/runtime/diagnostics/dotnet-cpu-profiler.ts#L1-L32","documentation":"Thrown by collectCpuSamples() (dotnet-cpu-profiler) in diagnostics/dotnet-cpu-profiler.ts when serverSession is undefined. Same precondition as the other collectors: an in-browser diagnostic server session must already exist for the profiler to send its sampling commands.","triggerScenarios":"Calling API.collectCpuSamples() before the .NET diagnostic server advertised, or when diagnostics were not enabled.","commonSituations":"Profiling too early at startup. A build without the diagnostic server. Diagnostics disabled via configuration.","solutions":["Ensure the runtime is ready and the diagnostic server has established a session before profiling.","Enable diagnostics in the build and trigger a session (js://cpu-samples scenario or DOTNET_DiagnosticPorts).","Wait for serverSession to be non-null (the advertise handshake) before calling collectCpuSamples."],"exampleFix":"null","handlingStrategy":"validation","validationCode":"import { serverSession } from \"./diagnostics-js\";\nasync function collectCpuSamplesSafe(opts?: DiagnosticCommandOptions) {\n  if (!serverSession) throw new Error('No diagnostic session yet; start one before profiling.');\n  return collectCpuSamples(opts);\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Ensure a diagnostic session is advertised before profiling.","Enable WasmPerformanceInstrumentation AND a diagnostic session."],"tags":["diagnostics","dotnet-cpu-profiler","session","ordering"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}