Short answer: there is no reliable way that I know of other than checking sources
Some background: I am the author of chrome-devtools-kotlin, a Kotlin client for the CDP, and I faced the exact same issue when trying to provide a type-safe API that respected the target domains available to each target types.
There is technically a Schema domain that allows to list domains and is supported by the Page
, ServiceWorker
, and SharedWorker
target types (AFAICT), but it's deprecated now, so I'm not sure we can really rely on it.
Eventually, I didn't find a better way than looking at the Chromium sources, and this is extremely brittle. The current query I run is the following:
https://source.chromium.org/search?q=%22session-%3ECreateAndAddHandler%22%20f:devtools&ss=chromium
Every few months or so, I go check the Chromium sources again and check the domains, and then update my own target_types.json which is one of my inputs for codegen. If I manage to understand how to use the chrome search API, I might automate this tedious process someday but it will still be inherently brittle (no matter how convenient I can make it).
I also have a test that runs a zenika/alpine-chrome:latest
Docker container, and then accesses the deprecated schema
domain to check if the server supports some domains that my library doesn't list as supported. But one day the schema domain may be entirely removed, so I need to change strategies. Another option for this test would be to use the /json/protocol
HTTP API instead, but I'm not sure it discriminates target types.