Skip to content

Commit

Permalink
Added fallback logic if setting willReadFrequently attribute fails
Browse files Browse the repository at this point in the history
  • Loading branch information
gianmarco27 authored May 14, 2024
1 parent 53cbd3b commit cee8bbe
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/readers/BrowserCodeReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export class BrowserCodeReader {
public static createCanvasFromMediaElement(mediaElement: HTMLVisualMediaElement) {

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

if (!ctx) {
throw new Error('Couldn\'t find Canvas 2D Context.');
Expand Down Expand Up @@ -1032,8 +1032,13 @@ export class BrowserCodeReader {
/**
* The HTML canvas element context.
*/
let captureCanvasContext = captureCanvas.getContext('2d');

let captureCanvasContext;

Check failure on line 1035 in src/readers/BrowserCodeReader.ts

View workflow job for this annotation

GitHub Actions / build

Variable 'captureCanvasContext' implicitly has type 'any' in some locations where its type cannot be determined.
try {
captureCanvasContext = elem.getContext('2d', { willReadFrequently: true }) as CanvasRenderingContext2D;

Check failure on line 1037 in src/readers/BrowserCodeReader.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'elem'.
} catch (e) {
captureCanvasContext = elem.getContext('2d');

Check failure on line 1039 in src/readers/BrowserCodeReader.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'elem'.
}

// cannot proceed w/o this
if (!captureCanvasContext) {
throw new Error('Couldn\'t create canvas for visual element scan.');
Expand Down

0 comments on commit cee8bbe

Please sign in to comment.