Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 1 | # WebDriver BiDi for Chromium [](https://www.npmjs.com/package/chromium-bidi) |
| 2 | |
Randolf | 5543146 | 2023-03-29 13:00:36 | [diff] [blame] | 3 | ## CI status |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 4 | |
Randolf | 5543146 | 2023-03-29 13:00:36 | [diff] [blame] | 5 |  |
| 6 |  |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 7 |  |
Randolf | 5543146 | 2023-03-29 13:00:36 | [diff] [blame] | 8 | |
Randolf | 5543146 | 2023-03-29 13:00:36 | [diff] [blame] | 9 |  |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 10 | |
| 11 | This is an implementation of the |
| 12 | [WebDriver BiDi](https://w3c.github.io/webdriver-bidi/) protocol with some |
| 13 | extensions (**BiDi+**) |
| 14 | for Chromium, implemented as a JavaScript layer translating between BiDi and CDP, |
| 15 | running inside a Chrome tab. |
| 16 | |
| 17 | Current status can be checked |
| 18 | at [WPT WebDriver BiDi status](https://wpt.fyi/results/webdriver/tests/bidi). |
| 19 | |
| 20 | ## BiDi+ |
| 21 | |
| 22 | **"BiDi+"** is an extension of the WebDriver BiDi protocol. In addition to [WebDriver BiDi](https://w3c.github.io/webdriver-bidi/) it has: |
| 23 | |
Alex Rudenko | fd8226a | 2025-01-17 09:14:20 | [diff] [blame] | 24 | ### Command `goog:cdp.sendCommand` |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 25 | |
| 26 | ```cddl |
| 27 | CdpSendCommandCommand = { |
Alex Rudenko | fd8226a | 2025-01-17 09:14:20 | [diff] [blame] | 28 | method: "goog:cdp.sendCommand", |
Alex Rudenko | 55d5f67 | 2024-08-02 12:04:00 | [diff] [blame] | 29 | params: CdpSendCommandParameters, |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | CdpSendCommandParameters = { |
Alex Rudenko | 1552f2b | 2023-07-11 11:18:32 | [diff] [blame] | 33 | method: text, |
| 34 | params: any, |
| 35 | session?: text, |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | CdpSendCommandResult = { |
| 39 | result: any, |
Alex Rudenko | 1552f2b | 2023-07-11 11:18:32 | [diff] [blame] | 40 | session: text, |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 41 | } |
| 42 | ``` |
| 43 | |
| 44 | The command runs the |
| 45 | described [CDP command](https://chromedevtools.github.io/devtools-protocol) |
Alex Rudenko | 1552f2b | 2023-07-11 11:18:32 | [diff] [blame] | 46 | and returns the result. |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 47 | |
Alex Rudenko | fd8226a | 2025-01-17 09:14:20 | [diff] [blame] | 48 | ### Command `goog:cdp.getSession` |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 49 | |
| 50 | ```cddl |
| 51 | CdpGetSessionCommand = { |
Alex Rudenko | fd8226a | 2025-01-17 09:14:20 | [diff] [blame] | 52 | method: "goog:cdp.getSession", |
Alex Rudenko | 55d5f67 | 2024-08-02 12:04:00 | [diff] [blame] | 53 | params: CdpGetSessionParameters, |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | CdpGetSessionParameters = { |
| 57 | context: BrowsingContext, |
| 58 | } |
| 59 | |
| 60 | CdpGetSessionResult = { |
Alex Rudenko | 1552f2b | 2023-07-11 11:18:32 | [diff] [blame] | 61 | session: text, |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 62 | } |
| 63 | ``` |
| 64 | |
| 65 | The command returns the default CDP session for the selected browsing context. |
| 66 | |
Alex Rudenko | fd8226a | 2025-01-17 09:14:20 | [diff] [blame] | 67 | ### Command `goog:cdp.resolveRealm` |
Alex Rudenko | 5fda646 | 2024-04-17 12:18:03 | [diff] [blame] | 68 | |
| 69 | ```cddl |
| 70 | CdpResolveRealmCommand = { |
Alex Rudenko | fd8226a | 2025-01-17 09:14:20 | [diff] [blame] | 71 | method: "goog:cdp.resolveRealm", |
Alex Rudenko | 55d5f67 | 2024-08-02 12:04:00 | [diff] [blame] | 72 | params: CdpResolveRealmParameters, |
Alex Rudenko | 5fda646 | 2024-04-17 12:18:03 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | CdpResolveRealmParameters = { |
| 76 | realm: Script.Realm, |
| 77 | } |
| 78 | |
| 79 | CdpResolveRealmResult = { |
| 80 | executionContextId: text, |
| 81 | } |
| 82 | ``` |
| 83 | |
| 84 | The command returns resolves a BiDi realm to its CDP execution context ID. |
| 85 | |
Alex Rudenko | fd8226a | 2025-01-17 09:14:20 | [diff] [blame] | 86 | ### Events `goog:cdp` |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 87 | |
| 88 | ```cddl |
| 89 | CdpEventReceivedEvent = { |
Alex Rudenko | fd8226a | 2025-01-17 09:14:20 | [diff] [blame] | 90 | method: "goog:cdp.<CDP Event Name>", |
Alex Rudenko | 1552f2b | 2023-07-11 11:18:32 | [diff] [blame] | 91 | params: CdpEventReceivedParameters, |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | CdpEventReceivedParameters = { |
Alex Rudenko | 1552f2b | 2023-07-11 11:18:32 | [diff] [blame] | 95 | event: text, |
| 96 | params: any, |
| 97 | session: text, |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 98 | } |
| 99 | ``` |
| 100 | |
| 101 | The event contains a CDP event. |
| 102 | |
Adam Raine | ac00a7d | 2025-01-30 18:59:25 | [diff] [blame] | 103 | ### Field `goog:channel` |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 104 | |
Adam Raine | ac00a7d | 2025-01-30 18:59:25 | [diff] [blame] | 105 | Each command can be extended with a `goog:channel`: |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 106 | |
| 107 | ```cddl |
| 108 | Command = { |
| 109 | id: js-uint, |
Adam Raine | ac00a7d | 2025-01-30 18:59:25 | [diff] [blame] | 110 | "goog:channel"?: text, |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 111 | CommandData, |
| 112 | Extensible, |
| 113 | } |
| 114 | ``` |
| 115 | |
Adam Raine | ac00a7d | 2025-01-30 18:59:25 | [diff] [blame] | 116 | If provided and non-empty string, the very same `goog:channel` is added to the response: |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 117 | |
| 118 | ```cddl |
| 119 | CommandResponse = { |
| 120 | id: js-uint, |
Adam Raine | ac00a7d | 2025-01-30 18:59:25 | [diff] [blame] | 121 | "goog:channel"?: text, |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 122 | result: ResultData, |
| 123 | Extensible, |
| 124 | } |
| 125 | |
| 126 | ErrorResponse = { |
| 127 | id: js-uint / null, |
Adam Raine | ac00a7d | 2025-01-30 18:59:25 | [diff] [blame] | 128 | "goog:channel"?: text, |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 129 | error: ErrorCode, |
| 130 | message: text, |
| 131 | ?stacktrace: text, |
| 132 | Extensible |
| 133 | } |
| 134 | ``` |
| 135 | |
| 136 | When client uses |
| 137 | commands [`session.subscribe`](https://w3c.github.io/webdriver-bidi/#command-session-subscribe) |
| 138 | and [`session.unsubscribe`](https://w3c.github.io/webdriver-bidi/#command-session-unsubscribe) |
Adam Raine | ac00a7d | 2025-01-30 18:59:25 | [diff] [blame] | 139 | with `goog:channel`, the subscriptions are handled per channel, and the corresponding |
| 140 | `goog:channel` filed is added to the event message: |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 141 | |
| 142 | ```cddl |
| 143 | Event = { |
Adam Raine | ac00a7d | 2025-01-30 18:59:25 | [diff] [blame] | 144 | "goog:channel"?: text, |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 145 | EventData, |
| 146 | Extensible, |
| 147 | } |
| 148 | ``` |
| 149 | |
| 150 | ## Dev Setup |
| 151 | |
| 152 | ### `npm` |
| 153 | |
| 154 | This is a Node.js project, so install dependencies as usual: |
| 155 | |
| 156 | ```sh |
| 157 | npm install |
| 158 | ``` |
| 159 | |
Randolf Jung | 3e52631 | 2023-08-08 06:20:39 | [diff] [blame] | 160 | ### `cargo` |
| 161 | |
| 162 | <!-- TODO(jrandolf): Remove after binaries get published --> |
| 163 | |
Alex Rudenko | 09712c6 | 2024-11-21 09:06:05 | [diff] [blame] | 164 | We use [cddlconv](https://github.com/google/cddlconv) to generate our WebDriverBiDi types before building. |
Randolf Jung | 3e52631 | 2023-08-08 06:20:39 | [diff] [blame] | 165 | |
| 166 | 1. Install [Rust](https://rustup.rs/). |
Alex Rudenko | 662ce9c | 2023-08-29 08:05:30 | [diff] [blame] | 167 | 2. Run `cargo install --git https://github.com/google/cddlconv.git cddlconv` |
Randolf Jung | 3e52631 | 2023-08-08 06:20:39 | [diff] [blame] | 168 | |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 169 | ### pre-commit.com integration |
| 170 | |
| 171 | Refer to the documentation at [.pre-commit-config.yaml](.pre-commit-config.yaml). |
| 172 | |
Alex Rudenko | f7ea7ab | 2023-10-24 09:40:51 | [diff] [blame] | 173 | ```sh |
| 174 | pre-commit install --hook-type pre-push |
| 175 | ``` |
| 176 | |
Adam Raine | ac00a7d | 2025-01-30 18:59:25 | [diff] [blame] | 177 | Re-installing pre-commit locally: |
| 178 | |
| 179 | ``` |
| 180 | pre-commit clean && pip install pre-commit |
| 181 | ``` |
| 182 | |
Alex Rudenko | f7ea7ab | 2023-10-24 09:40:51 | [diff] [blame] | 183 | ### Starting WebDriver BiDi Server |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 184 | |
| 185 | This will run the server on port `8080`: |
| 186 | |
| 187 | ```sh |
| 188 | npm run server |
| 189 | ``` |
| 190 | |
| 191 | Use the `PORT=` environment variable or `--port=` argument to run it on another port: |
| 192 | |
| 193 | ```sh |
| 194 | PORT=8081 npm run server |
| 195 | npm run server -- --port=8081 |
| 196 | ``` |
| 197 | |
| 198 | Use the `DEBUG` environment variable to see debug info: |
| 199 | |
| 200 | ```sh |
| 201 | DEBUG=* npm run server |
| 202 | ``` |
| 203 | |
Alex Rudenko | 5fe99f8 | 2023-10-06 12:01:27 | [diff] [blame] | 204 | Use the `DEBUG_DEPTH` (default: `10`) environment variable to see debug deeply nested objects: |
| 205 | |
| 206 | ```sh |
| 207 | DEBUG_DEPTH=100 DEBUG=* npm run server |
| 208 | ``` |
| 209 | |
Alex Rudenko | 5fda646 | 2024-04-17 12:18:03 | [diff] [blame] | 210 | Use the `CHANNEL=...` environment variable with one of the following values to run |
| 211 | the specific Chrome channel: `stable`, `beta`, `canary`, `dev`, `local`. Default is |
| 212 | `local`. The `local` channel means the pinned in `.browser` Chrome version will be |
| 213 | downloaded if it is not yet in cache. Otherwise, the requested Chrome version should |
| 214 | be installed. |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 215 | |
| 216 | ```sh |
Randolf | 5543146 | 2023-03-29 13:00:36 | [diff] [blame] | 217 | CHANNEL=dev npm run server |
Randolf | 5543146 | 2023-03-29 13:00:36 | [diff] [blame] | 218 | ``` |
| 219 | |
Alex Rudenko | 1552f2b | 2023-07-11 11:18:32 | [diff] [blame] | 220 | Use the CLI argument `--verbose` to have CDP events printed to the console. Note: you have to enable debugging output `bidi:mapper:debug:*` as well. |
Randolf | 5543146 | 2023-03-29 13:00:36 | [diff] [blame] | 221 | |
| 222 | ```sh |
Alex Rudenko | 1552f2b | 2023-07-11 11:18:32 | [diff] [blame] | 223 | DEBUG=bidi:mapper:debug:* npm run server -- --verbose |
Randolf | 5543146 | 2023-03-29 13:00:36 | [diff] [blame] | 224 | ``` |
| 225 | |
| 226 | or |
| 227 | |
| 228 | ```sh |
| 229 | DEBUG=* npm run server -- --verbose |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 230 | ``` |
| 231 | |
| 232 | ### Starting on Linux and Mac |
| 233 | |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 234 | TODO: verify it works on Windows. |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 235 | |
Randolf Jung | 3e52631 | 2023-08-08 06:20:39 | [diff] [blame] | 236 | You can also run the server by using `npm run server`. It will write |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 237 | output to the file `log.txt`: |
| 238 | |
| 239 | ```sh |
Randolf Jung | 3e52631 | 2023-08-08 06:20:39 | [diff] [blame] | 240 | npm run server -- --port=8081 --headless=false |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 241 | ``` |
| 242 | |
Alex Rudenko | 5fe99f8 | 2023-10-06 12:01:27 | [diff] [blame] | 243 | ### Running with in other project |
| 244 | |
| 245 | Sometimes it good to verify that a change will not affect thing downstream for other packages. |
| 246 | There is a useful `puppeteer` label you can add to any PR to run Puppeteer test with your changes. |
| 247 | It will bundle `chromium-bidi` and install it in Puppeteer project then run that package test. |
| 248 | |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 249 | ## Running |
| 250 | |
| 251 | ### Unit tests |
| 252 | |
| 253 | Running: |
| 254 | |
| 255 | ```sh |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 256 | npm run unit |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 257 | ``` |
| 258 | |
| 259 | ### E2E tests |
| 260 | |
Alex Rudenko | fd8226a | 2025-01-17 09:14:20 | [diff] [blame] | 261 | The e2e tests serve the following purposes: |
| 262 | |
| 263 | 1. Brief checks of the scenarios (the detailed check is done in WPT) |
| 264 | 2. Test Chromium-specific behavior nuances |
| 265 | 3. Add a simple setup for engaging the specific command |
| 266 | |
| 267 | The E2E tests are written using Python, in order to more-or-less align with the web-platform-tests. |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 268 | |
Alex Rudenko | 5fe99f8 | 2023-10-06 12:01:27 | [diff] [blame] | 269 | #### Installation |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 270 | |
Alex Rudenko | af11b7c | 2024-02-06 10:44:42 | [diff] [blame] | 271 | Python 3.10+ and some dependencies are required: |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 272 | |
| 273 | ```sh |
Alex Rudenko | af11b7c | 2024-02-06 10:44:42 | [diff] [blame] | 274 | python -m pip install --user pipenv |
| 275 | pipenv install |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 276 | ``` |
| 277 | |
Alex Rudenko | 5fe99f8 | 2023-10-06 12:01:27 | [diff] [blame] | 278 | #### Running |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 279 | |
| 280 | The E2E tests require BiDi server running on the same host. By default, tests |
| 281 | try to connect to the port `8080`. The server can be run from the project root: |
| 282 | |
| 283 | ```sh |
Alex Rudenko | d04dd45 | 2024-02-27 08:25:35 | [diff] [blame] | 284 | npm run e2e # alias to to e2e:headless |
| 285 | npm run e2e:headful |
| 286 | npm run e2e:headless |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 287 | ``` |
| 288 | |
Alex Rudenko | 5fda646 | 2024-04-17 12:18:03 | [diff] [blame] | 289 | This commands will run `./tools/run-e2e.mjs`, which will log the PyTest output to console, |
| 290 | Additionally the output is also recorded under `./logs/<DATE>.e2e.log`, this will contain |
| 291 | both the PyTest logs and in the event of `FAILED` test all the Chromium-BiDi logs. |
| 292 | |
| 293 | If you need to see the logs for all test run the command with `VERBOSE=true`. |
| 294 | |
| 295 | Simply pass `npm run e2e -- tests/<PathOrFile>` and the e2e will run only the selected one. |
| 296 | You run a specific test by running `npm run e2e -- -k <TestName>`. |
| 297 | |
| 298 | Use `CHROMEDRIVER` environment to run tests in `chromedriver` instead of NodeJS runner: |
| 299 | |
| 300 | ```shell |
| 301 | CHROMEDRIVER=true npm run e2e |
| 302 | ``` |
| 303 | |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 304 | Use the `PORT` environment variable to connect to another port: |
| 305 | |
| 306 | ```sh |
| 307 | PORT=8081 npm run e2e |
| 308 | ``` |
| 309 | |
Alex Rudenko | 5fda646 | 2024-04-17 12:18:03 | [diff] [blame] | 310 | Use the `HEADLESS` to run the tests in headless (new or old) or headful modes. |
| 311 | Values: `new`, `old`, `false`, default: `new`. |
| 312 | |
| 313 | ```sh |
| 314 | HEADLESS=new npm run e2e |
| 315 | ``` |
| 316 | |
Alex Rudenko | af11b7c | 2024-02-06 10:44:42 | [diff] [blame] | 317 | #### Updating snapshots |
| 318 | |
| 319 | ```sh |
Alex Rudenko | fd8226a | 2025-01-17 09:14:20 | [diff] [blame] | 320 | npm run e2e -- --snapshot-update true |
Alex Rudenko | af11b7c | 2024-02-06 10:44:42 | [diff] [blame] | 321 | ``` |
| 322 | |
| 323 | See https://github.com/tophat/syrupy for more information. |
| 324 | |
Alex Rudenko | f7ea7ab | 2023-10-24 09:40:51 | [diff] [blame] | 325 | ### Local http server |
| 326 | |
| 327 | E2E tests use local http |
| 328 | server [`pytest-httpserver`](https://pytest-httpserver.readthedocs.io/), which is run |
| 329 | automatically with the tests. However, |
| 330 | sometimes it is useful to run the http server outside the test |
| 331 | case, for example for manual debugging. This can be done by running: |
| 332 | |
| 333 | ```sh |
Alex Rudenko | af11b7c | 2024-02-06 10:44:42 | [diff] [blame] | 334 | pipenv run local_http_server |
Alex Rudenko | f7ea7ab | 2023-10-24 09:40:51 | [diff] [blame] | 335 | ``` |
| 336 | |
Alex Rudenko | af11b7c | 2024-02-06 10:44:42 | [diff] [blame] | 337 | ...or directly: |
Alex Rudenko | f7ea7ab | 2023-10-24 09:40:51 | [diff] [blame] | 338 | |
| 339 | ```sh |
Alex Rudenko | af11b7c | 2024-02-06 10:44:42 | [diff] [blame] | 340 | python tests/tools/local_http_server.py |
Alex Rudenko | f7ea7ab | 2023-10-24 09:40:51 | [diff] [blame] | 341 | ``` |
| 342 | |
| 343 | ### Examples |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 344 | |
| 345 | Refer to [examples/README.md](examples/README.md). |
| 346 | |
| 347 | ## WPT (Web Platform Tests) |
| 348 | |
| 349 | WPT is added as |
| 350 | a [git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules). To get run |
| 351 | WPT tests: |
| 352 | |
| 353 | ### Check out and setup WPT |
| 354 | |
| 355 | #### 1. Check out WPT |
| 356 | |
| 357 | ```sh |
| 358 | git submodule update --init |
| 359 | ``` |
| 360 | |
| 361 | #### 2. Go to the WPT folder |
| 362 | |
| 363 | ```sh |
| 364 | cd wpt |
| 365 | ``` |
| 366 | |
| 367 | #### 3. Set up virtualenv |
| 368 | |
| 369 | Follow the [_System |
| 370 | Setup_](https://web-platform-tests.org/running-tests/from-local-system.html#system-setup) |
| 371 | instructions. |
| 372 | |
| 373 | #### 4. Setup `hosts` file |
| 374 | |
| 375 | Follow |
| 376 | the [`hosts` File Setup](https://web-platform-tests.org/running-tests/from-local-system.html#hosts-file-setup) |
| 377 | instructions. |
| 378 | |
| 379 | ##### 4.a On Linux, macOS or other UNIX-like system |
| 380 | |
| 381 | ```sh |
| 382 | ./wpt make-hosts-file | sudo tee -a /etc/hosts |
| 383 | ``` |
| 384 | |
| 385 | ##### 4.b On **Windows** |
| 386 | |
| 387 | This must be run in a PowerShell session with Administrator privileges: |
| 388 | |
| 389 | ```sh |
| 390 | python wpt make-hosts-file | Out-File $env:SystemRoot\System32\drivers\etc\hosts -Encoding ascii -Append |
| 391 | ``` |
| 392 | |
| 393 | If you are behind a proxy, you also need to make sure the domains above are excluded |
| 394 | from your proxy lookups. |
| 395 | |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 396 | #### 5. Set `BROWSER_BIN` |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 397 | |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 398 | Set the `BROWSER_BIN` environment variable to a Chrome, Edge or Chromium binary to launch. |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 399 | For example, on macOS: |
| 400 | |
| 401 | ```sh |
| 402 | # Chrome |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 403 | export BROWSER_BIN="/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary" |
| 404 | export BROWSER_BIN="/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev" |
| 405 | export BROWSER_BIN="/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta" |
| 406 | export BROWSER_BIN="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" |
| 407 | export BROWSER_BIN="/Applications/Chromium.app/Contents/MacOS/Chromium" |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 408 | |
| 409 | # Edge |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 410 | export BROWSER_BIN="/Applications/Microsoft Edge Canary.app/Contents/MacOS/Microsoft Edge Canary" |
| 411 | export BROWSER_BIN="/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge" |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 412 | ``` |
| 413 | |
| 414 | ### Run WPT tests |
| 415 | |
| 416 | #### 1. Make sure you have Chrome Dev installed |
| 417 | |
| 418 | https://www.google.com/chrome/dev/ |
| 419 | |
Randolf | 5543146 | 2023-03-29 13:00:36 | [diff] [blame] | 420 | #### 2. Build Chromedriver BiDi |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 421 | |
| 422 | Oneshot: |
| 423 | |
| 424 | ```sh |
| 425 | npm run build |
| 426 | ``` |
| 427 | |
| 428 | Continuously: |
| 429 | |
| 430 | ```sh |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 431 | npm run build --watch |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 432 | ``` |
| 433 | |
| 434 | #### 3. Run |
| 435 | |
| 436 | ```sh |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 437 | npm run wpt -- webdriver/tests/bidi/ |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 438 | ``` |
| 439 | |
| 440 | ### Update WPT expectations if needed |
| 441 | |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 442 | ```sh |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 443 | UPDATE_EXPECTATIONS=true npm run wpt -- webdriver/tests/bidi/ |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 444 | ``` |
| 445 | |
| 446 | ## How does it work? |
| 447 | |
| 448 | The architecture is described in the |
| 449 | [WebDriver BiDi in Chrome Context implementation plan](https://docs.google.com/document/d/1VfQ9tv0wPSnb5TI-MOobjoQ5CXLnJJx9F_PxOMQc8kY) |
| 450 | . |
| 451 | |
| 452 | There are 2 main modules: |
| 453 | |
| 454 | 1. backend WS server in `src`. It runs webSocket server, and for each ws connection |
| 455 | runs an instance of browser with BiDi Mapper. |
| 456 | 2. front-end BiDi Mapper in `src/bidiMapper`. Gets BiDi commands from the backend, |
| 457 | and map them to CDP commands. |
| 458 | |
Alex Rudenko | 5fe99f8 | 2023-10-06 12:01:27 | [diff] [blame] | 459 | ## Contributing |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 460 | |
| 461 | The BiDi commands are processed in the `src/bidiMapper/commandProcessor.ts`. To add a |
| 462 | new command, add it to `_processCommand`, write and call processor for it. |
| 463 | |
| 464 | ### Publish new `npm` release |
| 465 | |
Alex Rudenko | 09712c6 | 2024-11-21 09:06:05 | [diff] [blame] | 466 | #### Release branches |
| 467 | |
| 468 | `chromium-bidi` maintains release branches corresponding to Chrome releases. The |
| 469 | branches are named using the following pattern: `releases/m$MAJOR_VERSION`. |
| 470 | |
| 471 | The new release branch is created as soon a new major browser version is |
| 472 | published by the |
| 473 | [update-browser-version](https://github.com/GoogleChromeLabs/chromium-bidi/blob/main/.github/workflows/update-browser-version.yml) |
| 474 | job: |
| 475 | |
| 476 | - the PR created by this job should be marked as a feature and it should cause the |
| 477 | major package version to be bumped. |
| 478 | - once the browser version is bumped, the commit preceding the version bump |
| 479 | should be used to create a release branch for major version pinned before the bump. |
| 480 | |
| 481 | Changes that need to be cherry-picked into the release branch should be marked |
| 482 | as patches. Either major or minor version bumps are not allowed on the release |
| 483 | branch. |
| 484 | |
| 485 | Example workflow: |
| 486 | |
| 487 | ```mermaid |
| 488 | gitGraph |
| 489 | commit id: "feat: featA" |
| 490 | commit id: "release: v0.5.0" |
| 491 | branch release/m129 |
| 492 | checkout main |
| 493 | commit id: "feat: roll Chrome to M130 from 129" |
| 494 | commit id: "release: v0.6.0" |
| 495 | commit id: "fix: for m129" |
| 496 | checkout release/m129 |
| 497 | cherry-pick id: "fix: for m129" |
| 498 | commit id: "release: v0.5.1 " |
| 499 | ``` |
| 500 | |
| 501 | Currently, the releases from release branches are not automated. |
| 502 | |
Alex Rudenko | 1552f2b | 2023-07-11 11:18:32 | [diff] [blame] | 503 | #### Automatic release |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 504 | |
Alex Rudenko | 1552f2b | 2023-07-11 11:18:32 | [diff] [blame] | 505 | We use [release-please](https://github.com/googleapis/release-please) to automate releases. When a release should be done, check for the release PR in our [pull requests](https://github.com/GoogleChromeLabs/chromium-bidi/pulls) and merge it. |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 506 | |
| 507 | #### Manual release |
| 508 | |
| 509 | 1. Dry-run |
| 510 | |
| 511 | ```sh |
| 512 | npm publish --dry-run |
| 513 | ``` |
| 514 | |
Randolf | 5543146 | 2023-03-29 13:00:36 | [diff] [blame] | 515 | 1. Open a PR bumping the chromium-bidi version number in `package.json` for review: |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 516 | |
| 517 | ```sh |
Alex Rudenko | 1552f2b | 2023-07-11 11:18:32 | [diff] [blame] | 518 | npm version patch -m 'chore: Release v%s' --no-git-tag-version |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 519 | ``` |
| 520 | |
| 521 | Instead of `patch`, use `minor` or `major` [as needed](https://semver.org/). |
| 522 | |
Randolf | 5543146 | 2023-03-29 13:00:36 | [diff] [blame] | 523 | 1. After the PR is reviewed, [create a GitHub release](https://github.com/GoogleChromeLabs/chromium-bidi/releases/new) specifying the tag name matching the bumped version. |
| 524 | Our CI then automatically publishes the new release to npm based on the tag name. |
Randolf Jung | 3e52631 | 2023-08-08 06:20:39 | [diff] [blame] | 525 | |
| 526 | #### Roll into Chromium |
| 527 | |
Alex Rudenko | b013f87 | 2023-09-29 05:56:03 | [diff] [blame] | 528 | This section assumes you already have a Chromium set-up locally, |
| 529 | and knowledge on [how to submit changes to the repo](https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/contributing.md). |
| 530 | Otherwise submit an issue for a project maintainer. |
Randolf Jung | 3e52631 | 2023-08-08 06:20:39 | [diff] [blame] | 531 | |
Alex Rudenko | b013f87 | 2023-09-29 05:56:03 | [diff] [blame] | 532 | 1. Create a new branch in chromium `src/`. |
| 533 | 2. Update the mapper version: |
Randolf Jung | 3e52631 | 2023-08-08 06:20:39 | [diff] [blame] | 534 | |
Alex Rudenko | b013f87 | 2023-09-29 05:56:03 | [diff] [blame] | 535 | ```shell |
Alex Rudenko | 09712c6 | 2024-11-21 09:06:05 | [diff] [blame] | 536 | third_party/bidimapper/roll_bidmapper |
Randolf Jung | 3e52631 | 2023-08-08 06:20:39 | [diff] [blame] | 537 | ``` |
| 538 | |
Alex Rudenko | fd8226a | 2025-01-17 09:14:20 | [diff] [blame] | 539 | 3. Submit a CL with bug `42323268` ([link](https://crbug.com/42323268)). |
Alex Rudenko | b013f87 | 2023-09-29 05:56:03 | [diff] [blame] | 540 | |
Alex Rudenko | af11b7c | 2024-02-06 10:44:42 | [diff] [blame] | 541 | 4. [Regenerate WPT expectations or baselines](https://chromium.googlesource.com/chromium/src/+/HEAD/docs/testing/run_web_platform_tests.md#test-expectations-and-baselines): |
Alex Rudenko | b013f87 | 2023-09-29 05:56:03 | [diff] [blame] | 542 | |
Alex Rudenko | af11b7c | 2024-02-06 10:44:42 | [diff] [blame] | 543 | 4.1. Trigger a build and test run: |
Alex Rudenko | b013f87 | 2023-09-29 05:56:03 | [diff] [blame] | 544 | |
Alex Rudenko | af11b7c | 2024-02-06 10:44:42 | [diff] [blame] | 545 | ```shell |
| 546 | third_party/blink/tools/blink_tool.py rebaseline-cl --build="linux-blink-rel" --verbose |
| 547 | ``` |
| 548 | |
| 549 | 4.2. Once the test completes on the builder, rerun that command to update the |
| 550 | baselines. Update test expectations if there are any crashes or timeouts. |
| 551 | Commit the changes (if any), and upload the new patch to the CL. |
Alex Rudenko | b013f87 | 2023-09-29 05:56:03 | [diff] [blame] | 552 | |
| 553 | 5. Add appropriate reviewers or comment the CL link on the PR. |
Alex Rudenko | fd8226a | 2025-01-17 09:14:20 | [diff] [blame] | 554 | |
| 555 | ## Adding new command |
| 556 | |
| 557 | Want to add a shiny new command to WebDriver BiDi for Chromium? Here's the playbook: |
| 558 | |
| 559 | ### Prerequisites |
| 560 | |
| 561 | #### Specification |
| 562 | |
| 563 | The WebDriver BiDi [module](https://w3c.github.io/webdriver-bidi/#protocol-modules), [command](https://w3c.github.io/webdriver-bidi/#commands), or [event](https://w3c.github.io/webdriver-bidi/#events) must be specified either in the [WebDriver BiDi specification](https://w3c.github.io/webdriver-bidi) or as an extension in a separate specification (e.g., the [Permissions specification](https://www.w3.org/TR/permissions/#automation-webdriver-bidi)). The specification should include the command's type definitions in valid [CDDL](https://datatracker.ietf.org/doc/html/rfc8610) format. |
| 564 | |
| 565 | #### WPT wdspec tests |
| 566 | |
| 567 | You'll need tests to prove your command works as expected. These tests should be written using [WPT wdspec](https://web-platform-tests.org/writing-tests/wdspec.html) and submitted along with the spec itself. Don't forget to roll the WPT repo into the Mapper ([dependabot](https://github.com/GoogleChromeLabs/chromium-bidi/network/updates/10663151/jobs) can help, and you will likely need to tweak some expectations afterward). |
| 568 | |
| 569 | #### CDP implementation |
| 570 | |
| 571 | Make sure Chromium already has the CDP methods your command will rely on. |
| 572 | |
| 573 | ### Update CDDL types |
| 574 | |
| 575 | 1. If your command lives in a separate spec, add a link to that spec in the ["Build WebDriverBiDi types"](https://github.com/GoogleChromeLabs/chromium-bidi/blob/0f971303281aba1910786035facc5eb54a833232/.github/workflows/update-bidi-types.yml#L27) GitHub action (check out the ["bluetooth" pull request](https://github.com/GoogleChromeLabs/chromium-bidi/pull/2585) for an example). |
| 576 | 2. Run the ["Update WebdriverBiDi types"](https://github.com/GoogleChromeLabs/chromium-bidi/actions/workflows/update-bidi-types.yml) GitHub action. This will create a pull request with your new types. If you added a command, this PR will have a failing check complaining about a non-exhaustive switch statement: |
| 577 | > error: Switch is not exhaustive. Cases not matched: "{NEW_COMMAND_NAME}" @typescript-eslint/switch-exhaustiveness-check |
| 578 | 3. Update the created pull request. Add your new command to [`CommandProcessor.#processCommand`](https://github.com/GoogleChromeLabs/chromium-bidi/blob/0f971303281aba1910786035facc5eb54a833232/src/bidiMapper/CommandProcessor.ts#L140). For now, just have it throw an UnknownErrorException (see the [example](https://github.com/GoogleChromeLabs/chromium-bidi/pull/2647/files#diff-7f06ce28b8514fd75b759d217bff9f5a471b657bcf78bd893cc291c7945c1cacR169) for how to do this). |
| 579 | |
| 580 | ```typescript |
| 581 | case '{NEW_COMMAND_NAME}': |
| 582 | throw new UnknownErrorException( |
| 583 | `Method ${command.method} is not implemented.`, |
| 584 | ); |
| 585 | ``` |
| 586 | |
| 587 | 4. Merge it! Standard PR process: create, review, merge. |
| 588 | |
| 589 | ### Implement the new command |
| 590 | |
| 591 | [`CommandProcessor.#processCommand`](https://github.com/GoogleChromeLabs/chromium-bidi/blob/0f971303281aba1910786035facc5eb54a833232/src/bidiMapper/CommandProcessor.ts#L140) handles parsing parameters and running your command. |
| 592 | |
| 593 | #### (only if the new command has non-empty parameters) parse command parameters |
| 594 | |
| 595 | If your command has parameters, update the [`BidiCommandParameterParser`](https://github.com/GoogleChromeLabs/chromium-bidi/blob/0f971303281aba1910786035facc5eb54a833232/src/bidiMapper/BidiParser.ts#L31) and implement the parsing logic in [`BidiNoOpParser`](https://github.com/GoogleChromeLabs/chromium-bidi/blob/0f971303281aba1910786035facc5eb54a833232/src/bidiMapper/BidiNoOpParser.ts#L209), [`BidiParser`](https://github.com/GoogleChromeLabs/chromium-bidi/blob/0f971303281aba1910786035facc5eb54a833232/src/bidiTab/BidiParser.ts#L182) and [`protocol-parser`](https://github.com/GoogleChromeLabs/chromium-bidi/blob/0f971303281aba1910786035facc5eb54a833232/src/protocol-parser/protocol-parser.ts#L386). Look at the [example](https://github.com/GoogleChromeLabs/chromium-bidi/blob/0f971303281aba1910786035facc5eb54a833232/src/bidiMapper/BidiParser.ts#L97) for guidance. |
| 596 | |
| 597 | #### Implement the new command |
| 598 | |
| 599 | Write the core logic for your command in the appropriate domain processor. Again, [example](https://github.com/GoogleChromeLabs/chromium-bidi/blob/0f971303281aba1910786035facc5eb54a833232/src/bidiMapper/modules/permissions/PermissionsProcessor.ts#L32) is your friend. |
| 600 | |
| 601 | #### Call the module processor's method |
| 602 | |
| 603 | Call your new module processor method from `CommandProcessor.#processCommand`, passing in the parsed parameters. [Example](https://github.com/GoogleChromeLabs/chromium-bidi/blob/0f971303281aba1910786035facc5eb54a833232/src/bidiMapper/CommandProcessor.ts#L313). |
| 604 | |
| 605 | #### Add e2e tests |
| 606 | |
| 607 | Write end-to-end tests for your command, including the happy path and any edge cases that might trip things up. Focus on testing the code in the mapper. |
| 608 | |
| 609 | #### Update WPT expectations |
| 610 | |
| 611 | Your WPT tests will probably fail now. |
| 612 | |
| 613 | > Tests with unexpected results: PASS [expected FAIL] ... |
| 614 | |
| 615 | Update the expectations in a draft PR with the "update-expectations" label. This will trigger an automated PR "test: update the expectations for PR" that you'll need to merge to your branch. |
| 616 | |
| 617 | #### Merge it! |
| 618 | |
| 619 | Mark your PR as ready, get it reviewed, and merge it in. |
| 620 | |
| 621 | ### Roll in ChromeDriver |
| 622 | |
| 623 | This bit usually involves the core devs: |
| 624 | |
| 625 | 1. [Release](#automatic-release) your changes. |
| 626 | 2. [Roll the changes into ChromeDriver](#roll-into-chromium). |