Skip to content

Commit cee8bbe

Browse files
authored
Added fallback logic if setting willReadFrequently attribute fails
1 parent 53cbd3b commit cee8bbe

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/readers/BrowserCodeReader.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ export class BrowserCodeReader {
315315
public static createCanvasFromMediaElement(mediaElement: HTMLVisualMediaElement) {
316316

317317
const canvas = BrowserCodeReader.createCaptureCanvas(mediaElement);
318-
const ctx = canvas.getContext('2d', { willReadFrequently: true });
318+
const ctx = canvas.getContext('2d');
319319

320320
if (!ctx) {
321321
throw new Error('Couldn\'t find Canvas 2D Context.');
@@ -1032,8 +1032,13 @@ export class BrowserCodeReader {
10321032
/**
10331033
* The HTML canvas element context.
10341034
*/
1035-
let captureCanvasContext = captureCanvas.getContext('2d');
1036-
1035+
let captureCanvasContext;
1036+
try {
1037+
captureCanvasContext = elem.getContext('2d', { willReadFrequently: true }) as CanvasRenderingContext2D;
1038+
} catch (e) {
1039+
captureCanvasContext = elem.getContext('2d');
1040+
}
1041+
10371042
// cannot proceed w/o this
10381043
if (!captureCanvasContext) {
10391044
throw new Error('Couldn\'t create canvas for visual element scan.');

0 commit comments

Comments
 (0)