Skip to content

Commit 47776f6

Browse files
fix: add Promise.try polyfill (closes #51)
1 parent b4f513a commit 47776f6

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/pdfjs-serverless/polyfills.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ if (typeof Promise.withResolvers === 'undefined') {
1010
}
1111
}
1212

13+
// `Promise.try` is used by PDF.js v5.6+ in its message handler.
14+
// Not yet available in Safari < 18.2 and Node.js < 23.
15+
if (typeof Promise.try === 'undefined') {
16+
Promise.try = function (fn, ...args) {
17+
return new Promise(resolve => resolve(fn(...args)))
18+
}
19+
}
20+
1321
// `Map.prototype.getOrInsertComputed` is used extensively by PDF.js v5.6+.
1422
// Not yet available in most runtimes.
1523
if (typeof Map.prototype.getOrInsertComputed === 'undefined') {

0 commit comments

Comments
 (0)