From a70e2f13813a91bd5fd973fd5f410b4ed54ef5f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Sun, 30 Oct 2022 09:21:16 +0100 Subject: [PATCH] Check canvas export permission when initializing FaviconService MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- src/utils/favicon-service.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/utils/favicon-service.ts b/src/utils/favicon-service.ts index 805275fa5..ef372dd40 100644 --- a/src/utils/favicon-service.ts +++ b/src/utils/favicon-service.ts @@ -1,6 +1,22 @@ // Adapted from Pleroma FE // https://git.pleroma.social/pleroma/pleroma-fe/-/blob/ef5bbc4e5f84bb9e8da76a0440eea5d656d36977/src/services/favicon_service/favicon_service.js +const checkCanvasExtractPermission = () => { + const canvas = document.createElement('canvas'); + canvas.width = 1; + canvas.height = 1; + + const ctx = canvas.getContext('2d')!; + if (!ctx) return false; + + ctx.fillStyle = '#0482d8'; + ctx.fillRect(0, 0, 1, 1); + + const { data } = ctx.getImageData(0, 0, 1, 1); + + return data.join(',') === '4,130,216,255'; +}; + type Favicon = { favcanvas: HTMLCanvasElement; favimg: HTMLImageElement; @@ -17,6 +33,8 @@ const createFaviconService = () => { /** Start the favicon service */ const initFaviconService = (): void => { + if (!checkCanvasExtractPermission()) return; + const nodes: NodeListOf = document.querySelectorAll('link[rel="icon"]'); nodes.forEach(favicon => { if (favicon) {