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 | |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 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 | |
| 24 | ### Command `cdp.sendCommand` |
| 25 | |
| 26 | ```cddl |
| 27 | CdpSendCommandCommand = { |
| 28 | method: "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 | |
| 48 | ### Command `cdp.getSession` |
| 49 | |
| 50 | ```cddl |
| 51 | CdpGetSessionCommand = { |
Alex Rudenko | 5fda646 | 2024-04-17 12:18:03 | [diff] [blame] | 52 | method: "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 | 5fda646 | 2024-04-17 12:18:03 | [diff] [blame] | 67 | ### Command `cdp.resolveRealm` |
| 68 | |
| 69 | ```cddl |
| 70 | CdpResolveRealmCommand = { |
| 71 | method: "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 | 1552f2b | 2023-07-11 11:18:32 | [diff] [blame] | 86 | ### Events `cdp` |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 87 | |
| 88 | ```cddl |
| 89 | CdpEventReceivedEvent = { |
Alex Rudenko | 1552f2b | 2023-07-11 11:18:32 | [diff] [blame] | 90 | method: "cdp.<CDP Event Name>", |
| 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 | |
| 103 | ### Field `channel` |
| 104 | |
| 105 | Each command can be extended with a `channel`: |
| 106 | |
| 107 | ```cddl |
| 108 | Command = { |
| 109 | id: js-uint, |
| 110 | channel?: text, |
| 111 | CommandData, |
| 112 | Extensible, |
| 113 | } |
| 114 | ``` |
| 115 | |
| 116 | If provided and non-empty string, the very same `channel` is added to the response: |
| 117 | |
| 118 | ```cddl |
| 119 | CommandResponse = { |
| 120 | id: js-uint, |
| 121 | channel?: text, |
| 122 | result: ResultData, |
| 123 | Extensible, |
| 124 | } |
| 125 | |
| 126 | ErrorResponse = { |
| 127 | id: js-uint / null, |
| 128 | channel?: text, |
| 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) |
| 139 | with `channel`, the subscriptions are handled per channel, and the corresponding |
| 140 | `channel` filed is added to the event message: |
| 141 | |
| 142 | ```cddl |
| 143 | Event = { |
| 144 | channel?: text, |
| 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 | 662ce9c | 2023-08-29 08:05:30 | [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 | |
| 177 | ### Starting WebDriver BiDi Server |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 178 | |
| 179 | This will run the server on port `8080`: |
| 180 | |
| 181 | ```sh |
| 182 | npm run server |
| 183 | ``` |
| 184 | |
| 185 | Use the `PORT=` environment variable or `--port=` argument to run it on another port: |
| 186 | |
| 187 | ```sh |
| 188 | PORT=8081 npm run server |
| 189 | npm run server -- --port=8081 |
| 190 | ``` |
| 191 | |
| 192 | Use the `DEBUG` environment variable to see debug info: |
| 193 | |
| 194 | ```sh |
| 195 | DEBUG=* npm run server |
| 196 | ``` |
| 197 | |
Alex Rudenko | 5fe99f8 | 2023-10-06 12:01:27 | [diff] [blame] | 198 | Use the `DEBUG_DEPTH` (default: `10`) environment variable to see debug deeply nested objects: |
| 199 | |
| 200 | ```sh |
| 201 | DEBUG_DEPTH=100 DEBUG=* npm run server |
| 202 | ``` |
| 203 | |
Alex Rudenko | 5fda646 | 2024-04-17 12:18:03 | [diff] [blame] | 204 | Use the `CHANNEL=...` environment variable with one of the following values to run |
| 205 | the specific Chrome channel: `stable`, `beta`, `canary`, `dev`, `local`. Default is |
| 206 | `local`. The `local` channel means the pinned in `.browser` Chrome version will be |
| 207 | downloaded if it is not yet in cache. Otherwise, the requested Chrome version should |
| 208 | be installed. |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 209 | |
| 210 | ```sh |
Randolf | 5543146 | 2023-03-29 13:00:36 | [diff] [blame] | 211 | CHANNEL=dev npm run server |
Randolf | 5543146 | 2023-03-29 13:00:36 | [diff] [blame] | 212 | ``` |
| 213 | |
Alex Rudenko | 1552f2b | 2023-07-11 11:18:32 | [diff] [blame] | 214 | 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] | 215 | |
| 216 | ```sh |
Alex Rudenko | 1552f2b | 2023-07-11 11:18:32 | [diff] [blame] | 217 | DEBUG=bidi:mapper:debug:* npm run server -- --verbose |
Randolf | 5543146 | 2023-03-29 13:00:36 | [diff] [blame] | 218 | ``` |
| 219 | |
| 220 | or |
| 221 | |
| 222 | ```sh |
| 223 | DEBUG=* npm run server -- --verbose |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 224 | ``` |
| 225 | |
| 226 | ### Starting on Linux and Mac |
| 227 | |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 228 | TODO: verify it works on Windows. |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 229 | |
Randolf Jung | 3e52631 | 2023-08-08 06:20:39 | [diff] [blame] | 230 | You can also run the server by using `npm run server`. It will write |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 231 | output to the file `log.txt`: |
| 232 | |
| 233 | ```sh |
Randolf Jung | 3e52631 | 2023-08-08 06:20:39 | [diff] [blame] | 234 | npm run server -- --port=8081 --headless=false |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 235 | ``` |
| 236 | |
Alex Rudenko | 5fe99f8 | 2023-10-06 12:01:27 | [diff] [blame] | 237 | ### Running with in other project |
| 238 | |
| 239 | Sometimes it good to verify that a change will not affect thing downstream for other packages. |
| 240 | There is a useful `puppeteer` label you can add to any PR to run Puppeteer test with your changes. |
| 241 | It will bundle `chromium-bidi` and install it in Puppeteer project then run that package test. |
| 242 | |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 243 | ## Running |
| 244 | |
| 245 | ### Unit tests |
| 246 | |
| 247 | Running: |
| 248 | |
| 249 | ```sh |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 250 | npm run unit |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 251 | ``` |
| 252 | |
| 253 | ### E2E tests |
| 254 | |
| 255 | The E2E tests are written using Python, in order to learn how to eventually do |
| 256 | this in web-platform-tests. |
| 257 | |
Alex Rudenko | 5fe99f8 | 2023-10-06 12:01:27 | [diff] [blame] | 258 | #### Installation |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 259 | |
Alex Rudenko | af11b7c | 2024-02-06 10:44:42 | [diff] [blame] | 260 | Python 3.10+ and some dependencies are required: |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 261 | |
| 262 | ```sh |
Alex Rudenko | af11b7c | 2024-02-06 10:44:42 | [diff] [blame] | 263 | python -m pip install --user pipenv |
| 264 | pipenv install |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 265 | ``` |
| 266 | |
Alex Rudenko | 5fe99f8 | 2023-10-06 12:01:27 | [diff] [blame] | 267 | #### Running |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 268 | |
| 269 | The E2E tests require BiDi server running on the same host. By default, tests |
| 270 | try to connect to the port `8080`. The server can be run from the project root: |
| 271 | |
| 272 | ```sh |
Alex Rudenko | d04dd45 | 2024-02-27 08:25:35 | [diff] [blame] | 273 | npm run e2e # alias to to e2e:headless |
| 274 | npm run e2e:headful |
| 275 | npm run e2e:headless |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 276 | ``` |
| 277 | |
Alex Rudenko | 5fda646 | 2024-04-17 12:18:03 | [diff] [blame] | 278 | This commands will run `./tools/run-e2e.mjs`, which will log the PyTest output to console, |
| 279 | Additionally the output is also recorded under `./logs/<DATE>.e2e.log`, this will contain |
| 280 | both the PyTest logs and in the event of `FAILED` test all the Chromium-BiDi logs. |
| 281 | |
| 282 | If you need to see the logs for all test run the command with `VERBOSE=true`. |
| 283 | |
| 284 | Simply pass `npm run e2e -- tests/<PathOrFile>` and the e2e will run only the selected one. |
| 285 | You run a specific test by running `npm run e2e -- -k <TestName>`. |
| 286 | |
| 287 | Use `CHROMEDRIVER` environment to run tests in `chromedriver` instead of NodeJS runner: |
| 288 | |
| 289 | ```shell |
| 290 | CHROMEDRIVER=true npm run e2e |
| 291 | ``` |
| 292 | |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 293 | Use the `PORT` environment variable to connect to another port: |
| 294 | |
| 295 | ```sh |
| 296 | PORT=8081 npm run e2e |
| 297 | ``` |
| 298 | |
Alex Rudenko | 5fda646 | 2024-04-17 12:18:03 | [diff] [blame] | 299 | Use the `HEADLESS` to run the tests in headless (new or old) or headful modes. |
| 300 | Values: `new`, `old`, `false`, default: `new`. |
| 301 | |
| 302 | ```sh |
| 303 | HEADLESS=new npm run e2e |
| 304 | ``` |
| 305 | |
Alex Rudenko | af11b7c | 2024-02-06 10:44:42 | [diff] [blame] | 306 | #### Updating snapshots |
| 307 | |
| 308 | ```sh |
| 309 | npm run e2e -- --snapshot-update |
| 310 | ``` |
| 311 | |
| 312 | See https://github.com/tophat/syrupy for more information. |
| 313 | |
Alex Rudenko | f7ea7ab | 2023-10-24 09:40:51 | [diff] [blame] | 314 | ### Local http server |
| 315 | |
| 316 | E2E tests use local http |
| 317 | server [`pytest-httpserver`](https://pytest-httpserver.readthedocs.io/), which is run |
| 318 | automatically with the tests. However, |
| 319 | sometimes it is useful to run the http server outside the test |
| 320 | case, for example for manual debugging. This can be done by running: |
| 321 | |
| 322 | ```sh |
Alex Rudenko | af11b7c | 2024-02-06 10:44:42 | [diff] [blame] | 323 | pipenv run local_http_server |
Alex Rudenko | f7ea7ab | 2023-10-24 09:40:51 | [diff] [blame] | 324 | ``` |
| 325 | |
Alex Rudenko | af11b7c | 2024-02-06 10:44:42 | [diff] [blame] | 326 | ...or directly: |
Alex Rudenko | f7ea7ab | 2023-10-24 09:40:51 | [diff] [blame] | 327 | |
| 328 | ```sh |
Alex Rudenko | af11b7c | 2024-02-06 10:44:42 | [diff] [blame] | 329 | python tests/tools/local_http_server.py |
Alex Rudenko | f7ea7ab | 2023-10-24 09:40:51 | [diff] [blame] | 330 | ``` |
| 331 | |
| 332 | ### Examples |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 333 | |
| 334 | Refer to [examples/README.md](examples/README.md). |
| 335 | |
| 336 | ## WPT (Web Platform Tests) |
| 337 | |
| 338 | WPT is added as |
| 339 | a [git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules). To get run |
| 340 | WPT tests: |
| 341 | |
| 342 | ### Check out and setup WPT |
| 343 | |
| 344 | #### 1. Check out WPT |
| 345 | |
| 346 | ```sh |
| 347 | git submodule update --init |
| 348 | ``` |
| 349 | |
| 350 | #### 2. Go to the WPT folder |
| 351 | |
| 352 | ```sh |
| 353 | cd wpt |
| 354 | ``` |
| 355 | |
| 356 | #### 3. Set up virtualenv |
| 357 | |
| 358 | Follow the [_System |
| 359 | Setup_](https://web-platform-tests.org/running-tests/from-local-system.html#system-setup) |
| 360 | instructions. |
| 361 | |
| 362 | #### 4. Setup `hosts` file |
| 363 | |
| 364 | Follow |
| 365 | the [`hosts` File Setup](https://web-platform-tests.org/running-tests/from-local-system.html#hosts-file-setup) |
| 366 | instructions. |
| 367 | |
| 368 | ##### 4.a On Linux, macOS or other UNIX-like system |
| 369 | |
| 370 | ```sh |
| 371 | ./wpt make-hosts-file | sudo tee -a /etc/hosts |
| 372 | ``` |
| 373 | |
| 374 | ##### 4.b On **Windows** |
| 375 | |
| 376 | This must be run in a PowerShell session with Administrator privileges: |
| 377 | |
| 378 | ```sh |
| 379 | python wpt make-hosts-file | Out-File $env:SystemRoot\System32\drivers\etc\hosts -Encoding ascii -Append |
| 380 | ``` |
| 381 | |
| 382 | If you are behind a proxy, you also need to make sure the domains above are excluded |
| 383 | from your proxy lookups. |
| 384 | |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 385 | #### 5. Set `BROWSER_BIN` |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 386 | |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 387 | 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] | 388 | For example, on macOS: |
| 389 | |
| 390 | ```sh |
| 391 | # Chrome |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 392 | export BROWSER_BIN="/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary" |
| 393 | export BROWSER_BIN="/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev" |
| 394 | export BROWSER_BIN="/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta" |
| 395 | export BROWSER_BIN="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" |
| 396 | export BROWSER_BIN="/Applications/Chromium.app/Contents/MacOS/Chromium" |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 397 | |
| 398 | # Edge |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 399 | export BROWSER_BIN="/Applications/Microsoft Edge Canary.app/Contents/MacOS/Microsoft Edge Canary" |
| 400 | export BROWSER_BIN="/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge" |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 401 | ``` |
| 402 | |
| 403 | ### Run WPT tests |
| 404 | |
| 405 | #### 1. Make sure you have Chrome Dev installed |
| 406 | |
| 407 | https://www.google.com/chrome/dev/ |
| 408 | |
Randolf | 5543146 | 2023-03-29 13:00:36 | [diff] [blame] | 409 | #### 2. Build Chromedriver BiDi |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 410 | |
| 411 | Oneshot: |
| 412 | |
| 413 | ```sh |
| 414 | npm run build |
| 415 | ``` |
| 416 | |
| 417 | Continuously: |
| 418 | |
| 419 | ```sh |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 420 | npm run build --watch |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 421 | ``` |
| 422 | |
| 423 | #### 3. Run |
| 424 | |
| 425 | ```sh |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 426 | npm run wpt -- webdriver/tests/bidi/ |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 427 | ``` |
| 428 | |
| 429 | ### Update WPT expectations if needed |
| 430 | |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 431 | ```sh |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 432 | UPDATE_EXPECTATIONS=true npm run wpt -- webdriver/tests/bidi/ |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 433 | ``` |
| 434 | |
| 435 | ## How does it work? |
| 436 | |
| 437 | The architecture is described in the |
| 438 | [WebDriver BiDi in Chrome Context implementation plan](https://docs.google.com/document/d/1VfQ9tv0wPSnb5TI-MOobjoQ5CXLnJJx9F_PxOMQc8kY) |
| 439 | . |
| 440 | |
| 441 | There are 2 main modules: |
| 442 | |
| 443 | 1. backend WS server in `src`. It runs webSocket server, and for each ws connection |
| 444 | runs an instance of browser with BiDi Mapper. |
| 445 | 2. front-end BiDi Mapper in `src/bidiMapper`. Gets BiDi commands from the backend, |
| 446 | and map them to CDP commands. |
| 447 | |
Alex Rudenko | 5fe99f8 | 2023-10-06 12:01:27 | [diff] [blame] | 448 | ## Contributing |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 449 | |
| 450 | The BiDi commands are processed in the `src/bidiMapper/commandProcessor.ts`. To add a |
| 451 | new command, add it to `_processCommand`, write and call processor for it. |
| 452 | |
| 453 | ### Publish new `npm` release |
| 454 | |
Alex Rudenko | 1552f2b | 2023-07-11 11:18:32 | [diff] [blame] | 455 | #### Automatic release |
Randolf Jung | bcb3bc8 | 2023-06-26 16:30:14 | [diff] [blame] | 456 | |
Alex Rudenko | 1552f2b | 2023-07-11 11:18:32 | [diff] [blame] | 457 | 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] | 458 | |
| 459 | #### Manual release |
| 460 | |
| 461 | 1. Dry-run |
| 462 | |
| 463 | ```sh |
| 464 | npm publish --dry-run |
| 465 | ``` |
| 466 | |
Randolf | 5543146 | 2023-03-29 13:00:36 | [diff] [blame] | 467 | 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] | 468 | |
| 469 | ```sh |
Alex Rudenko | 1552f2b | 2023-07-11 11:18:32 | [diff] [blame] | 470 | npm version patch -m 'chore: Release v%s' --no-git-tag-version |
Randolf | b0fe9c1 | 2023-03-06 14:03:48 | [diff] [blame] | 471 | ``` |
| 472 | |
| 473 | Instead of `patch`, use `minor` or `major` [as needed](https://semver.org/). |
| 474 | |
Randolf | 5543146 | 2023-03-29 13:00:36 | [diff] [blame] | 475 | 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. |
| 476 | 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] | 477 | |
| 478 | #### Roll into Chromium |
| 479 | |
Alex Rudenko | b013f87 | 2023-09-29 05:56:03 | [diff] [blame] | 480 | This section assumes you already have a Chromium set-up locally, |
| 481 | and knowledge on [how to submit changes to the repo](https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/contributing.md). |
| 482 | Otherwise submit an issue for a project maintainer. |
Randolf Jung | 3e52631 | 2023-08-08 06:20:39 | [diff] [blame] | 483 | |
Alex Rudenko | b013f87 | 2023-09-29 05:56:03 | [diff] [blame] | 484 | 1. Create a new branch in chromium `src/`. |
| 485 | 2. Update the mapper version: |
Randolf Jung | 3e52631 | 2023-08-08 06:20:39 | [diff] [blame] | 486 | |
Alex Rudenko | b013f87 | 2023-09-29 05:56:03 | [diff] [blame] | 487 | ```shell |
| 488 | third_party/bidimapper/pull.sh |
| 489 | third_party/bidimapper/build.sh |
Randolf Jung | 3e52631 | 2023-08-08 06:20:39 | [diff] [blame] | 490 | ``` |
| 491 | |
Alex Rudenko | b013f87 | 2023-09-29 05:56:03 | [diff] [blame] | 492 | 3. Submit a CL with bug `chromedriver:4226`. |
Alex Rudenko | b013f87 | 2023-09-29 05:56:03 | [diff] [blame] | 493 | |
Alex Rudenko | af11b7c | 2024-02-06 10:44:42 | [diff] [blame] | 494 | 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] | 495 | |
Alex Rudenko | af11b7c | 2024-02-06 10:44:42 | [diff] [blame] | 496 | 4.1. Trigger a build and test run: |
Alex Rudenko | b013f87 | 2023-09-29 05:56:03 | [diff] [blame] | 497 | |
Alex Rudenko | af11b7c | 2024-02-06 10:44:42 | [diff] [blame] | 498 | ```shell |
| 499 | third_party/blink/tools/blink_tool.py rebaseline-cl --build="linux-blink-rel" --verbose |
| 500 | ``` |
| 501 | |
| 502 | 4.2. Once the test completes on the builder, rerun that command to update the |
| 503 | baselines. Update test expectations if there are any crashes or timeouts. |
| 504 | Commit the changes (if any), and upload the new patch to the CL. |
Alex Rudenko | b013f87 | 2023-09-29 05:56:03 | [diff] [blame] | 505 | |
| 506 | 5. Add appropriate reviewers or comment the CL link on the PR. |