cdp-driver 0.5.0

Chrome DevTools Protocol (CDP) client for Rust: every command, event and type generated from the schema, with sessions, for browser automation and AI agents
Documentation
// @generated by `just generate-methods` from protocol/*.json.
// Do not edit by hand; edit xtask/ and regenerate.

//! This domain allows interacting with the browser to control PWAs.
//!
//! Types, command parameters and event payloads for the `PWA`
//! domain. The method-name constants for the same domain are in
//! [`crate::methods`].
//!
//! This domain is experimental and may change without notice.

use serde::{Deserialize, Serialize};

/// The following types are the replica of
/// <https://crsrc.org/c/chrome/browser/web_applications/proto/web_app_os_integration_state.proto;drc=9910d3be894c8f142c977ba1023f30a656bc13fc;l=67>
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct FileHandlerAccept {
    /// New name of the mimetype according to
    /// <https://www.iana.org/assignments/media-types/media-types.xhtml>
    #[serde(rename = "mediaType")]
    pub media_type: String,
    #[serde(rename = "fileExtensions")]
    pub file_extensions: Vec<String>,
}

#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct FileHandler {
    pub action: String,
    pub accepts: Vec<FileHandlerAccept>,
    #[serde(rename = "displayName")]
    pub display_name: String,
}

/// If user prefers opening the app in browser or an app window.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum DisplayMode {
    /// `standalone`
    #[serde(rename = "standalone")]
    Standalone,
    /// `browser`
    #[serde(rename = "browser")]
    Browser,
    /// A value this vendored schema does not list. Chrome adds values ahead of
    /// the published protocol, so an unrecognised one is kept as it arrived
    /// rather than failing the payload it came in.
    #[serde(untagged)]
    Unrecognized(String),
}

/// Returns the following OS state for the given manifest id.
///
/// Parameters of `PWA.getOsAppState`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetOsAppStateParams {
    /// The id from the webapp's manifest file, commonly it's the url of the site
    /// installing the webapp. See <https://web.dev/learn/pwa/web-app-manifest>.
    #[serde(rename = "manifestId")]
    pub manifest_id: String,
}

/// What `PWA.getOsAppState` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetOsAppStateReturns {
    #[serde(rename = "badgeCount")]
    pub badge_count: i64,
    #[serde(rename = "fileHandlers")]
    pub file_handlers: Vec<FileHandler>,
}

impl crate::typed::Command for GetOsAppStateParams {
    const METHOD: &'static str = "PWA.getOsAppState";
    type Returns = GetOsAppStateReturns;
}

/// Installs the given manifest identity, optionally using the given
/// installUrlOrBundleUrl IWA-specific install description: manifestId
/// corresponds to isolated-app:// + web_package::SignedWebBundleId File
/// installation mode: The installUrlOrBundleUrl can be either file:// or
/// http(s):// pointing to a signed web bundle (.swbn). In this case
/// SignedWebBundleId must correspond to The .swbn file's signing key. Dev
/// proxy installation mode: installUrlOrBundleUrl must be http(s):// that
/// serves dev mode IWA. web_package::SignedWebBundleId must be of type dev
/// proxy. The advantage of dev proxy mode is that all changes to IWA
/// automatically will be reflected in the running app without reinstallation.
/// To generate bundle id for proxy mode: 1. Generate 32 random bytes. 2. Add
/// a specific suffix at the end following the documentation
/// <https://github.com/WICG/isolated-web-apps/blob/main/Scheme.md#suffix> 3.
/// Encode the entire sequence using Base32 without padding. If Chrome is not
/// in IWA dev mode, the installation will fail, regardless of the state of
/// the allowlist.
///
/// Parameters of `PWA.install`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct InstallParams {
    #[serde(rename = "manifestId")]
    pub manifest_id: String,
    /// The location of the app or bundle overriding the one derived from the
    /// manifestId.
    #[serde(
        rename = "installUrlOrBundleUrl",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub install_url_or_bundle_url: Option<String>,
}

impl crate::typed::Command for InstallParams {
    const METHOD: &'static str = "PWA.install";
    type Returns = crate::typed::NoReturns;
}

/// Uninstalls the given manifest_id and closes any opened app windows.
///
/// Parameters of `PWA.uninstall`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct UninstallParams {
    #[serde(rename = "manifestId")]
    pub manifest_id: String,
}

impl crate::typed::Command for UninstallParams {
    const METHOD: &'static str = "PWA.uninstall";
    type Returns = crate::typed::NoReturns;
}

/// Launches the installed web app, or an url in the same web app instead of
/// the default start url if it is provided. Returns a page Target.TargetID
/// which can be used to attach to via Target.attachToTarget or similar APIs.
///
/// Parameters of `PWA.launch`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct LaunchParams {
    #[serde(rename = "manifestId")]
    pub manifest_id: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub url: Option<String>,
}

/// What `PWA.launch` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct LaunchReturns {
    /// ID of the tab target created as a result.
    #[serde(rename = "targetId")]
    pub target_id: crate::protocol::target::TargetId,
}

impl crate::typed::Command for LaunchParams {
    const METHOD: &'static str = "PWA.launch";
    type Returns = LaunchReturns;
}

/// Opens one or more local files from an installed web app identified by its
/// manifestId. The web app needs to have file handlers registered to process
/// the files. The API returns one or more page Target.TargetIDs which can be
/// used to attach to via Target.attachToTarget or similar APIs. If some files
/// in the parameters cannot be handled by the web app, they will be ignored.
/// If none of the files can be handled, this API returns an error. If no
/// files are provided as the parameter, this API also returns an error.
/// According to the definition of the file handlers in the manifest file, one
/// Target.TargetID may represent a page handling one or more files. The order
/// of the returned Target.TargetIDs is not guaranteed.
/// TODO(crbug.com/339454034): Check the existences of the input files.
///
/// Parameters of `PWA.launchFilesInApp`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct LaunchFilesInAppParams {
    #[serde(rename = "manifestId")]
    pub manifest_id: String,
    pub files: Vec<String>,
}

/// What `PWA.launchFilesInApp` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct LaunchFilesInAppReturns {
    /// IDs of the tab targets created as the result.
    #[serde(rename = "targetIds")]
    pub target_ids: Vec<crate::protocol::target::TargetId>,
}

impl crate::typed::Command for LaunchFilesInAppParams {
    const METHOD: &'static str = "PWA.launchFilesInApp";
    type Returns = LaunchFilesInAppReturns;
}

/// Opens the current page in its web app identified by the manifest id, needs
/// to be called on a page target. This function returns immediately without
/// waiting for the app to finish loading.
///
/// Parameters of `PWA.openCurrentPageInApp`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct OpenCurrentPageInAppParams {
    #[serde(rename = "manifestId")]
    pub manifest_id: String,
}

impl crate::typed::Command for OpenCurrentPageInAppParams {
    const METHOD: &'static str = "PWA.openCurrentPageInApp";
    type Returns = crate::typed::NoReturns;
}

/// Changes user settings of the web app identified by its manifestId. If the
/// app was not installed, this command returns an error. Unset parameters
/// will be ignored; unrecognized values will cause an error. Unlike the ones
/// defined in the manifest files of the web apps, these settings are provided
/// by the browser and controlled by the users, they impact the way the
/// browser handling the web apps. See the comment of each parameter.
///
/// Parameters of `PWA.changeAppUserSettings`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ChangeAppUserSettingsParams {
    #[serde(rename = "manifestId")]
    pub manifest_id: String,
    /// If user allows the links clicked on by the user in the app's scope, or
    /// extended scope if the manifest has scope extensions and the flags
    /// `DesktopPWAsLinkCapturingWithScopeExtensions` and
    /// `WebAppEnableScopeExtensions` are enabled. Note, the API does not support
    /// resetting the linkCapturing to the initial value, uninstalling and
    /// installing the web app again will reset it. TODO(crbug.com/339453269):
    /// Setting this value on ChromeOS is not supported yet.
    #[serde(
        rename = "linkCapturing",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub link_capturing: Option<bool>,
    #[serde(
        rename = "displayMode",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub display_mode: Option<DisplayMode>,
}

impl crate::typed::Command for ChangeAppUserSettingsParams {
    const METHOD: &'static str = "PWA.changeAppUserSettings";
    type Returns = crate::typed::NoReturns;
}