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

Mobile Chrome crash on Pinch and Zoom > 200% ( Android 13,built in Web View but latest Chrome as well) #2568

Closed
dtrbi opened this issue Sep 16, 2024 · 42 comments
Assignees
Labels

Comments

@dtrbi
Copy link

dtrbi commented Sep 16, 2024

Hi,

we found one issue with Pinch and Zoom on the mobile Chrome and Android 13.
We can reproduce even with https://pdfviewer.net/extended-pdf-viewer/simple. Just try to zoom and it will crash.

We can not reproduce on Firefox Android or any browser on Android 14. As well https://mozilla.github.io/pdf.js/web/viewer.html works on Android 13 and does not crash.

All latest updates are installed on Android 13 device.

Version info

  • 21.3.8

Demo PDF file
Any .pdf file

Thank you and best regards.

@stephanrauh
Copy link
Owner

I don't own an Android device, let alone Android 13, so there's little I can do.

However, does this bug occur on https://mozilla.github.io/pdf.js/web/viewer.html or https://mozilla.github.io/pdf.js/legacy/web/viewer.html? If so, it's a bug of the base library, and you can forward it to the pdf.js team.

@stephanrauh stephanrauh self-assigned this Sep 16, 2024
@stephanrauh stephanrauh added bug Something isn't working I'd like to help but it's difficult You've raised an issue that's just right - but for some reason, it's hard to solve. labels Sep 16, 2024
@dtrbi
Copy link
Author

dtrbi commented Sep 30, 2024

On both https://mozilla.github.io/pdf.js/web/viewer.html and https://mozilla.github.io/pdf.js/legacy/web/viewer.html it is working fine.

But as already said we can reproduce problem on most of Android 13 devices and some of Android 14 (mostly low level) on https://pdfviewer.net/extended-pdf-viewer/simple.

Steps to reproduce:

  1. Zoom in/zoom out with pinch and zoom several times

I am pretty sure there is some kind of memory leak.

Thank you for all your hard work and making our life with Angular and PDF.js much easier.

@raphjutras
Copy link

I can confirm that we also experience this problem on both Android and iOS.

It will happen when we zoom a lot on the PDF: ex, on construction plans, they are really zoomed-out and to be able to see any detail, the user must pinch to zoom it, more than 200%.

Example PDF file: https://vancouver.ca/files/cov/sample-drawing-package-1and2family.pdf

I have noticed that, while pinch-zooming, the screen will tear and freeze.
Our app also crashed when zooming-in-out multiple time (with a bigger PDF plan than the sample provided here).
Also, while zoomed, if we move to left-right, some part of the PDF just dissapear/blank. we have to zoom-out then re-zoom in to see it. There is clearly somethign strange happening.

@stephanrauh
Copy link
Owner

Phew. First of all, sorry for answering late. It's because I'm ill.

However, I still don't know how to solve the issue. I understand there's a difference between my fork of pdf.js and the original that causes crashes. But how to solve that? As I've mentioned earlier, I don't own an Android device, so I'm at a loss. @raphjutras I do own an iOS device, so maybe I can debug the problem, but it's still a major challenge.

Can I talk you into helping me? Does the debugger or the console show anything useful?

@raphjutras
Copy link

raphjutras commented Oct 6, 2024

@stephanrauh I have made a simple test with original pdf.js in my Safari browser (iPhone) by accessing PDF.js official demo:
https://mozilla.github.io/pdf.js/web/viewer.html

It seem that the original script suffer from same tearing bug when pinch-zooming a lot.

I havent had the chance to look at debuger/console.

@raphjutras
Copy link

Just did a research on PDF.js github, looks like the issue had already been flagged..!
mozilla/pdf.js#17713

@dtrbi
Copy link
Author

dtrbi commented Oct 7, 2024

Phew. First of all, sorry for answering late. It's because I'm ill.

Get well soon. Wishing you a speedy recovery. This bug is not so important.

@stephanrauh
Copy link
Owner

@raphjutras Are your referring to this workaround?

.pdfViewer .canvasWrapper,
.pdfViewer .page canvas[zooming] {
  width: inherit !important;
}

@raphjutras
Copy link

@stephanrauh Yes, I will definitely need to give this a try!

@raphjutras
Copy link

On both https://mozilla.github.io/pdf.js/web/viewer.html and https://mozilla.github.io/pdf.js/legacy/web/viewer.html it is working fine.

But as already said we can reproduce problem on most of Android 13 devices and some of Android 14 (mostly low level) on https://pdfviewer.net/extended-pdf-viewer/simple.
.

I think this might be two separate/different bugs.. Tearing is something, app crashing is something else hehe

@stephanrauh
Copy link
Owner

Yes, you're right. I hoped it might be the same bug, but it was a wild shot.

@stephanrauh
Copy link
Owner

What about version 22.0.0? Currently, that's an alpha version, but it's running on a new version of pdf.js. Maybe that solves the issue?

@raphjutras
Copy link

Hello @stephanrauh, I have installed 21.4.6 and I still encouter problems when zomming a lot.
I tried installing version 22.0.0 by adding this line to my package.json:
"ngx-extended-pdf-viewer": "git://github.com/stephanrauh/ngx-extended-pdf-viewer.git#22.0.0-alpha.2"

It successfully installs it, I can see the changes in node_modules folder, however I am unable to build my Angular app after that, it will hrow a lot of errors (about my own components? I don't know why) and the last error is:
Error: src/app/shared/shared.module.ts:79:44 - error TS2307: Cannot find module 'ngx-extended-pdf-viewer' or its corresponding type declarations. [ng] [ng] 79 import { NgxExtendedPdfViewerModule } from 'ngx-extended-pdf-viewer';

So I can't really test v22.0.0 on browser or mobile.

@dtrbi
Copy link
Author

dtrbi commented Nov 27, 2024

What about version 22.0.0? Currently, that's an alpha version, but it's running on a new version of pdf.js. Maybe that solves the issue?

Same. :(
It must be some memory leak somewhere but I do not have skills to debug this library.

Base library does not have this problem but is missing nice Angular integration.

@stephanrauh
Copy link
Owner

I still don't know how to reproduce and find the bug. Does it require Android 13? Thing is, I don't own an Android device.

@dtrbi
Copy link
Author

dtrbi commented Dec 18, 2024

If you visit https://pdfviewer.net/extended-pdf-viewer/simple with Chrome on a mid-range phone (regardless of the Android version) or Safari on an iPhone and try zooming in and out several times using the pinch gesture, it should crash or freeze.

It might be possible to reproduce this using Chrome Dev Tools, but we did not succeed, most likely because the desktop is much more powerful.

@stephanrauh
Copy link
Owner

We're getting closer. I've tested pinching and zooming on my iPad for several minutes. I didn't ovserve a crash, but the rendering time went up tremendously.

I also suspect that it's not necessary to use touch gestures. Modifiying the zoom setting repeatedly does the trick just as well.

@joelutting
Copy link

I'm having what seems to be the same issue in ionic capacitor.

It works and displays the PDF, but then when I pinch zoom a few times it crashes.

here is the console from android studio running on a real device (Samsung A53) - not sure if this will help. Also do you think going to a previous version would fix this issue?

2025-01-21 20:28:23.790 5767-5767 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/3581.1979fc5e688587d8.js - Line 1 - Msg: TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-21 20:28:23.792 5767-5767 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/polyfills.c3a9e4b87df5be46.js - Line 1 - Msg: Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-21 20:28:23.792 5767-5767 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/3581.1979fc5e688587d8.js - Line 1 - Msg: TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-21 20:28:23.793 5767-5767 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/polyfills.c3a9e4b87df5be46.js - Line 1 - Msg: Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-21 20:28:23.832 5767-5767 Capacitor io.ionic.i4m.myfieldwise E JavaScript Error: {"type":"js.error","error":{"message":"Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')","url":"https://localhost/polyfills.c3a9e4b87df5be46.js","line":1,"col":5336,"errorObject":"{}"}}
2025-01-21 20:28:23.842 5767-5767 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/3581.1979fc5e688587d8.js - Line 1 - Msg: TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-21 20:28:23.843 5767-5767 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/polyfills.c3a9e4b87df5be46.js - Line 1 - Msg: Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-21 20:28:23.848 5767-5767 Capacitor io.ionic.i4m.myfieldwise E JavaScript Error: {"type":"js.error","error":{"message":"Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')","url":"https://localhost/polyfills.c3a9e4b87df5be46.js","line":1,"col":5336,"errorObject":"{}"}}
2025-01-21 20:28:23.855 5767-5767 Capacitor io.ionic.i4m.myfieldwise E JavaScript Error: {"type":"js.error","error":{"message":"Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')","url":"https://localhost/polyfills.c3a9e4b87df5be46.js","line":1,"col":5336,"errorObject":"{}"}}
2025-01-21 20:28:23.860 5767-5767 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/3581.1979fc5e688587d8.js - Line 1 - Msg: TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-21 20:28:23.860 5767-5767 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/polyfills.c3a9e4b87df5be46.js - Line 1 - Msg: Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-21 20:28:23.877 5767-5767 Capacitor io.ionic.i4m.myfieldwise E JavaScript Error: {"type":"js.error","error":{"message":"Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')","url":"https://localhost/polyfills.c3a9e4b87df5be46.js","line":1,"col":5336,"errorObject":"{}"}}
2025-01-21 20:28:24.012 5767-5767 ViewRootIm...nActivity] io.ionic.i4m.myfieldwise I ViewPostIme pointer 1
2025-01-21 20:28:25.051 5767-5767 ViewRootIm...nActivity] io.ionic.i4m.myfieldwise I ViewPostIme pointer 0
2025-01-21 20:28:25.151 5767-5767 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/3581.1979fc5e688587d8.js - Line 1 - Msg: TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-21 20:28:25.152 5767-5767 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/polyfills.c3a9e4b87df5be46.js - Line 1 - Msg: Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-21 20:28:25.172 5767-5767 Capacitor io.ionic.i4m.myfieldwise E JavaScript Error: {"type":"js.error","error":{"message":"Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')","url":"https://localhost/polyfills.c3a9e4b87df5be46.js","line":1,"col":5336,"errorObject":"{}"}}
2025-01-21 20:28:25.204 5767-5767 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/3581.1979fc5e688587d8.js - Line 1 - Msg: TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-21 20:28:25.205 5767-5767 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/polyfills.c3a9e4b87df5be46.js - Line 1 - Msg: Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-21 20:28:25.416 5767-5767 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/3581.1979fc5e688587d8.js - Line 1 - Msg: TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-21 20:28:25.416 5767-5767 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/polyfills.c3a9e4b87df5be46.js - Line 1 - Msg: Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-21 20:28:25.418 5767-5767 Capacitor io.ionic.i4m.myfieldwise E JavaScript Error: {"type":"js.error","error":{"message":"Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')","url":"https://localhost/polyfills.c3a9e4b87df5be46.js","line":1,"col":5336,"errorObject":"{}"}}
2025-01-21 20:28:25.604 5767-5767 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/3581.1979fc5e688587d8.js - Line 1 - Msg: TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-21 20:28:25.615 5767-5767 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/polyfills.c3a9e4b87df5be46.js - Line 1 - Msg: Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-21 20:28:27.055 5767-5767 ViewRootIm...nActivity] io.ionic.i4m.myfieldwise I ViewPostIme pointer 1
2025-01-21 20:28:29.660 5767-5767 ViewRootIm...nActivity] io.ionic.i4m.myfieldwise I ViewPostIme pointer 0
2025-01-21 20:28:29.763 5767-5767 ViewRootIm...nActivity] io.ionic.i4m.myfieldwise I ViewPostIme pointer 1
2025-01-21 20:28:29.769 5767-5767 ViewRootIm...nActivity] io.ionic.i4m.myfieldwise I ViewPostIme pointer 0
2025-01-21 20:28:29.785 5767-5767 ViewRootIm...nActivity] io.ionic.i4m.myfieldwise I ViewPostIme pointer 1
2025-01-21 20:28:29.834 5767-5862 cr_ChildProcessConn io.ionic.i4m.myfieldwise W onServiceDisconnected (crash or killed by oom): pid=5892 bindings:W S
2025-01-21 20:28:29.846 5767-5767 Capacitor io.ionic.i4m.myfieldwise E JavaScript Error: {"type":"js.error","error":{"message":"Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')","url":"https://localhost/polyfills.c3a9e4b87df5be46.js","line":1,"col":5336,"errorObject":"{}"}}
2025-01-21 20:28:29.851 5767-5767 Choreographer io.ionic.i4m.myfieldwise I Skipped 530 frames! The application may be doing too much work on its main thread.
2025-01-21 20:28:29.983 5767-5805 OpenGLRenderer io.ionic.i4m.myfieldwise D CacheManager::trimMemory(15)
2025-01-21 20:28:30.020 5767-6317 OpenGLRenderer io.ionic.i4m.myfieldwise I Davey! duration=4555ms; Flags=0, FrameTimelineVsyncId=20934151, IntendedVsync=1868423696493774, Vsync=1868428119861584, InputEventId=648176844, HandleInputStart=1868428133829050, AnimationStart=1868428133858050, PerformTraversalsStart=1868428144199281, DrawStart=1868428148445550, FrameDeadline=1868424138817911, FrameInterval=1868428124049358, FrameStartTime=8345977, SyncQueued=1868428166117319, SyncStart=1868428168448319, IssueDrawCommandsStart=1868428170218396, SwapBuffers=1868428248322550, FrameCompleted=1868428254306204, DequeueBufferDuration=967807, QueueBufferDuration=1643846, GpuCompleted=1868428253337204, SwapBuffersCompleted=1868428254306204, DisplayPresentTime=1868414889347790, CommandSubmissionCompleted=1868428248322550,
2025-01-21 20:28:30.069 5767-5767 chromium io.ionic.i4m.myfieldwise E [ERROR:aw_browser_terminator.cc(165)] Renderer process (5892) crash detected (code -1).
2025-01-21 20:28:30.082 5767-5767 chromium io.ionic.i4m.myfieldwise E [ERROR:aw_browser_terminator.cc(113)] Render process (5892) kill (OOM or update) wasn't handed by all associated webviews, killing application.

@stephanrauh
Copy link
Owner

@timvandermeij Does this ring a bell? I've got some reports that the PDF viewer (more to the point: my fork of it) crashes when pinching on certain Android devices. I'm pretty sure the relevant code is identical on pdf.js and on my fork. The latest report is interesting. It's a long stack trace containing many repetitions, all at the same line of code: "Cannot read properties of undefined (reading 'rotation')".

Any ideas?

@joelutting
Copy link

I sometimes also get the error 'parentOffset not set, cannot scroll' or something along those lines, but scrolling does work.

@stephanrauh
Copy link
Owner

@joelutting Are you initializing the PDF viewer in a hidden div, tab or modal? Usually that doomed to fail, but sometimes it causes the error message you've mention. A missing or incorrect position on the parent container can also cause offsetParent to fail.

@stephanrauh
Copy link
Owner

@joelutting You may want to update to version 22.3.0. I've optimized a few things, so now the library uses slightly less resources and avoids the "offsetParent not set" message.

@timvandermeij
Copy link

timvandermeij commented Jan 26, 2025

@timvandermeij Does this ring a bell? I've got some reports that the PDF viewer (more to the point: my fork of it) crashes when pinching on certain Android devices.

I don't recall having seen reports about this exact issue before, but in general performance on mobile devices might be a bit suboptimal compared to desktop devices given the usually more limited resources. However, it should never crash the browser. It could be a memory leak for example because pinch-zooming can cause quite a lot of rendering operations to happen in series, and while there should be thresholds in place to prevent unnecessary re-rendering I could imagine that that part could be buggy/missing here.

For the issue to be actionable for PDF.js it would be necessary to reproduce it with the default viewer at https://mozilla.github.io/pdf.js/web/viewer.html. If it also reproduces there then it's at least clearer that it's a bug in PDF.js itself rather than in one of the forks, and it makes it easier to debug for us (because in general we don't really know what forks changed, and we have seen cases of forks e.g. using libraries that break PDF.js in "interesting" ways, so that's why we usually ask for a reproducer outside of the fork).

By the way, there is some work going on in mozilla/pdf.js#19128, mozilla/pdf.js#19043 and mozilla/pdf.js#6419 for which the idea is that it'll not only improve rendering quality but also performance on mobile devices. It's in early stages so it's not done yet, but the general performance for mobile devices is being looked at.

@stephanrauh
Copy link
Owner

@joelutting The "reading rotation" bit indicates it might be my bug. Can you set the attribute [minifiedJSLibraries]="false" and send me the stack trace again?

@stephanrauh
Copy link
Owner

@timvandermeij Don't worry, I don't expect you to debug a fork of your library. I tried to avoid interesting changes, if only I need to wrap my head around my own changes two months later. :) Even so, you're absolutely right. You're already helping me a lot!

@joelutting
Copy link

@stephanrauh thanks for looking into this! here is how I have it setup currently, its in a div within the main ion-content block.

Close

this is one a several divs within the each of which is a different main view in the app.

I updated to the latest so package.json shows;

"ngx-extended-pdf-viewer": "^22.3.0",

Here is the stack trace from android studio running it on the device - a samsung galaxy A53. I look at the document - looks great. I pinch zoom in a little, and then a little more and the pdf view goes white. I pinch zoom out slightly and the app crashes.

ViewPostIme pointer 0
2025-01-27 10:44:13.372 28199-28199 ViewRootIm...nActivity] io.ionic.i4m.myfieldwise I ViewPostIme pointer 1
2025-01-27 10:44:13.384 28199-28199 Capacitor/Console io.ionic.i4m.myfieldwise I File: https://localhost/6051.c5a20a6359278469.js - Line 1 - Msg: >>>>> load file
2025-01-27 10:44:13.385 28199-28199 Capacitor/Console io.ionic.i4m.myfieldwise I File: https://localhost/6051.c5a20a6359278469.js - Line 1 - Msg: true
2025-01-27 10:44:13.387 28199-28199 Capacitor/Plugin io.ionic.i4m.myfieldwise V To native (Capacitor plugin): callbackId: 104997680, pluginId: Filesystem, methodName: readFile
2025-01-27 10:44:13.388 28199-28199 Capacitor io.ionic.i4m.myfieldwise V callback: 104997680, pluginId: Filesystem, methodName: readFile, methodData: {"path":"documents/01M5YAXHPKTKO7IUKWMBALRQVVUS5FDV44.pdf","directory":"DATA"}
2025-01-27 10:44:13.441 28199-28199 Capacitor/Console io.ionic.i4m.myfieldwise I File: https://localhost/6051.c5a20a6359278469.js - Line 1 - Msg: diaply pdf inline<<<<<<<<<<<<<<<<<<<<<<
2025-01-27 10:44:13.503 28199-28347 Capacitor io.ionic.i4m.myfieldwise D Handling local request: https://localhost/assets/viewer-4.7.717.mjs
2025-01-27 10:44:13.585 28199-28348 Capacitor io.ionic.i4m.myfieldwise D Handling local request: https://localhost/assets/locale/locale.json
2025-01-27 10:44:13.633 28199-28199 AssistStructure io.ionic.i4m.myfieldwise I Flattened final assist data: 15676 bytes, containing 1 windows, 20 views
2025-01-27 10:44:13.635 28199-28347 Capacitor io.ionic.i4m.myfieldwise D Handling local request: https://localhost/assets/pdf.worker-4.7.717.mjs
2025-01-27 10:44:13.647 28199-28347 Capacitor io.ionic.i4m.myfieldwise D Handling local request: https://localhost/assets/locale/en-US/viewer.ftl
2025-01-27 10:44:13.850 28199-28199 Capacitor/Console io.ionic.i4m.myfieldwise I File: https://localhost/assets/viewer-4.7.717.mjs - Line 38 - Msg: PDF 7806c3ab2e06524ea327d24d10e43670 [1.5 Adobe PDF Library 15.0 / Acrobat PDFMaker 15 for Word] (PDF.js: 4.7.717 [066eb3e7b]) modified by ngx-extended-pdf-viewer 22.3.0
2025-01-27 10:44:13.880 28199-28199 AssistStructure io.ionic.i4m.myfieldwise I Flattened final assist data: 15548 bytes, containing 1 windows, 20 views
2025-01-27 10:44:13.932 28199-28199 Capacitor/Console io.ionic.i4m.myfieldwise I File: https://localhost/assets/pdf.worker-4.7.717.mjs - Line 60 - Msg: Warning: TT: undefined function: 32
2025-01-27 10:44:17.094 28199-28199 ViewRootIm...nActivity] io.ionic.i4m.myfieldwise I ViewPostIme pointer 0
2025-01-27 10:44:17.585 28199-28199 ViewRootIm...nActivity] io.ionic.i4m.myfieldwise I ViewPostIme pointer 1
2025-01-27 10:44:18.759 28199-28199 ViewRootIm...nActivity] io.ionic.i4m.myfieldwise I ViewPostIme pointer 0
2025-01-27 10:44:19.181 28199-28199 ViewRootIm...nActivity] io.ionic.i4m.myfieldwise I ViewPostIme pointer 1
2025-01-27 10:44:20.416 28199-28199 ViewRootIm...nActivity] io.ionic.i4m.myfieldwise I ViewPostIme pointer 0
2025-01-27 10:44:20.487 28199-28199 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/6051.c5a20a6359278469.js - Line 1 - Msg: TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-27 10:44:20.498 28199-28199 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/polyfills.c3a9e4b87df5be46.js - Line 1 - Msg: Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-27 10:44:20.500 28199-28199 Capacitor io.ionic.i4m.myfieldwise E JavaScript Error: {"type":"js.error","error":{"message":"Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')","url":"https://localhost/polyfills.c3a9e4b87df5be46.js","line":1,"col":5336,"errorObject":"{}"}}
2025-01-27 10:44:20.511 28199-28199 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/6051.c5a20a6359278469.js - Line 1 - Msg: TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-27 10:44:20.511 28199-28199 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/polyfills.c3a9e4b87df5be46.js - Line 1 - Msg: Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-27 10:44:20.512 28199-28199 Capacitor io.ionic.i4m.myfieldwise E JavaScript Error: {"type":"js.error","error":{"message":"Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')","url":"https://localhost/polyfills.c3a9e4b87df5be46.js","line":1,"col":5336,"errorObject":"{}"}}
2025-01-27 10:44:20.519 28199-28199 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/6051.c5a20a6359278469.js - Line 1 - Msg: TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-27 10:44:20.519 28199-28199 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/polyfills.c3a9e4b87df5be46.js - Line 1 - Msg: Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-27 10:44:20.546 28199-28199 Capacitor io.ionic.i4m.myfieldwise E JavaScript Error: {"type":"js.error","error":{"message":"Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')","url":"https://localhost/polyfills.c3a9e4b87df5be46.js","line":1,"col":5336,"errorObject":"{}"}}
2025-01-27 10:44:20.678 28199-28199 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/6051.c5a20a6359278469.js - Line 1 - Msg: TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-27 10:44:20.681 28199-28199 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/polyfills.c3a9e4b87df5be46.js - Line 1 - Msg: Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-27 10:44:20.681 28199-28199 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/6051.c5a20a6359278469.js - Line 1 - Msg: TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-27 10:44:20.682 28199-28199 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/polyfills.c3a9e4b87df5be46.js - Line 1 - Msg: Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-27 10:44:20.747 28199-28199 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/6051.c5a20a6359278469.js - Line 1 - Msg: TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-27 10:44:20.748 28199-28199 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/polyfills.c3a9e4b87df5be46.js - Line 1 - Msg: Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-27 10:44:20.751 28199-28199 Capacitor io.ionic.i4m.myfieldwise E JavaScript Error: {"type":"js.error","error":{"message":"Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')","url":"https://localhost/polyfills.c3a9e4b87df5be46.js","line":1,"col":5336,"errorObject":"{}"}}
2025-01-27 10:44:20.752 28199-28199 Capacitor io.ionic.i4m.myfieldwise E JavaScript Error: {"type":"js.error","error":{"message":"Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')","url":"https://localhost/polyfills.c3a9e4b87df5be46.js","line":1,"col":5336,"errorObject":"{}"}}
2025-01-27 10:44:20.806 28199-28199 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/6051.c5a20a6359278469.js - Line 1 - Msg: TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-27 10:44:20.807 28199-28199 Capacitor/Console io.ionic.i4m.myfieldwise E File: https://localhost/polyfills.c3a9e4b87df5be46.js - Line 1 - Msg: Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')
2025-01-27 10:44:20.814 28199-28199 ViewRootIm...nActivity] io.ionic.i4m.myfieldwise I ViewPostIme pointer 1
2025-01-27 10:44:20.819 28199-28199 Capacitor io.ionic.i4m.myfieldwise E JavaScript Error: {"type":"js.error","error":{"message":"Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')","url":"https://localhost/polyfills.c3a9e4b87df5be46.js","line":1,"col":5336,"errorObject":"{}"}}
2025-01-27 10:44:20.867 28199-28199 Capacitor io.ionic.i4m.myfieldwise E JavaScript Error: {"type":"js.error","error":{"message":"Uncaught TypeError: Cannot read properties of undefined (reading 'rotation')","url":"https://localhost/polyfills.c3a9e4b87df5be46.js","line":1,"col":5336,"errorObject":"{}"}}
2025-01-27 10:44:22.365 28199-28276 OpenGLRenderer io.ionic.i4m.myfieldwise D CacheManager::trimMemory(10)
2025-01-27 10:44:25.955 28199-28299 cr_ChildProcessConn io.ionic.i4m.myfieldwise W onServiceDisconnected (crash or killed by oom): pid=28327 bindings:W S
2025-01-27 10:44:26.109 28199-28199 chromium io.ionic.i4m.myfieldwise E [ERROR:aw_browser_terminator.cc(165)] Renderer process (28327) crash detected (code -1).
2025-01-27 10:44:26.122 28199-28199 chromium io.ionic.i4m.myfieldwise E [ERROR:aw_browser_terminator.cc(113)] Render process (28327) kill (OOM or update) wasn't handed by all associated webviews, killing application.
---------------------------- PROCESS ENDED (28199) for package io.ionic.i4m.myfieldwise ----------------------------

@joelutting
Copy link

joelutting commented Jan 26, 2025

@stephanrauh I put the html in the above comment but it seems to have been stripper out...I'll try again here;

 <div class="fw-pdf-view" [hidden]="!(MainView==2)">
      <div class="fw-pdf-view-doc">
        <ngx-extended-pdf-viewer #pdfViewerAutoLoad (pdfLoaded)="onPDFLoaded($event)" [minifiedJSLibraries]="false"
        [zoom]="'page-fit'" [src]="pdfData" [height]="'100%'" [textLayer]="true" 
        [showHandToolButton]="true" [mobileFriendlyZoom]="'true'" [minZoom]="0.5" [maxZoom]="1.5"></ngx-extended-pdf-viewer>
      </div>
      <div class="fw-pdf-view-header">
        <div class="fw-pdf-view-close" (click)="closePDF()">Close</div>
      </div>
    </div>

@stephanrauh
Copy link
Owner

I'm afraid all I can see is an "OOM", which probably means out-of-memory exception. The message "Cannot read properties of undefined (reading 'rotation')" is also there, but at an unlikely place: https://localhost/polyfills.c3a9e4b87df5be46.js. Try as I might, I cannot guess why a rotation flag is read in a polyfill, so I think some compiler magic is still obfuscating the code.

In other words: I don't have a clue, and I don't know how to proceed.

@joelutting
Copy link

@stephanrauh thats too bad - not sure what I can do to get better info for you. For me to proceed I guess I'll try using an earlier version(?)

@joelutting
Copy link

@stephanrauh I tried the most recent one you released and then I tried 21.4.6 and both got the same problem. There must be something else going on, maybe with ionic/capacitor - do you know if people have used this with ionic before?

@joelutting
Copy link

@stephanrauh is there any way I can turn off pinch zoom?

@joelutting
Copy link

@stephanrauh I don't know if I am missing something - I cannot find out how to turn off pinch zoom. Also it seems to crash when it zooms too far, but I can't seem to get minZoom/maxZoom to work to limit max zoom in(?) is that the right thing to use.

Also more info - the crash actually happens before the log I posted above, it just takes a few seconds to actually crash.

  1. So I zoom in too far
  2. the pdf view goes white
  3. if I leave it alone for a few secs the app crashes
  4. below is the actual log until the crash - I was continuing to try to zoom back in after the crash which is where the previous log came from;

File: https://localhost/9590.69d6b526f22a9006.js - Line 1 - Msg: >>>>> load file
2025-01-28 14:28:13.389 10180-10180 Capacitor/Console io.ionic.i4m.myfieldwise I File: https://localhost/9590.69d6b526f22a9006.js - Line 1 - Msg: true
2025-01-28 14:28:13.391 10180-10180 Capacitor/Plugin io.ionic.i4m.myfieldwise V To native (Capacitor plugin): callbackId: 5446508, pluginId: Filesystem, methodName: readFile
2025-01-28 14:28:13.391 10180-10180 Capacitor io.ionic.i4m.myfieldwise V callback: 5446508, pluginId: Filesystem, methodName: readFile, methodData: {"path":"documents/01M5YAXHPKTKO7IUKWMBALRQVVUS5FDV44.pdf","directory":"DATA"}
2025-01-28 14:28:13.434 10180-10180 Capacitor/Console io.ionic.i4m.myfieldwise I File: https://localhost/9590.69d6b526f22a9006.js - Line 1 - Msg: diaply pdf inline<<<<<<<<<<<<<<<<<<<<<<
2025-01-28 14:28:13.496 10180-10290 Capacitor io.ionic.i4m.myfieldwise D Handling local request: https://localhost/assets/pdf.worker-4.7.728.mjs
2025-01-28 14:28:13.659 10180-10180 Capacitor/Console io.ionic.i4m.myfieldwise I File: https://localhost/assets/viewer-4.7.728.mjs - Line 38 - Msg: PDF 7806c3ab2e06524ea327d24d10e43670 [1.5 Adobe PDF Library 15.0 / Acrobat PDFMaker 15 for Word] (PDF.js: 4.7.728 [7b20f7367]) modified by ngx-extended-pdf-viewer 22.3.9
2025-01-28 14:28:13.732 10180-10180 Capacitor/Console io.ionic.i4m.myfieldwise I File: https://localhost/assets/pdf.worker-4.7.728.mjs - Line 60 - Msg: Warning: TT: undefined function: 32
2025-01-28 14:28:13.740 10180-10180 AssistStructure io.ionic.i4m.myfieldwise I Flattened final assist data: 15548 bytes, containing 1 windows, 20 views
2025-01-28 14:28:16.262 10180-10180 ViewRootIm...nActivity] io.ionic.i4m.myfieldwise I ViewPostIme pointer 0
2025-01-28 14:28:17.735 10180-10180 ViewRootIm...nActivity] io.ionic.i4m.myfieldwise I ViewPostIme pointer 1
2025-01-28 14:28:19.665 10180-10180 ViewRootIm...nActivity] io.ionic.i4m.myfieldwise I ViewPostIme pointer 0
2025-01-28 14:28:20.191 10180-10180 ViewRootIm...nActivity] io.ionic.i4m.myfieldwise I ViewPostIme pointer 1
2025-01-28 14:28:23.828 10180-10264 OpenGLRenderer io.ionic.i4m.myfieldwise D CacheManager::trimMemory(15)
2025-01-28 14:28:26.375 10180-10287 cr_ChildProcessConn io.ionic.i4m.myfieldwise W onServiceDisconnected (crash or killed by oom): pid=10300 bindings:W S
2025-01-28 14:28:26.563 10180-10180 chromium io.ionic.i4m.myfieldwise E [ERROR:aw_browser_terminator.cc(165)] Renderer process (10300) crash detected (code -1).
2025-01-28 14:28:26.575 10180-10180 chromium io.ionic.i4m.myfieldwise E [ERROR:aw_browser_terminator.cc(113)] Render process (10300) kill (OOM or update) wasn't handed by all associated webviews, killing application.
---------------------------- PROCESS ENDED (10180) for package io.ionic.i4m.myfieldwise ----------------------------

@stephanrauh
Copy link
Owner

Well, maxZoom should work. I think there's also an option to limit the maximum canvas size - and that might be the root problem, maybe I've increased it to aggressively. I'll have a look after work.

@stephanrauh
Copy link
Owner

stephanrauh commented Jan 28, 2025

Try reducing pdfDefaultOptions. maxCanvasPixels or pdfDefaultOptions.maxImageSize. If I've seen it correctly, pdf.js limits the canvas size to 5 megapixels on iOS and Android. ngx-extended-pdf-viewer tries to find out the maximum possible size, but may that doesn't work on every device reliably.

  constructor() {
    pdfDefaultOptions.maxCanvasPixels = 5242880; // 5 Megapixel
  }

5 megapixels is only a suggestion - I suppose you'll want to experiment with smaller or maybe even higher numbers.

@stephanrauh
Copy link
Owner

I've also tested the pinch gesture on iOS. [maxZoom]="1" works well - I can't pinch beyond 100%.
For the sake of completeness, I've repeated the test with [maxZoom]="2", and it works well.

https://pdfviewer.net/extended-pdf-viewer/zoom

@luke-rogers
Copy link

luke-rogers commented Jan 28, 2025

We're also seeing this crashing within our app on iOS.

I can see "Canvas area exceeds the maximum limit (width * height > 67108864)." in the console so likely it's as you expect @stephanrauh.

Interestingly we get better performance on an older version of this library (20.2.0) versus the latest. I'm unsure exactly the behaviour, but it seems like the older version stops re-rendering after a certain level of zoom where whereas the newer version does re-render on very high zoom levels and ends up crashing.

Many of our clients have detailed drawings that they need to be able to zoom into, so limiting the zoom level isn't a solution for us. In the short term, we will stick with 22.2.0.

@joelutting
Copy link

@stephanrauh works!!!

for those that have the same problem, adding this one line fixed it all. Zoom in and out and scroll around heaps on multiple docs and ran the app several times doing this - did everything I could to break it but it worked prefectly!

Thanks so much for your help!

constructor() { pdfDefaultOptions.maxCanvasPixels = 5242880; // 5 Megapixel }

@stephanrauh
Copy link
Owner

So I guess I should make that the default for iOS and Android.

By the way, here's a list of resolutions supported by the browsers. Probably you can go a lot higher than 5 megapixels:
https://jhildenbiddle.github.io/canvas-size/#/?id=desktop

@joelutting
Copy link

@stephanrauh thanks - I was actually able to zoom in a long way, with a word taking up the whole screen - it seemed fast and clear.

Also I have not been able to limit the zoom though - I set minZoom to 0.9 and maxZoom to 1.1 but it did not stop zooming in or out at all. Not so important now it works though, just FYI.

@stephanrauh stephanrauh added Solved and removed I'd like to help but it's difficult You've raised an issue that's just right - but for some reason, it's hard to solve. labels Jan 29, 2025
@stephanrauh
Copy link
Owner

Things are getting interesting. I had a long discussion with my good friend ChatGPT, and it told me these are canvas sizes with a decent safety margin:

Image

I ran a few tests, and I reckon I should heed this advice. It's less aggressive than my previous approach, which may hurt a few use-cases, but I think using the function below as a default is safe.

By the way, I ran a few plagiarism checks because the function it's hard to believe the function is not in the training data of ChatGPT. Until now, I didn't find anything. Before adding it to the library, I'll run a second check, just to be sure.

function getSafeCanvasSize(): number {
  // Create a temporary WebGL context
  const canvas = document.createElement("canvas");
  const gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
  const maxTextureSize = gl ? gl.getParameter(gl.MAX_TEXTURE_SIZE) : 4096; // Default to 4096 if unknown

  // Get available device RAM (in MB)
  function getAvailableMemoryMB(): number {
    if (navigator.deviceMemory) {
      return navigator.deviceMemory * 1024; // Convert GB to MB
    }
    if (window.performance && window.performance.memory) {
      return window.performance.memory.jsHeapSizeLimit / 1024 / 1024; // Only works on Chrome
    }
    return 4096; // Default to 4GB if unknown
  }

  const availableMemoryMB = getAvailableMemoryMB();

  // Conservative formula: Scale by square root of available memory
  let estimatedSafeSize = Math.floor(Math.sqrt((availableMemoryMB * 1024 * 1024) / 6));

  // Apply platform-specific limits
  const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
  const isMobile = /Android|iPhone|iPad|iPod/.test(navigator.userAgent);
  const isHighEndDesktop = availableMemoryMB > 12000; // Assume high-end desktops have >12GB RAM

  if (isIOS) {
    estimatedSafeSize = Math.min(estimatedSafeSize, 4096); // iOS Safari memory limits
  } else if (isMobile) {
    estimatedSafeSize = Math.min(estimatedSafeSize, 4096); // Most mobile devices
  } else if (isHighEndDesktop) {
    estimatedSafeSize = Math.min(estimatedSafeSize, 8192); // Allow larger sizes for desktops
  } else {
    estimatedSafeSize = Math.min(estimatedSafeSize, 6000); // Mid-range desktops
  }

  // Final limit based on GPU and estimated memory safety
  return Math.min(maxTextureSize, estimatedSafeSize);
}

@joelutting
Copy link

@stephanrauh I can confirm that the minZoom and maxZoom works correctly now - in trying to fix other problems I had added those variables the wrong way (I used round braces instead of square ones!) - after changing that they work now. Just FYI - my bad.

stephanrauh added a commit that referenced this issue Feb 8, 2025
… on Android and iOS; #2679 allow developers to add highlight annotations programmatically; #2784 make sure that the eventBus attribute is set before using it (fixed a bug that caused some documents to crash in single-page mode)
@stephanrauh
Copy link
Owner

stephanrauh commented Feb 8, 2025

I've reduced the default maximum resolution in version 23.0.0-alpha.0. You can still go to the max by setting pdfDefaultOptions.maxCanvasPixels = -1.

Enjoy!
Stephan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants
@timvandermeij @stephanrauh @raphjutras @luke-rogers @joelutting @dtrbi and others