Skip to content

Commit 41f3a68

Browse files
jcscottiiiDevtools-frontend LUCI CQ
authored andcommitted
DevTools: Add CrashReportContext SDK Model
This CL introduces the `CrashReportContextModel` to the DevTools SDK layer. This model is responsible for communicating with the backend via the protocol to fetch and manage the crash report context payload. Building this data layer independently allows us to cleanly separate the backend state lifecycle from the UI rendering logic. Tests are included to verify correct state instantiation and protocol communication. Bug: 400432195 Change-Id: Ib82a3b91f3c73315cc5610d0fc54d3bbaa39f556 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7709032 Reviewed-by: Danil Somsikov <dsv@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
1 parent 27f777f commit 41f3a68

6 files changed

Lines changed: 101 additions & 0 deletions

File tree

config/gni/devtools_grd_files.gni

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,7 @@ grd_files_unbundled_sources = [
992992
"front_end/core/sdk/Cookie.js",
993993
"front_end/core/sdk/CookieModel.js",
994994
"front_end/core/sdk/CookieParser.js",
995+
"front_end/core/sdk/CrashReportContextModel.js",
995996
"front_end/core/sdk/DOMDebuggerModel.js",
996997
"front_end/core/sdk/DOMModel.js",
997998
"front_end/core/sdk/DebuggerModel.js",

front_end/core/protocol_client/InspectorBackend.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ export class TargetBase {
351351
return this.getAgent('CacheStorage');
352352
}
353353

354+
crashReportContextAgent(): ProtocolProxyApi.CrashReportContextApi {
355+
return this.getAgent('CrashReportContext');
356+
}
357+
354358
cssAgent(): ProtocolProxyApi.CSSApi {
355359
return this.getAgent('CSS');
356360
}

front_end/core/sdk/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ devtools_module("sdk") {
4040
"Cookie.ts",
4141
"CookieModel.ts",
4242
"CookieParser.ts",
43+
"CrashReportContextModel.ts",
4344
"DOMDebuggerModel.ts",
4445
"DOMModel.ts",
4546
"DebuggerModel.ts",
@@ -158,6 +159,7 @@ ts_library("unittests") {
158159
"Cookie.test.ts",
159160
"CookieModel.test.ts",
160161
"CookieParser.test.ts",
162+
"CrashReportContextModel.test.ts",
161163
"DOMModel.test.ts",
162164
"EmulationModel.test.ts",
163165
"EnhancedTracesParser.test.ts",
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2026 The Chromium Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import type * as Protocol from '../../generated/protocol.js';
6+
import {createTarget} from '../../testing/EnvironmentHelpers.js';
7+
import {describeWithMockConnection, setMockConnectionResponseHandler} from '../../testing/MockConnection.js';
8+
9+
import * as SDK from './sdk.js';
10+
11+
describeWithMockConnection('CrashReportContextModel', () => {
12+
let model: SDK.CrashReportContextModel.CrashReportContextModel;
13+
14+
beforeEach(() => {
15+
const target = createTarget();
16+
model = target.model(SDK.CrashReportContextModel.CrashReportContextModel)!;
17+
assert.exists(model);
18+
});
19+
20+
it('can retrieve entries', async () => {
21+
const frameId = 'frame-1' as Protocol.Page.FrameId;
22+
setMockConnectionResponseHandler('CrashReportContext.getEntries', () => {
23+
return {
24+
entries: [
25+
{key: 'key1', value: 'value1', frameId},
26+
{key: 'key2', value: 'value2', frameId},
27+
],
28+
};
29+
});
30+
31+
const entries = await model.getEntries();
32+
assert.exists(entries);
33+
assert.lengthOf(entries, 2);
34+
assert.strictEqual(entries[0].key, 'key1');
35+
assert.strictEqual(entries[0].value, 'value1');
36+
assert.strictEqual(entries[0].frameId, 'frame-1');
37+
assert.strictEqual(entries[1].key, 'key2');
38+
assert.strictEqual(entries[1].value, 'value2');
39+
assert.strictEqual(entries[1].frameId, 'frame-1');
40+
});
41+
42+
it('handles empty entries', async () => {
43+
setMockConnectionResponseHandler('CrashReportContext.getEntries', () => {
44+
return {
45+
entries: [],
46+
};
47+
});
48+
49+
const entries = await model.getEntries();
50+
assert.exists(entries);
51+
assert.lengthOf(entries, 0);
52+
});
53+
54+
it('returns null on protocol error', async () => {
55+
setMockConnectionResponseHandler('CrashReportContext.getEntries', () => {
56+
return {
57+
getError: () => 'Feature disabled',
58+
};
59+
});
60+
61+
const entries = await model.getEntries();
62+
assert.isNull(entries);
63+
});
64+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2026 The Chromium Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import type * as ProtocolProxyApi from '../../generated/protocol-proxy-api.js';
6+
import type * as Protocol from '../../generated/protocol.js';
7+
8+
import {SDKModel} from './SDKModel.js';
9+
import {Capability, type Target} from './Target.js';
10+
11+
export class CrashReportContextModel extends SDKModel<void> {
12+
readonly #agent: ProtocolProxyApi.CrashReportContextApi;
13+
14+
constructor(target: Target) {
15+
super(target);
16+
this.#agent = target.crashReportContextAgent();
17+
}
18+
19+
async getEntries(): Promise<Protocol.CrashReportContext.CrashReportContextEntry[]|null> {
20+
const response = await this.#agent.invoke_getEntries();
21+
if (response.getError()) {
22+
return null;
23+
}
24+
return response.entries;
25+
}
26+
}
27+
28+
SDKModel.register(CrashReportContextModel, {capabilities: Capability.JS, autostart: false});

front_end/core/sdk/sdk.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import * as CookieModel from './CookieModel.js';
2222
import * as CookieParser from './CookieParser.js';
2323
import * as CPUProfilerModel from './CPUProfilerModel.js';
2424
import * as CPUThrottlingManager from './CPUThrottlingManager.js';
25+
import * as CrashReportContextModel from './CrashReportContextModel.js';
2526
import * as CSSContainerQuery from './CSSContainerQuery.js';
2627
import * as CSSFontFace from './CSSFontFace.js';
2728
import * as CSSLayer from './CSSLayer.js';
@@ -105,6 +106,7 @@ export {
105106
CookieParser,
106107
CPUProfilerModel,
107108
CPUThrottlingManager,
109+
CrashReportContextModel,
108110
CSSContainerQuery,
109111
CSSFontFace,
110112
CSSLayer,

0 commit comments

Comments
 (0)