fix(workers/blurhash): Don't use OffscreenCanvas (#1398)

This commit is contained in:
Sorin Davidoi 2019-08-18 14:14:11 +02:00 committed by Nolan Lawson
parent 03dff1c595
commit 823a7abebf

View file

@ -2,7 +2,11 @@ import { decode as decodeBlurHash } from 'blurhash'
import registerPromiseWorker from 'promise-worker/register'
import { BLURHASH_RESOLUTION as RESOLUTION } from '../_static/blurhash'
const OFFSCREEN_CANVAS = typeof OffscreenCanvas === 'function'
const isChrome = /Chrome/.test(navigator.userAgent)
// Disabled in Chrome because convertToBlob() is slow
// https://github.com/nolanlawson/pinafore/issues/1396
const OFFSCREEN_CANVAS = !isChrome && typeof OffscreenCanvas === 'function'
? new OffscreenCanvas(RESOLUTION, RESOLUTION) : null
const OFFSCREEN_CANVAS_CONTEXT_2D = OFFSCREEN_CANVAS
? OFFSCREEN_CANVAS.getContext('2d') : null