Created
January 12, 2021 15:02
-
-
Save sontek/2fa71697fdd6355352fb41f14371d064 to your computer and use it in GitHub Desktop.
A way to get all rendered fonts on a page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
save this file as "rendered_fonts.js" | |
yarn add puppeteer | |
node rendered_fonts.js | |
*/ | |
const puppeteer = require('puppeteer'); | |
(async () => { | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
await page.goto('https://eldarion.com/'); | |
await page._client.send('DOM.enable'); | |
await page._client.send('CSS.enable'); | |
const fonts = []; | |
const doc = await page._client.send('DOM.getDocument'); | |
const nodes = await page._client.send('DOM.querySelectorAll', { | |
nodeId: doc.root.nodeId, | |
selector: '*' | |
}); | |
const stylesForNodes = [] | |
for (id of nodes.nodeIds) { | |
const styles = await page._client.send( | |
'CSS.getPlatformFontsForNode', {nodeId: id} | |
) | |
const fonts = styles['fonts']; | |
if(fonts.length > 0) { | |
stylesForNodes.push(fonts); | |
} | |
} | |
console.log(stylesForNodes); | |
await browser.close(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment