diff --git a/shell/browser/api/electron_api_content_tracing.cc b/shell/browser/api/electron_api_content_tracing.cc index f7e64cb2bbccc..f44f2d849417a 100644 --- a/shell/browser/api/electron_api_content_tracing.cc +++ b/shell/browser/api/electron_api_content_tracing.cc @@ -77,15 +77,20 @@ void StopTracing(gin_helper::Promise promise, } }, std::move(promise), *file_path); - if (file_path) { + + auto* instance = TracingController::GetInstance(); + if (!instance->IsTracing()) { + std::move(resolve_or_reject) + .Run(absl::make_optional( + "Failed to stop tracing - no trace in progress")); + } else if (file_path) { auto split_callback = base::SplitOnceCallback(std::move(resolve_or_reject)); auto endpoint = TracingController::CreateFileEndpoint( *file_path, base::BindOnce(std::move(split_callback.first), absl::nullopt)); - if (!TracingController::GetInstance()->StopTracing(endpoint)) { + if (!instance->StopTracing(endpoint)) { std::move(split_callback.second) - .Run(absl::make_optional( - "Failed to stop tracing (was a trace in progress?)")); + .Run(absl::make_optional("Failed to stop tracing")); } } else { std::move(resolve_or_reject) diff --git a/spec/api-content-tracing-spec.ts b/spec/api-content-tracing-spec.ts index 38cc6ab8b3242..2d43de3e90192 100644 --- a/spec/api-content-tracing-spec.ts +++ b/spec/api-content-tracing-spec.ts @@ -114,7 +114,7 @@ ifdescribe(!(['arm', 'arm64', 'ia32'].includes(process.arch)))('contentTracing', }); it('rejects if no trace is happening', async () => { - await expect(contentTracing.stopRecording()).to.be.rejected(); + await expect(contentTracing.stopRecording()).to.be.rejectedWith('Failed to stop tracing - no trace in progress'); }); });