Skip to content

Commit

Permalink
Merge pull request #134 from gianmarco27/canvas2D-willReadFrequently
Browse files Browse the repository at this point in the history
 Fix: set willReadFrequently attribute for multiple readback operations in scan method.
  • Loading branch information
werthdavid committed May 22, 2024
2 parents 8f477fa + cee8bbe commit 7631880
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/readers/BrowserCodeReader.ts
Original file line number Diff line number Diff line change
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.

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'.

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'.

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 7631880

Please sign in to comment.