diff --git a/third_party/blink/renderer/core/layout/ng/custom/layout_worklet_global_scope.cc b/third_party/blink/renderer/core/layout/ng/custom/layout_worklet_global_scope.cc index 317d8921237102..68cbfca48a500c 100644 --- a/third_party/blink/renderer/core/layout/ng/custom/layout_worklet_global_scope.cc +++ b/third_party/blink/renderer/core/layout/ng/custom/layout_worklet_global_scope.cc @@ -59,6 +59,8 @@ void LayoutWorkletGlobalScope::Dispose() { ScriptController()->GetScriptState()); WorkletGlobalScope::Dispose(); + + NotifyContextDestroyed(); } // https://drafts.css-houdini.org/css-layout-api/#dom-layoutworkletglobalscope-registerlayout diff --git a/third_party/blink/renderer/core/workers/worker_or_worklet_global_scope.cc b/third_party/blink/renderer/core/workers/worker_or_worklet_global_scope.cc index 2acf0a5b1806b6..817795e5c4acb9 100644 --- a/third_party/blink/renderer/core/workers/worker_or_worklet_global_scope.cc +++ b/third_party/blink/renderer/core/workers/worker_or_worklet_global_scope.cc @@ -257,6 +257,14 @@ bool WorkerOrWorkletGlobalScope::HasPendingActivity() const { void WorkerOrWorkletGlobalScope::CountUse(WebFeature feature) { DCHECK(IsContextThread()); + + // `reporting_proxy_` should outlive `this` but there seems a situation where + // the assumption is broken. Don't count features while the context is + // destroyed. + // TODO(https://crbug.com/1298450): Fix the lifetime of WorkerReportingProxy. + if (IsContextDestroyed()) + return; + DCHECK_NE(WebFeature::kOBSOLETE_PageDestruction, feature); DCHECK_GT(WebFeature::kNumberOfFeatures, feature); if (used_features_[static_cast(feature)]) diff --git a/third_party/blink/renderer/modules/csspaint/paint_worklet_global_scope.cc b/third_party/blink/renderer/modules/csspaint/paint_worklet_global_scope.cc index aa19afd767c052..df8078f007b03a 100644 --- a/third_party/blink/renderer/modules/csspaint/paint_worklet_global_scope.cc +++ b/third_party/blink/renderer/modules/csspaint/paint_worklet_global_scope.cc @@ -147,6 +147,12 @@ void PaintWorkletGlobalScope::Dispose() { ScriptController()->GetScriptState()); } WorkletGlobalScope::Dispose(); + + if (WTF::IsMainThread()) { + // For off-the-main-thread paint worklet, this will be called in + // WorkerThread::PrepareForShutdownOnWorkerThread(). + NotifyContextDestroyed(); + } } void PaintWorkletGlobalScope::registerPaint(const ScriptState* script_state,