Check for canvas extract permission when initializing favicon service
Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
parent
5eb9c030fd
commit
9e2ee1e66a
2 changed files with 19 additions and 0 deletions
1
changelog.d/check-canvas-extract-permission.fix
Normal file
1
changelog.d/check-canvas-extract-permission.fix
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Check for canvas extract permission when initializing favicon service
|
||||||
|
|
@ -1,3 +1,19 @@
|
||||||
|
const checkCanvasExtractPermission = () => {
|
||||||
|
const canvas = document.createElement('canvas');
|
||||||
|
canvas.width = 1;
|
||||||
|
canvas.height = 1;
|
||||||
|
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
if (!ctx) return false;
|
||||||
|
|
||||||
|
ctx.fillStyle = '#0f161e';
|
||||||
|
ctx.fillRect(0, 0, 1, 1);
|
||||||
|
|
||||||
|
const { data } = ctx.getImageData(0, 0, 1, 1);
|
||||||
|
|
||||||
|
return data.join(',') === '15,22,30,255';
|
||||||
|
};
|
||||||
|
|
||||||
const createFaviconService = () => {
|
const createFaviconService = () => {
|
||||||
const favicons = []
|
const favicons = []
|
||||||
const faviconWidth = 128
|
const faviconWidth = 128
|
||||||
|
|
@ -5,6 +21,8 @@ const createFaviconService = () => {
|
||||||
const badgeRadius = 32
|
const badgeRadius = 32
|
||||||
|
|
||||||
const initFaviconService = () => {
|
const initFaviconService = () => {
|
||||||
|
if (!checkCanvasExtractPermission()) return;
|
||||||
|
|
||||||
const nodes = document.querySelectorAll('link[rel="icon"]')
|
const nodes = document.querySelectorAll('link[rel="icon"]')
|
||||||
nodes.forEach(favicon => {
|
nodes.forEach(favicon => {
|
||||||
if (favicon) {
|
if (favicon) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue