Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,23 @@ Use the [protocol viewer](https://chromedevtools.github.io/devtools-protocol/) f
TypeScript definitions for the protocol's types are available in ['types/protocol.d.ts'](https://github.com/ChromeDevTools/devtools-protocol/tree/master/types). Mappings from Commands and events to these types are available in either generated `DomainApi` style in [`types/protocol-proxy-api.d.ts`](https://github.com/ChromeDevTools/devtools-protocol/blob/master/types/protocol-proxy-api.d.ts) or in simple name-to-type-interface style in [`types/protocol-mapping.d.ts`](https://github.com/ChromeDevTools/devtools-protocol/blob/master/types/protocol-mapping.d.ts).

Also, this repo is published as the [`devtools-protocol`](https://www.npmjs.com/package/devtools-protocol) npm module.

## Development

The `.pdl` files, the `json/` files and the TypeScript definitions in `types/`
are all generated by [`scripts/update-to-latest.sh`](scripts/update-to-latest.sh),
which runs daily. Do not edit them by hand.

The TypeScript generator itself lives in Chromium, at
[`//third_party/blink/public/devtools_protocol/scripts/protocol_dts_generator.ts`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/public/devtools_protocol/scripts/protocol_dts_generator.ts),
so that Chromium and this repo share a single source of truth. It is fetched
into `tmp/chromium/` by the sparse checkout in `update-to-latest.sh`. Changes to
the generator should be made in Chromium.

To regenerate `types/` against an existing local Chromium checkout:

```sh
cd scripts
CHROMIUM_PROTOCOL_SCRIPTS_DIR=/path/to/src/third_party/blink/public/devtools_protocol/scripts \
npm run build-protocol-dts
```
49 changes: 49 additions & 0 deletions scripts/build-protocol-dts.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Regenerates types/*.d.ts using Chromium's protocol_dts_generator.ts.
//
// The generator is maintained in Chromium (the single source of truth) at
// //third_party/blink/public/devtools_protocol/scripts/ and is fetched into
// tmp/chromium/ by the sparse checkout in scripts/update-to-latest.sh.

import {spawnSync} from 'node:child_process';
import {existsSync} from 'node:fs';
import path from 'node:path';

const scriptsDir = import.meta.dirname;
const repoRoot = path.join(scriptsDir, '..');

const chromiumScriptsDir = process.env.CHROMIUM_PROTOCOL_SCRIPTS_DIR ??
path.join(repoRoot, 'tmp/chromium/third_party/blink/public/devtools_protocol/scripts');
const generator = path.join(chromiumScriptsDir, 'protocol_dts_generator.ts');

if (!existsSync(generator)) {
console.error(`
Could not find Chromium's protocol_dts_generator.ts at:
${generator}

This generator lives in Chromium, not in this repo. To regenerate the types:

* run scripts/update-to-latest.sh, which sparse-checks out Chromium into
Comment thread
Sergei-Rudenkov marked this conversation as resolved.
tmp/chromium/ and then runs this script, or

* point at an existing local Chromium checkout:
CHROMIUM_PROTOCOL_SCRIPTS_DIR=/path/to/src/third_party/blink/public/devtools_protocol/scripts \\
npm run build-protocol-dts
`);
process.exit(1);
}

const {status} = spawnSync(
process.execPath,
[
// The generator is type-stripped by Node. It lives outside of scripts/, so
// the nearest package.json has no "type": "module" and Node would warn.
'--disable-warning=MODULE_TYPELESS_PACKAGE_JSON',
Comment thread
Sergei-Rudenkov marked this conversation as resolved.
generator,
'--output-dir', path.join(repoRoot, 'types'),
path.join(repoRoot, 'json/js_protocol.json'),
path.join(repoRoot, 'json/browser_protocol.json'),
],
{stdio: 'inherit'},
);

process.exit(status ?? 1);
2 changes: 1 addition & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "module",
"license": "SEE LICENSE IN https://chromium.googlesource.com/chromium/src/+/main/LICENSE",
"scripts": {
"build-protocol-dts": "node protocol-dts-generator.ts",
"build-protocol-dts": "node build-protocol-dts.mjs",
"type-check": "tsc -p tsconfig.json",
"changelog": "node generate-changelog.mjs"
},
Expand Down
Loading
Loading