Skip to content
File

Blob: src/workerd/io/cdp.capnp

17.1 KB
1# Copyright (c) 2017-2022 Cloudflare, Inc.
2# Licensed under the Apache 2.0 license found in the LICENSE file or at:
3# https://opensource.org/licenses/Apache-2.0
4 
5@0x9ac3aeb51d4b6d95;
6# capnp structures describing parts of Chrome DevTools Protocol that we need to handle manually.
7# These were initially autogenerated, but later tweaked manually so script is not included.
8 
9using Cxx = import "/capnp/c++.capnp";
10using Json = import "/capnp/compat/json.capnp";
11 
12$Cxx.namespace("workerd::cdp");
13$Cxx.allowCancellation;
14 
15enum LogType {
16 log @0;
17 debug @1 $Cxx.name("debug_"); # avoid collision with macro on Apple platforms
18 info @2;
19 error @3;
20 warning @4;
21}
22 
23struct Runtime {
24 # Runtime domain exposes JavaScript runtime by means of remote evaluation and mirror objects. Evaluation results are returned as mirror object that expose object type, string representation and unique identifier that can be used for further object reference. Original objects are maintained in memory unless they are either explicitly released or are released along with the other objects in their object group.
25 using ScriptId = Text; # Unique script identifier.
26 struct CallFrame {
27 # Stack entry for runtime errors and assertions.
28 functionName @0 :Text; # JavaScript function name.
29 scriptId @1 :ScriptId; # JavaScript script id.
30 url @2 :Text; # JavaScript script name or url.
31 lineNumber @3 :Int32; # JavaScript script line number (0-based).
32 columnNumber @4 :Int32; # JavaScript script column number (0-based).
33 }
34 struct StackTrace {
35 # Call frames for assertions or error messages.
36 description @0 :Text; # String label of this stack trace. For async traces this may be a name of the function that initiated the async call.
37 callFrames @1 :List(CallFrame); # JavaScript function name.
38 parent @2 :StackTrace; # Asynchronous JavaScript stack trace that preceded this stack, if available.
39 parentId @3 :StackTraceId; # Asynchronous JavaScript stack trace that preceded this stack, if available.
40 }
41 using UniqueDebuggerId = Text; # Unique identifier of current debugger.
42 struct StackTraceId {
43 # If `debuggerId` is set stack trace comes from another debugger and can be resolved there. This allows to track cross-debugger calls. See `Runtime.StackTrace` and `Debugger.paused` for usages.
44 id @0 :Text;
45 debuggerId @1 :UniqueDebuggerId;
46 }
47 
48 struct Event {
49 struct ConsoleApiCalled {
50 type @0 :LogType;
51 
52 args @1 :List(Arg);
53 struct Arg $Json.discriminator(name = "type") {
54 union {
55 undefined @0 :Void;
56 string :group $Json.flatten() {
57 value @1 :Text;
58 }
59 # TODO(someday): Other types.
60 }
61 }
62 
63 executionContextId @2 :UInt32;
64 timestamp @3 :Float64;
65 stackTrace @4 :StackTrace;
66 }
67 }
68}
69struct Page {
70 # Actions and events related to the inspected page belong to the page domain.
71 enum ResourceType {
72 # Resource type as it was perceived by the rendering engine.
73 document @0 $Json.name("Document");
74 stylesheet @1 $Json.name("Stylesheet");
75 image @2 $Json.name("Image");
76 media @3 $Json.name("Media");
77 font @4 $Json.name("Font");
78 script @5 $Json.name("Script");
79 textTrack @6 $Json.name("TextTrack");
80 xhr @7 $Json.name("XHR");
81 fetch @8 $Json.name("Fetch");
82 eventSource @9 $Json.name("EventSource");
83 webSocket @10 $Json.name("WebSocket");
84 manifest @11 $Json.name("Manifest");
85 other @12 $Json.name("Other");
86 }
87 using FrameId = Text; # Unique frame identifier.
88}
89struct Security {
90 # Security
91 using CertificateId = Int32; # An internal certificate ID value.
92 enum MixedContentType {
93 # A description of mixed content (HTTP resources on HTTPS pages), as defined by https://www.w3.org/TR/mixed-content/#categories
94 blockable @0;
95 optionallyBlockable @1 $Json.name("optionally-blockable");
96 none @2;
97 }
98 enum SecurityState {
99 # The security level of a page or resource.
100 unknown @0;
101 neutral @1;
102 insecure @2;
103 secure @3;
104 info @4;
105 }
106}
107struct Network {
108 # Network domain allows tracking network activities of the page. It exposes information about http, file, data and other requests and responses, their headers, bodies, timing, etc.
109 using LoaderId = Text; # Unique loader identifier.
110 using RequestId = Text; # Unique request identifier.
111 using TimeSinceEpoch = Float64; # UTC time in seconds, counted from January 1, 1970.
112 using MonotonicTime = Float64; # Monotonically increasing time in seconds since an arbitrary point in the past.
113 using Headers = Json.Value; # Request / response headers as keys / values of JSON object.
114 struct ResourceTiming {
115 # Timing information for the request.
116 requestTime @0 :Float64; # Timing's requestTime is a baseline in seconds, while the other numbers are ticks in milliseconds relatively to this requestTime.
117 proxyStart @1 :Float64; # Started resolving proxy.
118 proxyEnd @2 :Float64; # Finished resolving proxy.
119 dnsStart @3 :Float64; # Started DNS address resolve.
120 dnsEnd @4 :Float64; # Finished DNS address resolve.
121 connectStart @5 :Float64; # Started connecting to the remote host.
122 connectEnd @6 :Float64; # Connected to the remote host.
123 sslStart @7 :Float64; # Started SSL handshake.
124 sslEnd @8 :Float64; # Finished SSL handshake.
125 workerStart @9 :Float64; # Started running ServiceWorker.
126 workerReady @10 :Float64; # Finished Starting ServiceWorker.
127 sendStart @11 :Float64; # Started sending request.
128 sendEnd @12 :Float64; # Finished sending request.
129 pushStart @13 :Float64; # Time the server started pushing request.
130 pushEnd @14 :Float64; # Time the server finished pushing request.
131 receiveHeadersEnd @15 :Float64; # Finished receiving response headers.
132 }
133 enum ResourcePriority {
134 # Loading priority of a resource request.
135 veryLow @0 $Json.name("VeryLow");
136 low @1 $Json.name("Low");
137 medium @2 $Json.name("Medium");
138 high @3 $Json.name("High");
139 veryHigh @4 $Json.name("VeryHigh");
140 }
141 struct Request {
142 # HTTP request data.
143 url @0 :Text; # Request URL.
144 method @1 :Text; # HTTP request method.
145 headers @2 :Headers; # HTTP request headers.
146 postData @3 :Text; # HTTP POST request data.
147 mixedContentType @4 :Security.MixedContentType; # The mixed content type of the request.
148 initialPriority @5 :ResourcePriority; # Priority of the resource request at the time request is sent.
149 enum ReferrerPolicy {
150 # The referrer policy of the request, as defined in https://www.w3.org/TR/referrer-policy/
151 unsafeUrl @0 $Json.name("unsafe-url");
152 noReferrerWhenDowngrade @1 $Json.name("no-referrer-when-downgrade");
153 noReferrer @2 $Json.name("no-referrer");
154 origin @3;
155 originWhenCrossOrigin @4 $Json.name("origin-when-cross-origin");
156 sameOrigin @5 $Json.name("same-origin");
157 strictOrigin @6 $Json.name("strict-origin");
158 strictOriginWhenCrossOrigin @7 $Json.name("strict-origin-when-cross-origin");
159 }
160 referrerPolicy @6 :ReferrerPolicy; # The referrer policy of the request, as defined in https://www.w3.org/TR/referrer-policy/
161 isLinkPreload @7 :Bool; # Whether is loaded via link preload.
162 }
163 struct SignedCertificateTimestamp {
164 # Details of a signed certificate timestamp (SCT).
165 status @0 :Text; # Validation status.
166 origin @1 :Text; # Origin.
167 logDescription @2 :Text; # Log name / description.
168 logId @3 :Text; # Log ID.
169 timestamp @4 :TimeSinceEpoch; # Issuance date.
170 hashAlgorithm @5 :Text; # Hash algorithm.
171 signatureAlgorithm @6 :Text; # Signature algorithm.
172 signatureData @7 :Text; # Signature data.
173 }
174 struct SecurityDetails {
175 # Security details about a request.
176 protocol @0 :Text; # Protocol name (e.g. "TLS 1.2" or "QUIC").
177 keyExchange @1 :Text; # Key Exchange used by the connection, or the empty string if not applicable.
178 keyExchangeGroup @2 :Text; # (EC)DH group used by the connection, if applicable.
179 cipher @3 :Text; # Cipher name.
180 mac @4 :Text; # TLS MAC. Note that AEAD ciphers do not have separate MACs.
181 certificateId @5 :Security.CertificateId; # Certificate ID value.
182 subjectName @6 :Text; # Certificate subject name.
183 sanList @7 :List(Text); # Subject Alternative Name (SAN) DNS names and IP addresses.
184 issuer @8 :Text; # Name of the issuing CA.
185 validFrom @9 :TimeSinceEpoch; # Certificate valid from date.
186 validTo @10 :TimeSinceEpoch; # Certificate valid to (expiration) date
187 signedCertificateTimestampList @11 :List(SignedCertificateTimestamp); # List of signed certificate timestamps (SCTs).
188 }
189 struct Response {
190 # HTTP response data.
191 url @0 :Text; # Response URL. This URL can be different from CachedResource.url in case of redirect.
192 status @1 :Int32; # HTTP response status code.
193 statusText @2 :Text; # HTTP response status text.
194 headers @3 :Headers; # HTTP response headers.
195 headersText @4 :Text; # HTTP response headers text.
196 mimeType @5 :Text; # Resource mimeType as determined by the browser.
197 requestHeaders @6 :Headers; # Refined HTTP request headers that were actually transmitted over the network.
198 requestHeadersText @7 :Text; # HTTP request headers text.
199 connectionReused @8 :Bool; # Specifies whether physical connection was actually reused for this request.
200 connectionId @9 :Float64; # Physical connection id that was actually used for this request.
201 remoteIPAddress @10 :Text; # Remote IP address.
202 remotePort @11 :Int32; # Remote port.
203 fromDiskCache @12 :Bool; # Specifies that the request was served from the disk cache.
204 fromServiceWorker @13 :Bool; # Specifies that the request was served from the ServiceWorker.
205 encodedDataLength @14 :Float64; # Total number of bytes received for this request so far.
206 timing @15 :ResourceTiming; # Timing information for the given request.
207 protocol @16 :Text; # Protocol used to fetch this request.
208 securityState @17 :Security.SecurityState; # Security state of the request resource.
209 securityDetails @18 :SecurityDetails; # Security details for the request.
210 }
211 struct Initiator {
212 # Information about the request initiator.
213 enum Type {
214 # Type of this initiator.
215 parser @0;
216 script @1;
217 preload @2;
218 other @3;
219 }
220 type @0 :Type; # Type of this initiator.
221 stack @1 :Runtime.StackTrace; # Initiator JavaScript stack trace, set for Script only.
222 url @2 :Text; # Initiator URL, set for Parser type or for Script type (when script is importing module).
223 lineNumber @3 :Float64; # Initiator line number, set for Parser type or for Script type (when script is importing module) (0-based).
224 }
225 struct Command {
226 struct Enable {
227 # Enables network tracking, network events will now be delivered to the client.
228 struct Params {
229 maxTotalBufferSize @0 :Int32; # Buffer size in bytes to use when preserving network payloads (XHRs, etc).
230 maxResourceBufferSize @1 :Int32; # Per-resource buffer size in bytes to use when preserving network payloads (XHRs, etc).
231 }
232 struct Result {}
233 }
234 struct Disable {
235 # Disables network tracking, prevents network events from being sent to the client.
236 struct Params {}
237 struct Result {}
238 }
239 struct GetResponseBody {
240 # Returns content served for the given request.
241 struct Params {
242 requestId @0 :RequestId; # Identifier of the network request to get content for.
243 }
244 struct Result {
245 body @0 :Text; # Response body.
246 base64Encoded @1 :Bool; # True, if content was sent as base64.
247 }
248 }
249 }
250 struct Event {
251 struct RequestWillBeSent {
252 # Fired when page is about to send HTTP request.
253 requestId @0 :RequestId; # Request identifier.
254 loaderId @1 :LoaderId; # Loader identifier. Empty string if the request is fetched from worker.
255 documentURL @2 :Text; # URL of the document this request is loaded for.
256 request @3 :Request; # Request data.
257 timestamp @4 :MonotonicTime; # Timestamp.
258 wallTime @5 :TimeSinceEpoch; # Timestamp.
259 initiator @6 :Initiator; # Request initiator.
260 redirectResponse @7 :Response; # Redirect response data.
261 type @8 :Page.ResourceType; # Type of this resource.
262 frameId @9 :Page.FrameId; # Frame identifier.
263 }
264 struct ResponseReceived {
265 # Fired when HTTP response is available.
266 requestId @0 :RequestId; # Request identifier.
267 loaderId @1 :LoaderId; # Loader identifier. Empty string if the request is fetched from worker.
268 timestamp @2 :MonotonicTime; # Timestamp.
269 type @3 :Page.ResourceType; # Resource type.
270 response @4 :Response; # Response data.
271 frameId @5 :Page.FrameId; # Frame identifier.
272 }
273 struct DataReceived {
274 # Fired when data chunk was received over the network.
275 requestId @0 :RequestId; # Request identifier.
276 timestamp @1 :MonotonicTime; # Timestamp.
277 dataLength @2 :Int32; # Data chunk length.
278 encodedDataLength @3 :Int32; # Actual bytes received (might be less than dataLength for compressed encodings).
279 }
280 struct LoadingFinished {
281 # Fired when HTTP request has finished loading.
282 requestId @0 :RequestId; # Request identifier.
283 timestamp @1 :MonotonicTime; # Timestamp.
284 encodedDataLength @2 :Float64; # Total number of bytes received for this request.
285 cfResponse @3 :Command.GetResponseBody.Result; # Custom extension to send response body immediately to the client.
286 }
287 }
288}
289 
290struct Profiler {
291 
292 struct PositionTickInfo {
293 line @0 :Int32;
294 ticks @1 :Int32;
295 }
296 
297 struct ProfileNode {
298 id @0 :Int32;
299 callFrame @1 :Runtime.CallFrame;
300 hitCount @2 :Int32;
301 children @3 :List(Int32);
302 deoptReason @4 :Text;
303 positionTicks @5 :List(PositionTickInfo);
304 }
305 
306 struct Profile {
307 nodes @0 :List(ProfileNode);
308 startTime @1 :Float64;
309 endTime @2 :Float64;
310 samples @3 :List(Int32);
311 timeDeltas @4 :List(Int32);
312 }
313 
314 struct Command {
315 struct Enable {
316 struct Params {}
317 struct Result {}
318 }
319 struct SetSamplingInterval {
320 struct Params {
321 interval @0 :Int32;
322 }
323 struct Result {}
324 }
325 struct Start {
326 struct Params {}
327 struct Result {}
328 }
329 struct Stop {
330 struct Params {}
331 struct Result {
332 profile @0 :Profile;
333 }
334 }
335 }
336}
337 
338struct HeapProfiler {
339 struct Command {
340 struct TakeHeapSnapshot {
341 struct Params {
342 reportProgress @0 : Bool;
343 captureNumericValue @1 : Bool;
344 exposeInternals @2 : Bool;
345 }
346 struct Result {}
347 }
348 }
349 
350 struct Event {
351 struct AddHeapSnapshotChunk {
352 chunk @0 :Text;
353 }
354 struct ReportHeapSnapshotProgress {
355 done @0 : UInt32;
356 total @1 : UInt32;
357 finished @2 : Bool;
358 }
359 }
360}
361 
362struct Error {
363 code @0 :Int32;
364 message @1 :Text;
365}
366 
367struct Method(Params, Result) {
368 union {
369 params @0 :Params;
370 result @1 :Result;
371 error @2 :Error;
372 }
373}
374 
375struct Command $Json.discriminator(name = "method") {
376 id @0 :Int32;
377 union {
378 unknown @1 :Void;
379 networkEnable @2 :Method(Network.Command.Enable.Params, Network.Command.Enable.Result) $Json.name("Network.enable") $Json.flatten();
380 networkDisable @3 :Method(Network.Command.Disable.Params, Network.Command.Disable.Result) $Json.name("Network.disable") $Json.flatten();
381 networkGetResponseBody @4 :Method(Network.Command.GetResponseBody.Params, Network.Command.GetResponseBody.Result) $Json.name("Network.getResponseBody") $Json.flatten();
382 profilerSetSamplingInterval @5 :Method(Profiler.Command.SetSamplingInterval.Params, Profiler.Command.SetSamplingInterval.Result) $Json.name("Profiler.setSamplingInterval") $Json.flatten();
383 profilerEnable @6 :Method(Profiler.Command.Enable.Params, Profiler.Command.Enable.Result) $Json.name("Profiler.enable") $Json.flatten();
384 profilerStart @7 :Method(Profiler.Command.Start.Params, Profiler.Command.Start.Result) $Json.name("Profiler.start") $Json.flatten();
385 profilerStop @8 :Method(Profiler.Command.Stop.Params, Profiler.Command.Stop.Result) $Json.name("Profiler.stop") $Json.flatten();
386 takeHeapSnapshot @9 : Method(HeapProfiler.Command.TakeHeapSnapshot.Params, HeapProfiler.Command.TakeHeapSnapshot.Result) $Json.name("HeapProfiler.takeHeapSnapshot") $Json.flatten();
387 }
388}
389 
390struct Event $Json.discriminator(name = "method", valueName = "params") {
391 union {
392 networkRequestWillBeSent @0 :Network.Event.RequestWillBeSent $Json.name("Network.requestWillBeSent"); # Fired when page is about to send HTTP request.
393 networkResponseReceived @1 :Network.Event.ResponseReceived $Json.name("Network.responseReceived"); # Fired when HTTP response is available.
394 networkDataReceived @2 :Network.Event.DataReceived $Json.name("Network.dataReceived"); # Fired when data chunk was received over the network.
395 networkLoadingFinished @3 :Network.Event.LoadingFinished $Json.name("Network.loadingFinished"); # Fired when HTTP request has finished loading.
396 
397 runtimeConsoleApiCalled @4 :Runtime.Event.ConsoleApiCalled $Json.name("Runtime.consoleAPICalled");
398 
399 addHeapSnapshotChunk @5 :HeapProfiler.Event.AddHeapSnapshotChunk $Json.name("HeapProfiler.addHeapSnapshotChunk");
400 reportHeapSnapshotProgress @6 :HeapProfiler.Event.ReportHeapSnapshotProgress $Json.name("HeapProfiler.reportHeapSnapshotProgress");
401 }
402}