ChromeDevTools / devtools-protocol

Chrome DevTools Protocol
https://chromedevtools.github.io/devtools-protocol/
BSD 3-Clause "New" or "Revised" License
1.15k stars 226 forks source link

Using Devtools protocol to get fonts used. #167

Closed anuragphadke closed 5 years ago

anuragphadke commented 5 years ago

I want to understand what fonts are being used to render a page. Currently, I am doing the following:

  const nodes = await page._client.send('DOM.querySelectorAll', {nodeId: doc.root.nodeId, selector: 'div'})

  for (var nodeId of nodes.nodeIds) {
    console.log(await page._client.send('CSS.getPlatformFontsForNode', {nodeId: nodeId}))
}

This gives me a list of fonts that were used, however, I am looking for some more info:

Some of this information is available via DevTools -> Application -> Frames -> Top -> Fonts (screenshot attached).

Any idea how I can get this info via devtools-protocol?

image

JoelEinbinder commented 5 years ago

Take a look at the fontsUpdated event. https://vanilla.aslushnikov.com/?CSS.fontsUpdated

It should be sent after enabling the page domain. Use createCDPSession in puppeteer instead of _client.

anuragphadke commented 5 years ago

awesome. Thank you so much.