stephanrauh / ngx-extended-pdf-viewer

A full-blown PDF viewer for Angular 16, 17, and beyond
https://pdfviewer.net
Apache License 2.0
450 stars 167 forks source link

Unhandled Promise rejection: Promise.withResolvers is not a function #2301

Open Congchuabongbong opened 2 months ago

Congchuabongbong commented 2 months ago

I am installing and testing version ^20.0.0-alpha.1 and see the error as shown in the picture: image_2024_04_17T08_29_24_951Z image_2024_04_17T08_29_39_510Z

stephanrauh commented 2 months ago

Which browser are you using? According to https://caniuse.com/?search=promise.withResolvers, browser support should be pretty good - with the exception of Safari: only the latest version of Safari supports this method.

image
Congchuabongbong commented 2 months ago

Currently I'm using Chrome!

stephanrauh commented 2 months ago

Yes, you're right - I was blind yesterday, I should have seen it from your screenshot. Which version are you using?

Congchuabongbong commented 2 months ago

i'm using latest version! exactly it's 124.0.6367.61

stephanrauh commented 2 months ago

That's weird. Nonetheless, the withResolvers() function is fairly new, so it makes sense to check whether the browser supports it. I'm preparing a browser switch.

Congchuabongbong commented 2 months ago

Ok, I hope you will find the cause and I will also try to find the cause

stephanrauh commented 2 months ago

The improvement is going to land with version 20.0.0-alpha.2.

stephanrauh commented 2 months ago

Version 20.0.0-alpha.2 was buggy. It always used the ES5 version of the code. Version 20.0.0-alpha.3 uses a more clever approach.

SimonKunz commented 1 month ago

Hey @stephanrauh,

unfortunately we still have trouble with this on safari. We tested this on Safari 15.6, 16.5 and 17.4.

17.4 works, but both older Browsers don't work.

It seems like zoneJS is messing things up here. When zoneJS is monkey patching the browser apis it's also monkey patching the 'withResolvers'-Function. So the function is not undefined any more, but still throws the error when invoked.

Is there any chance to fix this?

Thank you!

stephanrauh commented 1 month ago

@SimonKunz That's nasty. We have to talk serious with zone.js! :)

Jokes aside, I'm sure there's a way to solve it, but I'd like to talk you into finding the solution yourself and send me a pull request or to describe what I need to modify. I believe it's a task you can manage, and it helps me to catch up with the work that piled up during my vacations.

Browser detection happens in a file called op-chaining-support.js. That's a very simple class that runs some test. If they pass, the flag window.ngxExtendedPdfViewerCanRunModernJSCode is set to true, and otherwise the file crashed, so the flag remains undefined. Maybe you manage to call the withResolvers() function to enforce the crash, or you find a different class/method/function that has been introduced after Safari 17.4.