cesarvr / pdf-generator

Cordova plugin to generate pdf in the client-side
MIT License
106 stars 62 forks source link

Crashes with Chrome 86+ on Android #124

Open timbru31 opened 4 years ago

timbru31 commented 4 years ago

We are experiencing crashes (with the base64 option) and faulty previews (with the share option) when using Chrome's 86 beta version (86.0.4240.30) or higher (Canary (87.0.4262.3) is affected, too).

I've narrowed the behaviour down to the webview behvaior. The same webView is re-used and never destoryed, leading to the above bug description on the second call from the plugin. When destroying the WebView, i.e., always using a fresh one, the bug is fixed.

A pull request will follow shortly, which includes a general cleanup of the Java code.

For the completeness, here are the version information: Android 9 on a Lenovo TB-X505F.

cordova info ```txt Cordova Packages: cli: 10.0.0 common: 4.0.2 create: 3.0.0 lib: 10.0.0 common: 4.0.2 fetch: 3.0.0 serve: 4.0.0 Project Installed Platforms: android: 9.0.0 Project Installed Plugins: cordova-android-support-gradle-release: 3.0.1 cordova-open-native-settings: 1.5.2 cordova-pdf-generator: 2.1.1 cordova-plugin-androidx-adapter: 1.1.1 cordova-plugin-app-version: 0.1.9 cordova-plugin-badge: 0.8.8 cordova-plugin-calendar: 5.1.5 cordova-plugin-delete-launch-screen-cache: 1.0.1 cordova-plugin-device: 2.0.3 cordova-plugin-dialogs: 2.0.2 cordova-plugin-file-opener2: 3.0.4 cordova-plugin-file-transfer: 2.0.0 cordova-plugin-file: 6.0.2 cordova-plugin-geolocation: 4.0.2 cordova-plugin-inappbrowser: 4.0.0 cordova-plugin-ionic-keyboard: 2.2.0 cordova-plugin-ionic-webview: 5.0.0 cordova-plugin-ionic: 5.4.7 cordova-plugin-local-notification: 0.9.0-beta.3 cordova-plugin-lottie-splashscreen: 0.9.0 cordova-plugin-network-information: 2.0.2 cordova-plugin-pincheck: 0.0.6 cordova-plugin-screen-orientation: 3.0.2 cordova-plugin-secure-storage-echo: 5.1.1 cordova-plugin-statusbar: 2.4.3 cordova-plugin-whitelist: 1.3.4 cordova-plugin-x-toast: 2.7.2 cordova-plugin-zip: 5.0.0 es6-promise-plugin: 4.2.2 Environment: OS: macOS Catalina 10.15.6 (19G2021) (darwin 19.6.0) x64 Node: v12.18.3 npm: 6.14.6 android Environment: android: ************************************************************************* The "android" command is deprecated. For manual SDK, AVD, and project management, please use Android Studio. For command-line tools, use tools/bin/sdkmanager and tools/bin/avdmanager ************************************************************************* Running /Users/tim.brust/Library/Android/sdk/tools/bin/avdmanager list target Available Android targets:==============] 100% Fetch remote repository... ---------- id: 1 or "android-28" Name: Android API 28 Type: Platform API level: 28 Revision: 6 ---------- id: 2 or "android-29" Name: Android API 29 Type: Platform API level: 29 Revision: 5 Project Setting Files: config.xml: DEBUG-D2D App for supporting the mobile sales team. SinnerSchrader Deutschland GmbH Um zu sehen wo Du Dich aktuell auf der Karte befindest, braucht die D2D-App Zugriff auf Deinen Standort. Um zu sehen wo Du Dich aktuell auf der Karte befindest, braucht die D2D-App Zugriff auf Deinen Standort. package.json: --- Start of Cordova JSON Snippet --- { "plugins": { "@d2d/cordova-plugin-file-transfer": {}, "@d2d/cordova-plugin-zip": {}, "cordova-android-support-gradle-release": { "ANDROID_SUPPORT_VERSION": "28.+" }, "cordova-open-native-settings": {}, "cordova-pdf-generator": {}, "cordova-plugin-androidx-adapter": {}, "cordova-plugin-app-version": {}, "cordova-plugin-badge": {}, "cordova-plugin-calendar": { "CALENDAR_USAGE_DESCRIPTION": "Um Wiedervorlagen in Deinem Kalender speichern zu können, benötigt die D2D-App Zugriff darauf.", "CONTACTS_USAGE_DESCRIPTION": " " }, "cordova-plugin-delete-launch-screen-cache": {}, "cordova-plugin-device": {}, "cordova-plugin-dialogs": {}, "cordova-plugin-file-opener2": { "ANDROID_SUPPORT_V4_VERSION": "28.+" }, "cordova-plugin-file": {}, "cordova-plugin-file-transfer": {}, "cordova-plugin-geolocation": {}, "cordova-plugin-local-notification": { "ANDROID_SUPPORT_V4_VERSION": "28.+" }, "cordova-plugin-lottie-splashscreen": {}, "cordova-plugin-inappbrowser": {}, "cordova-plugin-ionic": { "APP_ID": "0d80246e", "CHANNEL_NAME": "production", "UPDATE_METHOD": "none", "MAX_STORE": "2", "UPDATE_API": "https://api.ionicjs.com", "MIN_BACKGROUND_DURATION": "30" }, "cordova-plugin-ionic-keyboard": {}, "cordova-plugin-ionic-webview": {}, "cordova-plugin-network-information": {}, "cordova-plugin-pincheck": {}, "cordova-plugin-screen-orientation": {}, "cordova-plugin-secure-storage-echo": {}, "cordova-plugin-statusbar": {}, "cordova-plugin-whitelist": {}, "cordova-plugin-x-toast": {}, "cordova-plugin-zip": {} }, "platforms": [ "android", "ios" ] } --- End of Cordova JSON Snippet --- ```
spillaiveliyam commented 4 years ago

I added the below code in PDFGenerator.java

public WebView getOffscreenWebkitInstance(Context ctx) {
        LOG.i(APPNAME, "Mounting offscreen webview");
        if(this.offscreenWebview !=null){
            this.offscreenWebview.destroy();
            this.offscreenWebview = null;
        }
        if (this.offscreenWebview == null){
            WebView view = new WebView(ctx);
            view.getSettings().setDatabaseEnabled(true);
            view.getSettings().setJavaScriptEnabled(true);
            return this.offscreenWebview = view;
        }else{
            return this.offscreenWebview;
        }
    }

I just destroyed the webView

timbru31 commented 4 years ago

My approach is/was to destroy the actual instance once the onFinish is called: https://github.com/cesarvr/pdf-generator/pull/125/files#r488642327 - otherwise you have a stale offScreenWebView that is only destroyed on the next print.

spillaiveliyam commented 4 years ago

^^ yea thats very much valid. I destroyed it in onFinish .

ascottk commented 4 years ago

Hello. Is this fix released? This problem fits the symptoms my users are reporting - and which I can replicate with a simple

Hello World
payload using type: 'base64' . Every second attempt to generate a PDF crashes the entire App. I tried installing 2.2.0 but a.) it didn't solve the problem and b.) the package version is still listed as 2.1.1 - see plugin.xml in pdf-generator-2.2.0.zip\pdf-generator-2.2.0. A fix would let me get my life back ...

timbru31 commented 4 years ago

You could use our fork as an intermediate solution: https://www.npmjs.com/package/@d2d/cordova-pdf-generator

ascottk commented 4 years ago

Thanks Tim, lifesaver.

From: Tim Brust notifications@github.com Sent: Wednesday, 14 October 2020 10:35 pm To: cesarvr/pdf-generator pdf-generator@noreply.github.com Cc: ascottk scottka@dbsys.co.nz; Comment comment@noreply.github.com Subject: Re: [cesarvr/pdf-generator] Crashes with Chrome 86+ on Android (#124)

You could use our fork as an intermediate solution: https://www.npmjs.com/package/@d2d/cordova-pdf-generator

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cesarvr/pdf-generator/issues/124#issuecomment-708283973 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ACF4OJTLKB23HJNHEHWDCRTSKVWE3ANCNFSM4RNB3RJA .

-- This email has been checked for viruses by AVG. https://www.avg.com