Skip to content

Commit

Permalink
Change PDF reading behavior to not fail completely on Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
jmerle committed Dec 31, 2024
1 parent 960ff11 commit f8c705c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Added support for the codeforces.net mirror of Codeforces and fixed support for the codeforc.es mirror on problem pages
- Fixed the Lanqiao problem parser
- Fixed the Kattis parser for samples containing only output
- Changed the behavior of parsers that need to read PDFs (like the ones on UVa Online Judge) to parse as much of the problem as possible on Firefox, rather than crashing due to Firefox bug [1757836](https://bugzilla.mozilla.org/show_bug.cgi?id=1757836)

## [2.57.1](https://github.com/jmerle/competitive-companion/releases/tag/2.57.1) (2024-11-15)
- Added the `X-Competitive-Companion` header to HTTP requests sent by Competitive Companion to indicate to the receiving end that the request is coming from Competitive Companion (thanks [@touhidurrr](https://github.com/touhidurrr))
Expand Down
16 changes: 15 additions & 1 deletion src/utils/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,21 @@ export async function readPdf(pdfUrl: string): Promise<string[]> {

for (let i = 0; i < pdf._pdfInfo.numPages; i++) {
const page = await pdf.getPage(i + 1);
const textContent = await page.getTextContent();

let textContent;
try {
textContent = await page.getTextContent();
} catch (err) {
if ((err as any)?.message === 'Permission denied to access property "autoAllocateChunkSize"') {
console.trace(err);
console.warn(
'Competitive Companion cannot read PDFs in Firefox due to Firefox bug 1757836: https://bugzilla.mozilla.org/show_bug.cgi?id=1757836',
);
return [];
}

throw err;
}

let currentLine = '';
let lastX = -1;
Expand Down

0 comments on commit f8c705c

Please sign in to comment.