Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: set willReadFrequently attribute for multiple readback operations in scan method. #134

Merged
merged 2 commits into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
/**
* 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 Expand Up @@ -1067,7 +1072,7 @@
}

try {
BrowserCodeReader.drawImageOnCanvas(captureCanvasContext, element);

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

View workflow job for this annotation

GitHub Actions / build

Variable 'captureCanvasContext' implicitly has an 'any' type.
const result = this.decodeFromCanvas(captureCanvas);
callbackFn(result, undefined, controls);
lastTimeoutId = setTimeout(loop, this.options.delayBetweenScanSuccess);
Expand Down
Loading