├── .github └── workflows │ ├── rust.yml │ └── semgrep.yml ├── .gitignore ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── RELEASE_CHECKLIST.md └── src ├── domain ├── mod.rs └── runtime │ ├── event │ ├── console_api_called.rs │ └── mod.rs │ ├── method │ ├── get_isolate_id.rs │ ├── mod.rs │ └── type.rs │ ├── mod.rs │ └── type │ ├── mod.rs │ └── remote_object │ ├── mod.rs │ └── type │ ├── mod.rs │ └── object │ ├── entry_preview.rs │ ├── mod.rs │ ├── object_preview │ ├── mod.rs │ └── subtype.rs │ └── property_preview.rs └── lib.rs /.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | name: Rust 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v1 12 | - name: Build 13 | run: cargo build --verbose 14 | - name: Run tests 15 | run: cargo test --verbose 16 | - name: Run clippy 17 | uses: actions-rs/clippy-check@v1.0.5 18 | with: 19 | token: ${{ secrets.GITHUB_TOKEN }} 20 | args: --all --all-features -- -D warnings 21 | 22 | -------------------------------------------------------------------------------- /.github/workflows/semgrep.yml: -------------------------------------------------------------------------------- 1 | 2 | on: 3 | pull_request: {} 4 | workflow_dispatch: {} 5 | push: 6 | branches: 7 | - main 8 | - master 9 | schedule: 10 | - cron: '0 0 * * *' 11 | name: Semgrep config 12 | jobs: 13 | semgrep: 14 | name: semgrep/ci 15 | runs-on: ubuntu-20.04 16 | env: 17 | SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }} 18 | SEMGREP_URL: https://cloudflare.semgrep.dev 19 | SEMGREP_APP_URL: https://cloudflare.semgrep.dev 20 | SEMGREP_VERSION_CHECK_URL: https://cloudflare.semgrep.dev/api/check-version 21 | container: 22 | image: returntocorp/semgrep 23 | steps: 24 | - uses: actions/checkout@v3 25 | - run: semgrep ci 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | **/*.rs.bk -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## ↔️ 0.0.0-alpha.3 4 | 5 | ### 🔌 Fixes 6 | 7 | - **Made RemoteObject derive Clone and increased size of timestamp in RemoteObject - [jspspike], [pull/51]** 8 | 9 | [jspspike]: https://github.com/jspspike 10 | [pull/40]: https://github.com/cloudflare/chrome-devtools-rs/pull/51 11 | 12 | ## 👽 0.0.0-alpha.2 13 | 14 | ### 🔌 Features 15 | 16 | - **Line numbers for exception thrown - [nataliescottdavidson], [pull/48]** 17 | 18 | [nataliescottdavidson]: https://github.com/nataliescottdavidson 19 | [pull/48]: https://github.com/cloudflare/chrome-devtools-rs/pull/48 20 | 21 | ## 🌈 0.0.0-alpha.1 22 | 23 | ### 🔌 Features 24 | 25 | - **Unescape escape sequences in Strings - [jspspike], [pull/40]** 26 | 27 | The Chrome Devtools Protocol will include escape sequences in the messages 28 | containing strings. In order to display these properly, we now unescape those 29 | sequences, resulting in much better looking output in the terminal. 30 | 31 | [jspspike]: https://github.com/jspspike 32 | [pull/40]: https://github.com/EverlastingBugstopper/chrome-devtools-rs/pull/40 33 | 34 | ### 👏 Fixes 35 | 36 | - **Adds accessor type to `RemoteObject` - [jspspike], [pull/38]** 37 | 38 | The `RemoteObject` type did not previously have the `accessor` type, which 39 | meant certain console calls would fail to deserialize. Now `RemoteObject` can 40 | parse messages with `accessor`! 41 | 42 | [jspspike]: https://github.com/jspspike 43 | [pull/38]: https://github.com/EverlastingBugstopper/chrome-devtools-rs/pull/38 44 | 45 | - **Don't color strings if color feature is not enabled - 46 | [EverlastingBugstopper], [pull/36]** 47 | 48 | You can build this crate with the `color` feature and it will display 49 | console.log calls with color. Before, it would do this even if you didn't pass 50 | the `color` feature, now the feature flag works as intended. 51 | 52 | [EverlastingBugstopper]: https://github.com/EverlastingBugstopper 53 | [pull/36]: https://github.com/EverlastingBugstopper/chrome-devtools-rs/pull/36 54 | 55 | ### 🔨 Maintenance 56 | 57 | - **Updated dependencies - [EverlastingBugstopper], [pull/41]** 58 | 59 | [EverlastingBugstopper]: https://github.com/EverlastingBugstopper 60 | [pull/41]: https://github.com/EverlastingBugstopper/chrome-devtools-rs/pull/41 61 | 62 | ## 💩 0.0.0-alpha.0 63 | 64 | - **First release - [EverlastingBugstopper]** 65 | 66 | First release of this crate only contains functionality for deserializing and 67 | displaying calls to console.log. 68 | 69 | [EverlastingBugstopper]: https://github.com/EverlastingBugstopper 70 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. 8 | 9 | ## Our Standards 10 | 11 | Examples of behavior that contributes to a positive environment for our community include: 12 | 13 | * Demonstrating empathy and kindness toward other people 14 | * Being respectful of differing opinions, viewpoints, and experiences 15 | * Giving and gracefully accepting constructive feedback 16 | * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience 17 | * Focusing on what is best not just for us as individuals, but for the overall community 18 | 19 | Examples of unacceptable behavior include: 20 | 21 | * The use of sexualized language or imagery, and sexual attention or 22 | advances of any kind 23 | * Trolling, insulting or derogatory comments, and personal or political attacks 24 | * Public or private harassment 25 | * Publishing others' private information, such as a physical or email 26 | address, without their explicit permission 27 | * Other conduct which could reasonably be considered inappropriate in a 28 | professional setting 29 | 30 | ## Enforcement Responsibilities 31 | 32 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. 33 | 34 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. 35 | 36 | ## Scope 37 | 38 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. 39 | 40 | ## Enforcement 41 | 42 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [INSERT CONTACT METHOD]. All complaints will be reviewed and investigated promptly and fairly. 43 | 44 | All community leaders are obligated to respect the privacy and security of the reporter of any incident. 45 | 46 | ## Enforcement Guidelines 47 | 48 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: 49 | 50 | ### 1. Correction 51 | 52 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. 53 | 54 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. 55 | 56 | ### 2. Warning 57 | 58 | **Community Impact**: A violation through a single incident or series of actions. 59 | 60 | **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. 61 | 62 | ### 3. Temporary Ban 63 | 64 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. 65 | 66 | **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. 67 | 68 | ### 4. Permanent Ban 69 | 70 | **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. 71 | 72 | **Consequence**: A permanent ban from any sort of public interaction within the project community. 73 | 74 | ## Attribution 75 | 76 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, 77 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 78 | 79 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). 80 | 81 | [homepage]: https://www.contributor-covenant.org 82 | 83 | For answers to common questions about this code of conduct, see the FAQ at 84 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. 85 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "cfg-if" 5 | version = "1.0.0" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 8 | 9 | [[package]] 10 | name = "chrome-devtools-rs" 11 | version = "0.0.0-alpha.3" 12 | dependencies = [ 13 | "console", 14 | "log", 15 | "serde", 16 | "serde_json", 17 | "unescape", 18 | ] 19 | 20 | [[package]] 21 | name = "console" 22 | version = "0.11.3" 23 | source = "registry+https://github.com/rust-lang/crates.io-index" 24 | checksum = "8c0994e656bba7b922d8dd1245db90672ffb701e684e45be58f20719d69abc5a" 25 | dependencies = [ 26 | "encode_unicode", 27 | "lazy_static", 28 | "libc", 29 | "regex", 30 | "terminal_size", 31 | "termios", 32 | "unicode-width", 33 | "winapi", 34 | "winapi-util", 35 | ] 36 | 37 | [[package]] 38 | name = "encode_unicode" 39 | version = "0.3.6" 40 | source = "registry+https://github.com/rust-lang/crates.io-index" 41 | checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" 42 | 43 | [[package]] 44 | name = "itoa" 45 | version = "0.4.7" 46 | source = "registry+https://github.com/rust-lang/crates.io-index" 47 | checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" 48 | 49 | [[package]] 50 | name = "lazy_static" 51 | version = "1.4.0" 52 | source = "registry+https://github.com/rust-lang/crates.io-index" 53 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 54 | 55 | [[package]] 56 | name = "libc" 57 | version = "0.2.98" 58 | source = "registry+https://github.com/rust-lang/crates.io-index" 59 | checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790" 60 | 61 | [[package]] 62 | name = "log" 63 | version = "0.4.14" 64 | source = "registry+https://github.com/rust-lang/crates.io-index" 65 | checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" 66 | dependencies = [ 67 | "cfg-if", 68 | ] 69 | 70 | [[package]] 71 | name = "proc-macro2" 72 | version = "1.0.27" 73 | source = "registry+https://github.com/rust-lang/crates.io-index" 74 | checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" 75 | dependencies = [ 76 | "unicode-xid", 77 | ] 78 | 79 | [[package]] 80 | name = "quote" 81 | version = "1.0.9" 82 | source = "registry+https://github.com/rust-lang/crates.io-index" 83 | checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" 84 | dependencies = [ 85 | "proc-macro2", 86 | ] 87 | 88 | [[package]] 89 | name = "regex" 90 | version = "1.5.4" 91 | source = "registry+https://github.com/rust-lang/crates.io-index" 92 | checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" 93 | dependencies = [ 94 | "regex-syntax", 95 | ] 96 | 97 | [[package]] 98 | name = "regex-syntax" 99 | version = "0.6.25" 100 | source = "registry+https://github.com/rust-lang/crates.io-index" 101 | checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" 102 | 103 | [[package]] 104 | name = "ryu" 105 | version = "1.0.5" 106 | source = "registry+https://github.com/rust-lang/crates.io-index" 107 | checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" 108 | 109 | [[package]] 110 | name = "serde" 111 | version = "1.0.126" 112 | source = "registry+https://github.com/rust-lang/crates.io-index" 113 | checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03" 114 | dependencies = [ 115 | "serde_derive", 116 | ] 117 | 118 | [[package]] 119 | name = "serde_derive" 120 | version = "1.0.126" 121 | source = "registry+https://github.com/rust-lang/crates.io-index" 122 | checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43" 123 | dependencies = [ 124 | "proc-macro2", 125 | "quote", 126 | "syn", 127 | ] 128 | 129 | [[package]] 130 | name = "serde_json" 131 | version = "1.0.64" 132 | source = "registry+https://github.com/rust-lang/crates.io-index" 133 | checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" 134 | dependencies = [ 135 | "itoa", 136 | "ryu", 137 | "serde", 138 | ] 139 | 140 | [[package]] 141 | name = "syn" 142 | version = "1.0.73" 143 | source = "registry+https://github.com/rust-lang/crates.io-index" 144 | checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" 145 | dependencies = [ 146 | "proc-macro2", 147 | "quote", 148 | "unicode-xid", 149 | ] 150 | 151 | [[package]] 152 | name = "terminal_size" 153 | version = "0.1.17" 154 | source = "registry+https://github.com/rust-lang/crates.io-index" 155 | checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" 156 | dependencies = [ 157 | "libc", 158 | "winapi", 159 | ] 160 | 161 | [[package]] 162 | name = "termios" 163 | version = "0.3.3" 164 | source = "registry+https://github.com/rust-lang/crates.io-index" 165 | checksum = "411c5bf740737c7918b8b1fe232dca4dc9f8e754b8ad5e20966814001ed0ac6b" 166 | dependencies = [ 167 | "libc", 168 | ] 169 | 170 | [[package]] 171 | name = "unescape" 172 | version = "0.1.0" 173 | source = "registry+https://github.com/rust-lang/crates.io-index" 174 | checksum = "ccb97dac3243214f8d8507998906ca3e2e0b900bf9bf4870477f125b82e68f6e" 175 | 176 | [[package]] 177 | name = "unicode-width" 178 | version = "0.1.8" 179 | source = "registry+https://github.com/rust-lang/crates.io-index" 180 | checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" 181 | 182 | [[package]] 183 | name = "unicode-xid" 184 | version = "0.2.2" 185 | source = "registry+https://github.com/rust-lang/crates.io-index" 186 | checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" 187 | 188 | [[package]] 189 | name = "winapi" 190 | version = "0.3.9" 191 | source = "registry+https://github.com/rust-lang/crates.io-index" 192 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 193 | dependencies = [ 194 | "winapi-i686-pc-windows-gnu", 195 | "winapi-x86_64-pc-windows-gnu", 196 | ] 197 | 198 | [[package]] 199 | name = "winapi-i686-pc-windows-gnu" 200 | version = "0.4.0" 201 | source = "registry+https://github.com/rust-lang/crates.io-index" 202 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 203 | 204 | [[package]] 205 | name = "winapi-util" 206 | version = "0.1.5" 207 | source = "registry+https://github.com/rust-lang/crates.io-index" 208 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" 209 | dependencies = [ 210 | "winapi", 211 | ] 212 | 213 | [[package]] 214 | name = "winapi-x86_64-pc-windows-gnu" 215 | version = "0.4.0" 216 | source = "registry+https://github.com/rust-lang/crates.io-index" 217 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 218 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "chrome-devtools-rs" 3 | version = "0.0.0-alpha.3" 4 | authors = ["Avery Harnish ", "Nat Davidson "] 5 | edition = "2018" 6 | license = "MIT" 7 | readme = "README.md" 8 | description = "Low-level library for interacting with the Chrome Devtools Protocol" 9 | repository = "https://github.com/EverlastingBugstopper/chrome-devtools-rs" 10 | 11 | [features] 12 | color = [] 13 | 14 | [dependencies] 15 | serde = { version = "1.0", features = ["derive"] } 16 | serde_json = "1.0" 17 | log = "0.4" 18 | console = "0.11" 19 | unescape = "0.1" 20 | 21 | [lib] 22 | name = "chrome_devtools" 23 | path = "src/lib.rs" 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2019 Avery Harnish 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Chrome Devtools Protocol Wrapper 2 | 3 | ⚠️ DO NOT USE THIS CRATE ⚠️ 4 | 5 | The API is extremely unstable, untested, and incomplete. There are a few other crates in the ecosystem that likely better serve your needs. 6 | 7 | ## What's here so far 8 | 9 | This repository is home to a wrapper for the [Chrome Devtools Protocol](https://chromedevtools.github.io/devtools-protocol/) written in Rust. It is a work in progress and does not cover all of the possible message types that the protocol emits. If you would like to use this library but it does not support a message type you need, feel free to open a PR. 10 | -------------------------------------------------------------------------------- /RELEASE_CHECKLIST.md: -------------------------------------------------------------------------------- 1 | # Release Checklist 2 | 3 | This is a list of the things that need to happen during a release. 4 | 5 | ## Build a Release 6 | 7 | ### Prepare the Changelog (Full release only) 8 | 9 | 1. Open the associated milestone. All issues and PRs should be closed. If they 10 | are not you should reassign all open issues and PRs to future milestones. 11 | 1. Go through the commit history since the last release. Ensure that all PRs 12 | that have landed are marked with the milestone. You can use this to show all 13 | the PRs that are merged on or after YYY-MM-DD: 14 | `https://github.com/issues?utf8=%E2%9C%93&q=repo%3Acloudflare%2Fchrome-devtools-rs+merged%3A%3E%3DYYYY-MM-DD` 15 | 1. Go through the closed PRs in the milestone. Each should have a changelog 16 | label indicating if the change is docs, fix, feature, or maintenance. If 17 | there is a missing label, please add one. 18 | 1. Choose an emoji for the release. Try to make it semi-related to something 19 | that's been included in the release (point releases can be a little weirder). 20 | 1. Add this release to the `CHANGELOG.md`. Use the structure of previous 21 | entries. If you use VS Code, you can use 22 | [this snippet](https://gist.github.com/cloudflare/9feaf56b3dfe2a2c4ad156db36f2f75a) 23 | to insert new changelog sections. If it is a release candidate, no official 24 | changelog is needed, but testing instructions will be added later in the 25 | process. 26 | 27 | ### Update cargo manifest 28 | 29 | 1. Update the version in `Cargo.toml`. 30 | 1. Run `cargo update`. 31 | 1. Run `cargo test`. 32 | 1. Run `cargo build`. 33 | 34 | ### Release 35 | 36 | 1. Create a new branch "#.#.#" where "#.#.#" is this release's version (release) 37 | or "#.#.#-alpha.#" 38 | 1. Push up a commit with the `Cargo.toml`, `Cargo.lock`, and `CHANGELOG.md` 39 | changes. The commit message should be the same as your branch name from 40 | step 1. 41 | 1. Once ready to merge, tag the commit by running either 42 | `git tag -a v#.#.# -m #.#.#` (release), or 43 | `git tag -a v#.#.#-alpha.# -m #.#.#`. 44 | 1. Run `git push --tags`. 45 | 1. Run `cargo publish`. 46 | -------------------------------------------------------------------------------- /src/domain/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod runtime; 2 | pub use runtime::Runtime; 3 | 4 | use serde::{Deserialize, Serialize}; 5 | 6 | /// `Domain` is an enum that should contain all of the different domains defined by the devtools 7 | /// protocol. Currently only the `Runtime` domain is implemented, but this will hopefully change 8 | /// as the library evolves. 9 | /// 10 | /// It's important to note that this enum is tagged as `#[non_exhaustive]` because the plan is to 11 | /// add more domains. This means that matching on a `Domain` will require handling a default `_` 12 | /// case for the sake of future compatibility. 13 | #[derive(Debug, Serialize, Deserialize)] 14 | #[serde(untagged)] 15 | #[non_exhaustive] 16 | pub enum Domain { 17 | Runtime(Runtime), 18 | } 19 | -------------------------------------------------------------------------------- /src/domain/runtime/event/console_api_called.rs: -------------------------------------------------------------------------------- 1 | use std::fmt; 2 | 3 | use serde::{Deserialize, Serialize}; 4 | 5 | use crate::domain::runtime::r#type::RemoteObject; 6 | 7 | /// Issued when console API was called. 8 | /// See [Runtime.consoleAPICalled](https://chromedevtools.github.io/devtools-protocol/tot/Runtime#event-bindingCalled) 9 | #[derive(Debug, Serialize, Deserialize, Clone)] 10 | pub struct Event { 11 | /// Type of the call 12 | pub r#type: String, // TODO: make this an enum 13 | /// Call arguments 14 | pub args: Vec, 15 | // TODO: Add other parameters 16 | } 17 | 18 | impl fmt::Display for Event { 19 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 20 | let last_index = self.args.len() - 1; 21 | for (index, arg) in self.args.iter().enumerate() { 22 | write!(f, "{}", arg)?; 23 | if index < last_index { 24 | write!(f, " ")?; 25 | } 26 | } 27 | Ok(()) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/domain/runtime/event/mod.rs: -------------------------------------------------------------------------------- 1 | //![Runtime events](https://chromedevtools.github.io/devtools-protocol/tot/Runtime) 2 | 3 | use crate::domain::runtime::r#type::RemoteObject; 4 | use serde::{Deserialize, Serialize}; 5 | use std::fmt; 6 | pub mod console_api_called; 7 | 8 | #[derive(Debug, Serialize, Deserialize, Clone)] 9 | #[non_exhaustive] 10 | #[serde(tag = "method", content = "params")] 11 | pub enum Event { 12 | #[serde(rename = "Runtime.consoleAPICalled")] 13 | ConsoleAPICalled(console_api_called::Event), 14 | #[serde(rename = "Runtime.exceptionThrown")] 15 | ExceptionThrown(ExceptionParams), 16 | } 17 | 18 | #[derive(Debug, Serialize, Deserialize, Clone)] 19 | #[non_exhaustive] 20 | #[serde(rename_all = "camelCase")] 21 | pub struct ExceptionParams { 22 | pub timestamp: i64, 23 | pub exception_details: ExceptionDetails, 24 | } 25 | 26 | #[derive(Debug, Serialize, Deserialize, Clone)] 27 | #[serde(rename_all = "camelCase")] 28 | pub struct ExceptionDetails { 29 | pub text: String, 30 | pub line_number: i32, 31 | pub column_number: i32, 32 | pub url: Option, 33 | pub exception: RemoteObject, 34 | } 35 | 36 | impl fmt::Display for Event { 37 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 38 | match &self { 39 | Event::ConsoleAPICalled(event) => write!(f, "{}", event), 40 | Event::ExceptionThrown(params) => params.exception_details.text.fmt(f), 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/domain/runtime/method/get_isolate_id.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | 3 | use crate::domain::runtime::method::r#type::{Id, IsolateId}; 4 | 5 | #[derive(Debug, Serialize, Deserialize)] 6 | pub struct Return { 7 | id: Id, 8 | isolate_id: IsolateId, 9 | } 10 | -------------------------------------------------------------------------------- /src/domain/runtime/method/mod.rs: -------------------------------------------------------------------------------- 1 | //! [Runtime events](https://chromedevtools.github.io/devtools-protocol/tot/Runtime) 2 | 3 | use serde::{Deserialize, Serialize}; 4 | 5 | pub mod r#type; 6 | 7 | mod get_isolate_id; 8 | 9 | use r#type::Id; 10 | 11 | use std::fmt; 12 | 13 | #[derive(Debug, Serialize, Deserialize)] 14 | #[serde(tag = "method")] 15 | #[non_exhaustive] 16 | pub enum SendMethod { 17 | #[serde(rename = "Runtime.enable")] 18 | Enable(SendId), 19 | #[serde(rename = "Runtime.disable")] 20 | Disable(SendId), 21 | #[serde(rename = "Runtime.getIsolateId")] 22 | GetIsolateId(SendId), 23 | } 24 | 25 | impl fmt::Display for SendMethod { 26 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 27 | write!(f, "{:?}", &self) 28 | } 29 | } 30 | 31 | #[derive(Debug, Serialize, Deserialize)] 32 | #[serde(tag = "method")] 33 | #[non_exhaustive] 34 | pub enum ReturnMethod { 35 | #[serde(rename = "Runtime.enable")] 36 | Enable(Id), 37 | #[serde(rename = "Runtime.disable")] 38 | Disable(Id), 39 | #[serde(rename = "Runtime.getIsolateId")] 40 | GetIsolateId(get_isolate_id::Return), 41 | } 42 | 43 | #[derive(Debug, Serialize, Deserialize)] 44 | pub struct SendId { 45 | id: Id, 46 | } 47 | 48 | impl From for SendId { 49 | fn from(id: u64) -> Self { 50 | SendId { id } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/domain/runtime/method/type.rs: -------------------------------------------------------------------------------- 1 | pub type Id = u64; 2 | pub type IsolateId = String; 3 | -------------------------------------------------------------------------------- /src/domain/runtime/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod event; 2 | pub mod method; 3 | pub mod r#type; 4 | 5 | pub use event::Event; 6 | pub use method::{ReturnMethod, SendMethod}; 7 | 8 | use serde::{Deserialize, Serialize}; 9 | 10 | /// See documentation for the 11 | /// [Runtime domain](https://chromedevtools.github.io/devtools-protocol/tot/Runtime) 12 | #[derive(Debug, Serialize, Deserialize)] 13 | #[serde(untagged)] 14 | pub enum Runtime { 15 | Event(Event), 16 | Method(ReturnMethod), 17 | } 18 | -------------------------------------------------------------------------------- /src/domain/runtime/type/mod.rs: -------------------------------------------------------------------------------- 1 | //! Runtime types are used internally by methods and events 2 | 3 | mod remote_object; 4 | 5 | pub use remote_object::RemoteObject; 6 | -------------------------------------------------------------------------------- /src/domain/runtime/type/remote_object/mod.rs: -------------------------------------------------------------------------------- 1 | use std::fmt; 2 | 3 | pub mod r#type; 4 | 5 | use r#type::object::{ObjectPreview, Subtype}; 6 | use r#type::Type; 7 | 8 | use serde::{Deserialize, Serialize}; 9 | use unescape::unescape; 10 | 11 | use console::style; 12 | 13 | /// Mirror object referencing original JavaScript object. 14 | /// See [RemoteObject](https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-RemoteObject) 15 | #[derive(Deserialize, Serialize, Debug, Clone)] 16 | #[serde(rename_all = "camelCase")] 17 | pub struct RemoteObject { 18 | pub r#type: Type, 19 | pub subtype: Option, 20 | pub description: Option, 21 | pub class_name: Option, 22 | pub value: Option, 23 | pub preview: Option, 24 | } 25 | 26 | impl RemoteObject { 27 | fn parse_error(&self) -> String { 28 | let e = if let Some(subtype) = &self.subtype { 29 | format!("{}", subtype) 30 | } else { 31 | format!("{}", &self.r#type) 32 | }; 33 | format!("{{unknown {}}}", e) 34 | } 35 | 36 | fn display_description(&self) -> String { 37 | if let Some(description) = &self.description { 38 | description.to_string() 39 | } else { 40 | self.parse_error() 41 | } 42 | } 43 | 44 | fn display_value(&self) -> String { 45 | if let Some(value) = &self.value { 46 | value.to_string() 47 | } else { 48 | self.parse_error() 49 | } 50 | } 51 | 52 | fn display_object(&self) -> String { 53 | if let Some(preview) = &self.preview { 54 | preview.to_string() 55 | } else if let Some(subtype) = &self.subtype { 56 | if subtype.to_string() == "null" { 57 | let mut null = "null".to_string(); 58 | if cfg!(feature = "color") { 59 | null = format!("{}", style(null).bold()); 60 | } 61 | null 62 | } else { 63 | self.parse_error() 64 | } 65 | } else { 66 | self.parse_error() 67 | } 68 | } 69 | } 70 | 71 | impl fmt::Display for RemoteObject { 72 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 73 | let formatted = match &self.r#type { 74 | Type::Undefined => { 75 | let mut disp = "undefined".to_string(); 76 | if cfg!(feature = "color") { 77 | disp = format!("{}", style(disp).dim()) 78 | } 79 | disp 80 | } 81 | Type::Boolean => { 82 | let mut disp = self.display_value(); 83 | if cfg!(feature = "color") { 84 | disp = format!("{}", style(disp).yellow()); 85 | } 86 | disp 87 | } 88 | Type::String => { 89 | if let Some(value) = &self.value { 90 | let value = value.to_string(); 91 | let end = value.len() - 1; 92 | 93 | if let Some(s) = unescape(&value[1..end]) { 94 | s 95 | } else { 96 | self.parse_error() 97 | } 98 | } else { 99 | self.parse_error() 100 | } 101 | } 102 | Type::Object => self.display_object(), 103 | Type::BigInt | Type::Number | Type::Symbol => { 104 | let mut disp = self.display_description(); 105 | if cfg!(feature = "color") { 106 | disp = format!("{}", style(disp).yellow()); 107 | } 108 | disp 109 | } 110 | Type::Function => { 111 | let mut disp = self.display_description(); 112 | if cfg!(feature = "color") { 113 | disp = format!("{}", style(disp).cyan()); 114 | } 115 | disp 116 | } 117 | Type::Accessor => self.display_object(), 118 | }; 119 | write!(f, "{}", formatted) 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/domain/runtime/type/remote_object/type/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod object; 2 | 3 | use std::fmt; 4 | 5 | use serde::{Deserialize, Serialize}; 6 | 7 | /// Object type. 8 | #[derive(Debug, Serialize, Deserialize, Clone)] 9 | #[serde(rename_all = "lowercase")] 10 | pub enum Type { 11 | Object, 12 | Number, 13 | BigInt, 14 | Boolean, 15 | String, 16 | Symbol, 17 | Undefined, 18 | Function, 19 | Accessor, 20 | } 21 | 22 | impl fmt::Display for Type { 23 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 24 | let r#type = format!("{:?}", &self); 25 | write!(f, "{}", r#type.to_lowercase()) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/domain/runtime/type/remote_object/type/object/entry_preview.rs: -------------------------------------------------------------------------------- 1 | use std::fmt; 2 | 3 | use serde::{Deserialize, Serialize}; 4 | 5 | use crate::domain::runtime::r#type::remote_object::r#type::object::ObjectPreview; 6 | 7 | /// See [EntryPreview](https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-EntryPreview) 8 | #[derive(Debug, Serialize, Deserialize, Clone)] 9 | pub struct EntryPreview { 10 | pub key: ObjectPreview, 11 | pub value: ObjectPreview, 12 | } 13 | 14 | impl fmt::Display for EntryPreview { 15 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 16 | write!(f, "{} => {}", &self.key, &self.value) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/domain/runtime/type/remote_object/type/object/mod.rs: -------------------------------------------------------------------------------- 1 | mod entry_preview; 2 | mod object_preview; 3 | mod property_preview; 4 | 5 | pub use entry_preview::EntryPreview; 6 | pub use object_preview::{ObjectPreview, Subtype}; 7 | pub use property_preview::PropertyPreview; 8 | -------------------------------------------------------------------------------- /src/domain/runtime/type/remote_object/type/object/object_preview/mod.rs: -------------------------------------------------------------------------------- 1 | use std::fmt; 2 | 3 | use console::style; 4 | use serde::{Deserialize, Serialize}; 5 | 6 | mod subtype; 7 | 8 | pub use subtype::Subtype; 9 | 10 | use crate::domain::runtime::r#type::remote_object::r#type::object::{ 11 | EntryPreview, PropertyPreview, 12 | }; 13 | use crate::domain::runtime::r#type::remote_object::Type; 14 | 15 | /// See [ObjectPreview](https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-ObjectPreview) 16 | #[derive(Debug, Serialize, Deserialize, Clone)] 17 | #[serde(rename_all = "camelCase")] 18 | pub struct ObjectPreview { 19 | pub r#type: Type, 20 | pub description: String, 21 | pub overflow: bool, 22 | pub subtype: Option, 23 | pub properties: Vec, 24 | pub entries: Option>, 25 | } 26 | 27 | impl fmt::Display for ObjectPreview { 28 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 29 | let disp = if let Some(subtype) = &self.subtype { 30 | match subtype { 31 | Subtype::Array => { 32 | let last_index = self.properties.len() - 1; 33 | let mut array = "".to_string(); 34 | for (index, property) in &mut self.properties.iter().enumerate() { 35 | if index == 0 { 36 | array += " "; 37 | } 38 | array += &property.get_value(); 39 | if index < last_index { 40 | array += ", "; 41 | } else if self.overflow { 42 | array += ", …"; 43 | } 44 | array += " "; 45 | } 46 | format!("[{}]", array) 47 | } 48 | Subtype::Map => { 49 | let map = if let Some(entries) = &self.entries { 50 | let last_index = entries.len() - 1; 51 | let mut map = "".to_string(); 52 | for (index, entry) in &mut entries.iter().enumerate() { 53 | if index == 0 { 54 | map += " "; 55 | } 56 | map += &format!("{}", entry); 57 | if index < last_index { 58 | map += ", "; 59 | } else if self.overflow { 60 | map += ", …" 61 | } 62 | } 63 | map += " "; 64 | map 65 | } else { 66 | "".to_string() 67 | }; 68 | format!("Map {{{}}}", map) 69 | } 70 | Subtype::RegExp => { 71 | let mut disp = self.description.to_string(); 72 | if cfg!(feature = "color") { 73 | disp = format!("{}", style(disp).red()) 74 | } 75 | disp 76 | } 77 | Subtype::Date => { 78 | let mut disp = self.description.to_string(); 79 | if cfg!(feature = "color") { 80 | disp = format!("{}", style(disp).magenta()) 81 | } 82 | disp 83 | } 84 | _ => format!("{}", subtype), 85 | } 86 | } else { 87 | match &self.r#type { 88 | Type::Object => { 89 | let last_index = self.properties.len() - 1; 90 | let mut object = "".to_string(); 91 | for (idx, property) in &mut self.properties.iter().enumerate() { 92 | if idx == 0 { 93 | object += " "; 94 | } 95 | object += &format!("{}", property); 96 | if idx < last_index { 97 | object += ","; 98 | } else if self.overflow { 99 | object += ", …"; 100 | } 101 | object += " "; 102 | } 103 | format!("{{{}}}", object) 104 | } 105 | Type::String => { 106 | if cfg!(feature = "color") { 107 | format!("'{}'", style(&self.description).green()) 108 | } else { 109 | format!("'{}'", &self.description) 110 | } 111 | } 112 | _ => self.description.to_string(), 113 | } 114 | }; 115 | write!(f, "{}", disp) 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/domain/runtime/type/remote_object/type/object/object_preview/subtype.rs: -------------------------------------------------------------------------------- 1 | use std::fmt; 2 | 3 | use serde::{Deserialize, Serialize}; 4 | 5 | /// Object subtype hint. Specified for the `object` [Type][crate::domain::runtime::type::remote_object::type::Type] values only 6 | #[derive(Debug, Serialize, Deserialize, Clone)] 7 | #[serde(rename_all = "lowercase")] 8 | pub enum Subtype { 9 | Array, 10 | Null, 11 | RegExp, 12 | Date, 13 | Map, 14 | Node, 15 | Set, 16 | WeakMap, 17 | WeakSet, 18 | Iterator, 19 | Generator, 20 | Error, 21 | Proxy, 22 | Promise, 23 | TypedArray, 24 | ArrayBuffer, 25 | DataView, 26 | } 27 | 28 | impl fmt::Display for Subtype { 29 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 30 | let subtype = format!("{:?}", &self); 31 | write!(f, "{}", subtype.to_lowercase()) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/domain/runtime/type/remote_object/type/object/property_preview.rs: -------------------------------------------------------------------------------- 1 | use std::fmt; 2 | 3 | use console::style; 4 | use serde::{Deserialize, Serialize}; 5 | 6 | use crate::runtime::r#type::remote_object::r#type::object::object_preview::{ 7 | ObjectPreview, Subtype, 8 | }; 9 | use crate::runtime::r#type::remote_object::r#type::Type; 10 | 11 | /// See [PropertyPreview](https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-PropertyPreview) 12 | #[derive(Debug, Deserialize, Serialize, Clone)] 13 | #[serde(rename_all = "camelCase")] 14 | pub struct PropertyPreview { 15 | pub name: String, 16 | #[serde(rename = "type")] 17 | pub r#type: Type, 18 | pub value: Option, 19 | pub value_preview: Option, 20 | pub subtype: Option, 21 | } 22 | 23 | impl PropertyPreview { 24 | pub fn get_value(&self) -> String { 25 | if let Some(value) = &self.value { 26 | match &self.r#type { 27 | Type::Undefined => { 28 | let mut value = "undefined".to_string(); 29 | if cfg!(feature = "color") { 30 | value = format!("{}", style(value).dim()); 31 | } 32 | value 33 | } 34 | Type::String => { 35 | let mut value = format!("'{}'", value); 36 | if cfg!(feature = "color") { 37 | value = format!("{}", style(value).green()); 38 | } 39 | value 40 | } 41 | Type::Object => { 42 | let r#type = if let Some(subtype) = &self.subtype { 43 | format!("{:?}", subtype) 44 | } else { 45 | "Object".to_string() 46 | }; 47 | let mut value = format!("[{}]", r#type); 48 | if cfg!(feature = "color") { 49 | value = format!("{}", style(value).cyan()) 50 | } 51 | value 52 | } 53 | Type::BigInt | Type::Number | Type::Boolean => { 54 | if cfg!(feature = "color") { 55 | format!("{}", style(value).yellow()) 56 | } else { 57 | value.to_string() 58 | } 59 | } 60 | Type::Symbol => { 61 | if cfg!(feature = "color") { 62 | format!("{}", style(value).green()) 63 | } else { 64 | value.to_string() 65 | } 66 | } 67 | Type::Function => { 68 | if cfg!(feature = "color") { 69 | format!("{}", style(value).cyan()) 70 | } else { 71 | value.to_string() 72 | } 73 | } 74 | Type::Accessor => { 75 | let r#type = if let Some(subtype) = &self.subtype { 76 | format!("{:?}", subtype) 77 | } else { 78 | "Object".to_string() 79 | }; 80 | let mut value = format!("[{}]", r#type); 81 | if cfg!(feature = "color") { 82 | value = format!("{}", style(value).red()) 83 | } 84 | value 85 | } 86 | } 87 | } else { 88 | let mut disp = format!("[{} {}]", &self.r#type, &self.name); 89 | if cfg!(feature = "color") { 90 | disp = format!("{}", style(disp).cyan()); 91 | } 92 | disp 93 | } 94 | } 95 | } 96 | 97 | impl fmt::Display for PropertyPreview { 98 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 99 | let value = &self.get_value(); 100 | write!(f, "{}: {}", &self.name, value) 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | //! An experimental new library that serializes and deserializes messages for the [Chrome Devtools 2 | //! Protocol](https://chromedevtools.github.io/devtools-protocol/). 3 | //! 4 | //! The Devtools Protocol is divided into a number of domains. Each of these domains have "methods" 5 | //! and "events" that can be both serialized and deserialized by this library. 6 | 7 | pub mod domain; 8 | 9 | pub use domain::{runtime, runtime::Runtime, Domain}; 10 | --------------------------------------------------------------------------------