Skip to content

Commit

Permalink
fix: default to fonts check
Browse files Browse the repository at this point in the history
  • Loading branch information
abrahamjuliot committed Aug 16, 2022
1 parent 6e0a75c commit b701222
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 157 deletions.
302 changes: 151 additions & 151 deletions docs/creep.js

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions src/fonts/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { captureError } from '../errors'
import { PHANTOM_DARKNESS, lieProps } from '../lies'
import { PHANTOM_DARKNESS, lieProps, getRandomValues } from '../lies'
import { hashMini } from '../utils/crypto'
import { CSS_FONT_FAMILY, createTimer, queueEvent, EMOJIS, logTestResult, performanceLogger, hashSlice, formatEmojiSet, LIKE_BRAVE_RESISTANCE } from '../utils/helpers'
import { CSS_FONT_FAMILY, createTimer, queueEvent, EMOJIS, logTestResult, performanceLogger, hashSlice, formatEmojiSet } from '../utils/helpers'
import { patch, html, HTMLNote, count } from '../utils/html'

// inspired by Lalit Patel's fontdetect.js
Expand Down Expand Up @@ -92,7 +92,6 @@ const DesktopAppFonts = {
const APPLE_FONTS = Object.keys(MacOSFonts).map((key) => MacOSFonts[key]).flat()
const WINDOWS_FONTS = Object.keys(WindowsFonts).map((key) => WindowsFonts[key]).flat()
const DESKTOP_APP_FONTS = (
LIKE_BRAVE_RESISTANCE /* unsupported & poisonous */ ? [] :
Object.keys(DesktopAppFonts).map((key) => DesktopAppFonts[key]).flat()
)
const LINUX_FONTS = [
Expand Down Expand Up @@ -182,8 +181,16 @@ export default async function getFonts() {
}
}

const getFontFaceLoadFonts = async (fontList) => {
const getFontFaceLoadFonts = async (fontList: string[]) => {
try {
if (!document.fonts.check(`0px "${getRandomValues()}"`)) {
const fontsChecked = fontList.reduce((acc, font) => {
const found = document.fonts.check(`0px "${font}"`)
if (found) acc.push(font)
return acc
}, [] as string[])
return fontsChecked
}
const fontFaceList = fontList.map((font) => new FontFace(font, `local("${font}")`))
const responseCollection = await Promise
.allSettled(fontFaceList.map((font) => font.load()))
Expand Down Expand Up @@ -375,7 +382,7 @@ export function fontsHTML(fp) {
)
})(fontFaceLoadFonts)}</div>
<div>apps: ${(apps || []).length ? apps.join(', ') : HTMLNote.UNSUPPORTED}</div>
<div class="block-text-large help relative" title="FontFace.load()">
<div class="block-text-large help relative" title="FontFace.load()\nFontFaceSet.check()">
${fontFaceLoadFonts.join(', ') || HTMLNote.UNSUPPORTED}
</div>
<div class="block-text help relative" title="${blockHelpTitle}">
Expand Down
2 changes: 1 addition & 1 deletion src/lies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,4 +930,4 @@ function liesHTML(fp: LiesFingerprint, pointsHTML: string): string {
}${pointsHTML}</div>`
}

export { documentLie, createLieDetector, PHANTOM_DARKNESS, PARENT_PHANTOM, lieProps, prototypeLies, lieRecords, getLies, getPluginLies, liesHTML }
export { getRandomValues, documentLie, createLieDetector, PHANTOM_DARKNESS, PARENT_PHANTOM, lieProps, prototypeLies, lieRecords, getLies, getPluginLies, liesHTML }

0 comments on commit b701222

Please sign in to comment.