youhackme / Toggle

Ever seen a nice website and asked yourself what theme or plugins they are using? This is what this project is all about. Started back in 2014. Re-written from the ground up in 2017 using Laravel 5, MySQL, Redis and Elastic.
1 stars 0 forks source link

Identify fonts being used on website #755

Open youhackme opened 7 years ago

youhackme commented 7 years ago

Identify fonts being used on website. See font ninja tool and whatruns code.

youhackme commented 6 years ago

Font rendering can be done through Chrome headless browsing:

https://stackoverflow.com/questions/47911613/fetch-rendered-font-using-chrome-headless-browser/47914111#47914111

Puppeteer doesn't expose this API directly, but it's possible to use the raw devtools protocol to get the "Rendered Fonts" information:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch()
  const page = await browser.newPage()
  await page.goto('https://www.stackoverflow.com/')

  await page._client.send('DOM.enable')
  await page._client.send('CSS.enable')
  const doc = await page._client.send('DOM.getDocument')
  const node = await page._client.send('DOM.querySelector', {nodeId: doc.root.nodeId, selector: 'h1'})
  const fonts = await page._client.send('CSS.getPlatformFontsForNode', {nodeId: node.nodeId})

  console.log(fonts)
  await browser.close()
})()

The devtools protocol documentation for CSS.getPlatformFontsForNode can be found here: https://chromedevtools.github.io/devtools-protocol/tot/CSS/#method-getPlatformFontsForNode