Packages

A browser automation tool and interface to the Chrome DevTools Protocol.

Current section

Files

Jump to
chrobot_extra src chrobot_extra protocol performance.gleam
Raw

src/chrobot_extra/protocol/performance.gleam

//// > ⚙️ This module was generated from the Chrome DevTools Protocol version **1.3**
//// ## Performance Domain
////
//// This protocol domain has no description.
////
//// [📖 View this domain on the DevTools Protocol API Docs](https://chromedevtools.github.io/devtools-protocol/1-3/Performance/)
// ---------------------------------------------------------------------------
// | !!!!!! This is an autogenerated file - Do not edit manually !!!!!! |
// | Run `codegen.sh` to regenerate. |
// ---------------------------------------------------------------------------
import chrobot_extra/chrome
import chrobot_extra/internal/utils
import gleam/dynamic/decode
import gleam/int
import gleam/json
import gleam/option
import gleam/result
/// Run-time execution metric.
pub type Metric {
Metric(
/// Metric name.
name: String,
/// Metric value.
value: Float,
)
}
@internal
pub fn encode__metric(value__: Metric) {
json.object([
#("name", json.string(value__.name)),
#("value", json.float(value__.value)),
])
}
@internal
pub fn decode__metric() {
{
use name <- decode.field("name", decode.string)
use value <- decode.field("value", decode.one_of(decode.float, [decode.int |> decode.map(int.to_float)]))
decode.success(Metric(name: name, value: value))
}
}
/// This type is not part of the protocol spec, it has been generated dynamically
/// to represent the response to the command `get_metrics`
pub type GetMetricsResponse {
GetMetricsResponse(
/// Current values for run-time metrics.
metrics: List(Metric),
)
}
@internal
pub fn decode__get_metrics_response() {
{
use metrics <- decode.field("metrics", decode.list(decode__metric()))
decode.success(GetMetricsResponse(metrics: metrics))
}
}
/// Disable collecting and reporting metrics.
///
pub fn disable(callback__) {
callback__("Performance.disable", option.None)
}
/// Enable collecting and reporting metrics.
///
/// Parameters:
/// - `time_domain` : Time domain to use for collecting and reporting duration metrics.
///
/// Returns:
///
pub fn enable(
callback__,
time_domain time_domain: option.Option(EnableTimeDomain),
) {
callback__(
"Performance.enable",
option.Some(json.object(
[]
|> utils.add_optional(time_domain, fn(inner_value__) {
#("timeDomain", encode__enable_time_domain(inner_value__))
}),
)),
)
}
/// This type is not part of the protocol spec, it has been generated dynamically
/// to represent the possible values of the enum property `timeDomain` of `enable`
pub type EnableTimeDomain {
EnableTimeDomainTimeTicks
EnableTimeDomainThreadTicks
}
@internal
pub fn encode__enable_time_domain(value__: EnableTimeDomain) {
case value__ {
EnableTimeDomainTimeTicks -> "timeTicks"
EnableTimeDomainThreadTicks -> "threadTicks"
}
|> json.string()
}
@internal
pub fn decode__enable_time_domain() {
{
use value__ <- decode.then(decode.string)
case value__ {
"timeTicks" -> decode.success(EnableTimeDomainTimeTicks)
"threadTicks" -> decode.success(EnableTimeDomainThreadTicks)
_ -> decode.failure(EnableTimeDomainTimeTicks, "valid enum property")
}
}
}
/// Retrieve current values of run-time metrics.
/// - `metrics` : Current values for run-time metrics.
///
pub fn get_metrics(callback__) {
use result__ <- result.try(callback__("Performance.getMetrics", option.None))
decode.run(result__, decode__get_metrics_response())
|> result.replace_error(chrome.ProtocolError)
}