viewpoint_cdp/protocol/runtime/
mod.rs

1//! Runtime domain types.
2//!
3//! The Runtime domain exposes JavaScript runtime by means of remote evaluation and mirror objects.
4
5use serde::{Deserialize, Serialize};
6
7/// Unique script identifier.
8pub type ScriptId = String;
9
10/// Unique execution context identifier.
11pub type ExecutionContextId = i64;
12
13/// Remote object value.
14#[derive(Debug, Clone, Deserialize)]
15#[serde(rename_all = "camelCase")]
16pub struct RemoteObject {
17    /// Object type.
18    #[serde(rename = "type")]
19    pub object_type: String,
20    /// Object subtype hint.
21    pub subtype: Option<String>,
22    /// Object class name.
23    pub class_name: Option<String>,
24    /// Remote object value.
25    pub value: Option<serde_json::Value>,
26    /// String representation of the object.
27    pub description: Option<String>,
28    /// Unique object identifier.
29    pub object_id: Option<String>,
30}
31
32/// Exception details.
33#[derive(Debug, Clone, Deserialize)]
34#[serde(rename_all = "camelCase")]
35pub struct ExceptionDetails {
36    /// Exception id.
37    pub exception_id: i64,
38    /// Exception text.
39    pub text: String,
40    /// Line number of the exception location.
41    pub line_number: i64,
42    /// Column number of the exception location.
43    pub column_number: i64,
44    /// Script ID of the exception location.
45    pub script_id: Option<ScriptId>,
46    /// URL of the exception location.
47    pub url: Option<String>,
48    /// Exception object if available.
49    pub exception: Option<RemoteObject>,
50    /// Execution context ID.
51    pub execution_context_id: Option<ExecutionContextId>,
52}
53
54/// Parameters for Runtime.evaluate.
55#[derive(Debug, Clone, Serialize)]
56#[serde(rename_all = "camelCase")]
57pub struct EvaluateParams {
58    /// Expression to evaluate.
59    pub expression: String,
60    /// Object group for the result.
61    #[serde(skip_serializing_if = "Option::is_none")]
62    pub object_group: Option<String>,
63    /// Whether to include command line API.
64    #[serde(skip_serializing_if = "Option::is_none")]
65    pub include_command_line_api: Option<bool>,
66    /// Whether to disable side effects.
67    #[serde(skip_serializing_if = "Option::is_none")]
68    pub silent: Option<bool>,
69    /// Execution context ID.
70    #[serde(skip_serializing_if = "Option::is_none")]
71    pub context_id: Option<ExecutionContextId>,
72    /// Whether to return by value.
73    #[serde(skip_serializing_if = "Option::is_none")]
74    pub return_by_value: Option<bool>,
75    /// Whether to await the promise.
76    #[serde(skip_serializing_if = "Option::is_none")]
77    pub await_promise: Option<bool>,
78}
79
80/// Result of Runtime.evaluate.
81#[derive(Debug, Clone, Deserialize)]
82#[serde(rename_all = "camelCase")]
83pub struct EvaluateResult {
84    /// Evaluation result.
85    pub result: RemoteObject,
86    /// Exception details if the evaluation threw.
87    pub exception_details: Option<ExceptionDetails>,
88}
89
90/// Event: Runtime.executionContextCreated
91#[derive(Debug, Clone, Deserialize)]
92pub struct ExecutionContextCreatedEvent {
93    /// Newly created execution context.
94    pub context: ExecutionContextDescription,
95}
96
97/// Execution context description.
98#[derive(Debug, Clone, Deserialize)]
99#[serde(rename_all = "camelCase")]
100pub struct ExecutionContextDescription {
101    /// Unique execution context id.
102    pub id: ExecutionContextId,
103    /// Execution context origin.
104    pub origin: String,
105    /// Human readable name describing given context.
106    pub name: String,
107}
108
109/// Event: Runtime.executionContextDestroyed
110#[derive(Debug, Clone, Deserialize)]
111#[serde(rename_all = "camelCase")]
112pub struct ExecutionContextDestroyedEvent {
113    /// ID of the destroyed context.
114    pub execution_context_id: ExecutionContextId,
115}
116
117// ============================================================================
118// Call Function On
119// ============================================================================
120
121/// Parameters for Runtime.callFunctionOn.
122#[derive(Debug, Clone, Serialize)]
123#[serde(rename_all = "camelCase")]
124pub struct CallFunctionOnParams {
125    /// Declaration of the function to call.
126    pub function_declaration: String,
127    /// Identifier of the object to call function on.
128    #[serde(skip_serializing_if = "Option::is_none")]
129    pub object_id: Option<String>,
130    /// Call arguments.
131    #[serde(skip_serializing_if = "Option::is_none")]
132    pub arguments: Option<Vec<CallArgument>>,
133    /// In silent mode exceptions thrown during evaluation are not reported.
134    #[serde(skip_serializing_if = "Option::is_none")]
135    pub silent: Option<bool>,
136    /// Whether the result is expected to be a JSON object.
137    #[serde(skip_serializing_if = "Option::is_none")]
138    pub return_by_value: Option<bool>,
139    /// Whether to generate preview for the result.
140    #[serde(skip_serializing_if = "Option::is_none")]
141    pub generate_preview: Option<bool>,
142    /// Whether execution should be treated as initiated by user in the UI.
143    #[serde(skip_serializing_if = "Option::is_none")]
144    pub user_gesture: Option<bool>,
145    /// Whether execution should await for resulting value.
146    #[serde(skip_serializing_if = "Option::is_none")]
147    pub await_promise: Option<bool>,
148    /// Specifies execution context which global object will be used.
149    #[serde(skip_serializing_if = "Option::is_none")]
150    pub execution_context_id: Option<ExecutionContextId>,
151    /// Symbolic group name that can be used to release multiple objects.
152    #[serde(skip_serializing_if = "Option::is_none")]
153    pub object_group: Option<String>,
154    /// Whether to throw an exception if side effect cannot be ruled out.
155    #[serde(skip_serializing_if = "Option::is_none")]
156    pub throw_on_side_effect: Option<bool>,
157    /// An alternative way to specify the execution context to call function on.
158    #[serde(skip_serializing_if = "Option::is_none")]
159    pub unique_context_id: Option<String>,
160    /// Specifies the result serialization.
161    #[serde(skip_serializing_if = "Option::is_none")]
162    pub serialization_options: Option<serde_json::Value>,
163}
164
165/// Call argument for callFunctionOn.
166#[derive(Debug, Clone, Serialize)]
167#[serde(rename_all = "camelCase")]
168pub struct CallArgument {
169    /// Primitive value or serializable javascript object.
170    #[serde(skip_serializing_if = "Option::is_none")]
171    pub value: Option<serde_json::Value>,
172    /// Primitive value which can not be JSON-stringified does not have value.
173    #[serde(skip_serializing_if = "Option::is_none")]
174    pub unserializable_value: Option<String>,
175    /// Remote object handle.
176    #[serde(skip_serializing_if = "Option::is_none")]
177    pub object_id: Option<String>,
178}
179
180/// Result of Runtime.callFunctionOn.
181#[derive(Debug, Clone, Deserialize)]
182#[serde(rename_all = "camelCase")]
183pub struct CallFunctionOnResult {
184    /// Call result.
185    pub result: RemoteObject,
186    /// Exception details if the call threw.
187    pub exception_details: Option<ExceptionDetails>,
188}
189
190// ============================================================================
191// Release Object
192// ============================================================================
193
194/// Parameters for Runtime.releaseObject.
195#[derive(Debug, Clone, Serialize)]
196#[serde(rename_all = "camelCase")]
197pub struct ReleaseObjectParams {
198    /// Identifier of the object to release.
199    pub object_id: String,
200}
201
202/// Parameters for Runtime.releaseObjectGroup.
203#[derive(Debug, Clone, Serialize)]
204#[serde(rename_all = "camelCase")]
205pub struct ReleaseObjectGroupParams {
206    /// Symbolic object group name.
207    pub object_group: String,
208}
209
210// ============================================================================
211// Get Properties
212// ============================================================================
213
214/// Parameters for Runtime.getProperties.
215#[derive(Debug, Clone, Serialize)]
216#[serde(rename_all = "camelCase")]
217pub struct GetPropertiesParams {
218    /// Identifier of the object to return properties for.
219    pub object_id: String,
220    /// If true, returns properties belonging only to the element itself.
221    #[serde(skip_serializing_if = "Option::is_none")]
222    pub own_properties: Option<bool>,
223    /// If true, returns accessor properties only.
224    #[serde(skip_serializing_if = "Option::is_none")]
225    pub accessor_properties_only: Option<bool>,
226    /// Whether preview should be generated for the results.
227    #[serde(skip_serializing_if = "Option::is_none")]
228    pub generate_preview: Option<bool>,
229    /// If true, returns non-indexed properties only.
230    #[serde(skip_serializing_if = "Option::is_none")]
231    pub non_indexed_properties_only: Option<bool>,
232}
233
234/// Property descriptor.
235#[derive(Debug, Clone, Deserialize)]
236#[serde(rename_all = "camelCase")]
237pub struct PropertyDescriptor {
238    /// Property name or symbol description.
239    pub name: String,
240    /// The value associated with the property.
241    pub value: Option<RemoteObject>,
242    /// True if the value associated with the property may be changed.
243    pub writable: Option<bool>,
244    /// A function which serves as a getter for the property.
245    pub get: Option<RemoteObject>,
246    /// A function which serves as a setter for the property.
247    pub set: Option<RemoteObject>,
248    /// True if the type of this property descriptor may be changed.
249    pub configurable: bool,
250    /// True if this property shows up during enumeration.
251    pub enumerable: bool,
252    /// True if the result was thrown during the evaluation.
253    pub was_thrown: Option<bool>,
254    /// True if the property is owned for the object.
255    pub is_own: Option<bool>,
256    /// Property symbol object.
257    pub symbol: Option<RemoteObject>,
258}
259
260/// Result of Runtime.getProperties.
261#[derive(Debug, Clone, Deserialize)]
262#[serde(rename_all = "camelCase")]
263pub struct GetPropertiesResult {
264    /// Object properties.
265    pub result: Vec<PropertyDescriptor>,
266    /// Internal object properties (only of the element itself).
267    pub internal_properties: Option<Vec<InternalPropertyDescriptor>>,
268    /// Object private properties.
269    pub private_properties: Option<Vec<PrivatePropertyDescriptor>>,
270    /// Exception details.
271    pub exception_details: Option<ExceptionDetails>,
272}
273
274/// Internal property descriptor.
275#[derive(Debug, Clone, Deserialize)]
276#[serde(rename_all = "camelCase")]
277pub struct InternalPropertyDescriptor {
278    /// Conventional property name.
279    pub name: String,
280    /// The value associated with the property.
281    pub value: Option<RemoteObject>,
282}
283
284/// Private property descriptor.
285#[derive(Debug, Clone, Deserialize)]
286#[serde(rename_all = "camelCase")]
287pub struct PrivatePropertyDescriptor {
288    /// Private property name.
289    pub name: String,
290    /// The value associated with the private property.
291    pub value: Option<RemoteObject>,
292    /// A function which serves as a getter for the private property.
293    pub get: Option<RemoteObject>,
294    /// A function which serves as a setter for the private property.
295    pub set: Option<RemoteObject>,
296}
297
298// ============================================================================
299// Binding
300// ============================================================================
301
302/// Parameters for Runtime.addBinding.
303#[derive(Debug, Clone, Serialize)]
304#[serde(rename_all = "camelCase")]
305pub struct AddBindingParams {
306    /// Binding name.
307    pub name: String,
308    /// If specified, the binding would only be exposed to the specified execution context.
309    #[serde(skip_serializing_if = "Option::is_none")]
310    pub execution_context_id: Option<ExecutionContextId>,
311    /// If specified, the binding is exposed to the given execution context name.
312    #[serde(skip_serializing_if = "Option::is_none")]
313    pub execution_context_name: Option<String>,
314}
315
316/// Parameters for Runtime.removeBinding.
317#[derive(Debug, Clone, Serialize)]
318pub struct RemoveBindingParams {
319    /// Binding name.
320    pub name: String,
321}
322
323/// Event: Runtime.bindingCalled
324#[derive(Debug, Clone, Deserialize)]
325#[serde(rename_all = "camelCase")]
326pub struct BindingCalledEvent {
327    /// Binding name.
328    pub name: String,
329    /// Binding payload.
330    pub payload: String,
331    /// Identifier of the context where the call was made.
332    pub execution_context_id: ExecutionContextId,
333}
334
335// ============================================================================
336// Console API Called Event
337// ============================================================================
338
339/// Console message type.
340#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
341#[serde(rename_all = "lowercase")]
342pub enum ConsoleApiType {
343    /// `console.log()`
344    Log,
345    /// `console.debug()`
346    Debug,
347    /// `console.info()`
348    Info,
349    /// `console.error()`
350    Error,
351    /// `console.warn()` / `console.warning()`
352    Warning,
353    /// `console.dir()`
354    Dir,
355    /// `console.dirxml()`
356    Dirxml,
357    /// `console.table()`
358    Table,
359    /// `console.trace()`
360    Trace,
361    /// `console.clear()`
362    Clear,
363    /// `console.count()`
364    Count,
365    /// `console.assert()`
366    Assert,
367    /// `console.profile()`
368    Profile,
369    /// `console.profileEnd()`
370    ProfileEnd,
371    /// `console.time()`
372    StartGroup,
373    /// `console.timeEnd()`
374    StartGroupCollapsed,
375    /// `console.groupEnd()`
376    EndGroup,
377    /// `console.timeLog()`
378    TimeEnd,
379}
380
381impl std::fmt::Display for ConsoleApiType {
382    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
383        let s = match self {
384            Self::Log => "log",
385            Self::Debug => "debug",
386            Self::Info => "info",
387            Self::Error => "error",
388            Self::Warning => "warning",
389            Self::Dir => "dir",
390            Self::Dirxml => "dirxml",
391            Self::Table => "table",
392            Self::Trace => "trace",
393            Self::Clear => "clear",
394            Self::Count => "count",
395            Self::Assert => "assert",
396            Self::Profile => "profile",
397            Self::ProfileEnd => "profileEnd",
398            Self::StartGroup => "startGroup",
399            Self::StartGroupCollapsed => "startGroupCollapsed",
400            Self::EndGroup => "endGroup",
401            Self::TimeEnd => "timeEnd",
402        };
403        write!(f, "{s}")
404    }
405}
406
407/// Stack trace entry.
408#[derive(Debug, Clone, Deserialize)]
409#[serde(rename_all = "camelCase")]
410pub struct CallFrame {
411    /// JavaScript function name.
412    pub function_name: String,
413    /// JavaScript script id.
414    pub script_id: ScriptId,
415    /// JavaScript script name or URL.
416    pub url: String,
417    /// JavaScript script line number (0-based).
418    pub line_number: i32,
419    /// JavaScript script column number (0-based).
420    pub column_number: i32,
421}
422
423/// Stack trace.
424#[derive(Debug, Clone, Deserialize)]
425#[serde(rename_all = "camelCase")]
426pub struct StackTrace {
427    /// String label of this stack trace.
428    pub description: Option<String>,
429    /// JavaScript function call frames.
430    pub call_frames: Vec<CallFrame>,
431    /// Asynchronous JavaScript stack trace that preceded this stack (if available).
432    pub parent: Option<Box<StackTrace>>,
433    /// Asynchronous JavaScript stack trace that preceded this stack (if available).
434    pub parent_id: Option<StackTraceId>,
435}
436
437/// Unique identifier of current debugger.
438#[derive(Debug, Clone, Deserialize)]
439#[serde(rename_all = "camelCase")]
440pub struct StackTraceId {
441    /// Unique id.
442    pub id: String,
443    /// Debugger id (only set when created by other debugger).
444    pub debugger_id: Option<String>,
445}
446
447/// Event: Runtime.consoleAPICalled
448///
449/// Issued when console API was called.
450#[derive(Debug, Clone, Deserialize)]
451#[serde(rename_all = "camelCase")]
452pub struct ConsoleApiCalledEvent {
453    /// Type of the call.
454    #[serde(rename = "type")]
455    pub call_type: ConsoleApiType,
456    /// Call arguments.
457    pub args: Vec<RemoteObject>,
458    /// Identifier of the context where the call was made.
459    pub execution_context_id: ExecutionContextId,
460    /// Call timestamp.
461    pub timestamp: f64,
462    /// Stack trace captured when the call was made.
463    pub stack_trace: Option<StackTrace>,
464    /// Console context descriptor for calls on non-default console context (not console.*):
465    /// 'anonymous#unique-logger-id' for call on unnamed context.
466    pub context: Option<String>,
467}
468
469// ============================================================================
470// Exception Thrown Event
471// ============================================================================
472
473/// Event: Runtime.exceptionThrown
474///
475/// Issued when exception was thrown and unhandled.
476#[derive(Debug, Clone, Deserialize)]
477#[serde(rename_all = "camelCase")]
478pub struct ExceptionThrownEvent {
479    /// Timestamp of the exception.
480    pub timestamp: f64,
481    /// Exception details.
482    pub exception_details: ExceptionDetails,
483}