ES2015, also supporting pseudo selectors ::before and ::after .
function listFonts () { let fonts = [] for (let node of document.querySelectorAll('*')) { if (!node.style) continue for (let pseudo of ['', ':before', ':after']) { let fontFamily = getComputedStyle(node, pseudo).fontFamily fonts = fonts.concat(fontFamily.split(/\n*,\n*/g)) } } // Remove duplicate elements from fonts array // and remove the surrounding quotes around elements return [...new Set(fonts)] .map(font => font.replace(/^\s*['"]([^'"]*)['"]\s*$/, '$1').trim()) }
When you run this, StackOverflow returns ["Times", "Arial", "Helvetica Neue", "Helvetica", "sans-serif", "BlinkMacSystemFont", "Consolas", "Menlo", "Monaco", "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", "monospace"]
source share