newrelic / newrelic-capacitor-plugin

Mobile instrumentation plugin for the Capacitor hybrid mobile platform by Ionic
Apache License 2.0
7 stars 10 forks source link

Capacitor Scheme HTTPS conflicts with loading the Plugin #70

Closed PrinzJuliano closed 4 months ago

PrinzJuliano commented 10 months ago

Description

Enabling https as androidScheme for android results in the app no longer loading the plugin. Furthermore, hard Startup Errors arise with the error message "NewRelicCapacitorPlugin" plugin is not implemented on android.

When disabling https, the app launches.

Steps to Reproduce

To enable Password managers and special security context capabilities, an android Configuration can be enabled to run the App under https://<hostname>

Namely: CapacitorConfig.server.androidScheme = 'https' See https://capacitorjs.com/docs/guides/autofill-credentials#configuration-for-android

Follow the guide to install the newrelic capacitor plugin and enable https as scheme for android.

Expected Behavior

The App should start without errors.

Relevant Logs / Console output

"NewRelicCapacitorPlugin" plugin is not implemented on android

Your Environment

macOS 14.1.1 node: v20.9.0 npm 10.1.0 android: 14 (UP1A.231105.003)

Packages:

├── @angular-devkit/build-angular@16.2.10
├── @angular-eslint/builder@16.3.1
├── @angular-eslint/eslint-plugin-template@16.3.1
├── @angular-eslint/eslint-plugin@16.3.1
├── @angular-eslint/schematics@16.3.1
├── @angular-eslint/template-parser@16.3.1
├── @angular/animations@16.2.12
├── @angular/cli@16.2.10
├── @angular/common@16.2.12
├── @angular/compiler-cli@16.2.12
├── @angular/compiler@16.2.12
├── @angular/core@16.2.12
├── @angular/forms@16.2.12
├── @angular/language-service@16.2.12
├── @angular/platform-browser-dynamic@16.2.12
├── @angular/platform-browser@16.2.12
├── @angular/router@16.2.12
├── @angular/service-worker@16.2.12
├── @capacitor/android@5.5.1
├── @capacitor/app@5.0.6
├── @capacitor/cli@5.2.2
├── @capacitor/clipboard@5.0.6
├── @capacitor/core@5.5.1
├── @capacitor/haptics@5.0.6
├── @capacitor/ios@5.5.1
├── @capacitor/keyboard@5.0.6
├── @capacitor/status-bar@5.0.6
├── @ionic/angular-toolkit@9.0.0
├── @ionic/angular@7.5.4
├── @newrelic/browser-agent@1.248.0
├── @newrelic/newrelic-capacitor-plugin@1.3.2
├── @ngneat/cashew@3.1.0
├── @types/dompurify@3.0.5
├── @types/jasmine@4.3.6
├── @types/node@12.20.55
├── @typescript-eslint/eslint-plugin@5.3.0
├── @typescript-eslint/parser@5.3.0
├── @uppy/angular@0.5.2
├── @uppy/core@3.7.0
├── @uppy/dashboard@3.7.0
├── @uppy/drag-drop@3.0.3
├── @uppy/image-editor@2.3.0
├── @uppy/locales@3.4.0
├── @uppy/progress-bar@3.0.4
├── @uppy/tus@3.4.0
├── @uppy/xhr-upload@3.5.0
├── angulartics2@12.2.1
├── dompurify@3.0.6
├── eslint-plugin-import@2.22.1
├── eslint-plugin-jsdoc@30.7.6
├── eslint-plugin-prefer-arrow@1.2.2
├── eslint@7.32.0
├── ionicons@7.2.1
├── jasmine-core@4.6.0
├── jasmine-spec-reporter@5.0.2
├── jwt-decode@3.1.2
├── karma-chrome-launcher@3.2.0
├── karma-coverage-istanbul-reporter@3.0.3
├── karma-coverage@2.2.1
├── karma-jasmine-html-reporter@2.0.0
├── karma-jasmine@5.1.0
├── karma@6.4.2
├── localforage@1.10.0
├── rxjs@7.8.1
├── swiper@10.3.1
├── ts-node@8.10.2
├── tslib@2.6.2
├── tsparticles-confetti@2.12.0
├── typescript@5.0.4
├── video.js@8.6.1
└── zone.js@0.13.3

Additional context

I need https to ensure autofill credentials works.

ndesai-newrelic commented 7 months ago

@PrinzJuliano is this still issue?

PrinzJuliano commented 7 months ago

@ndesai-newrelic I am now using the newest Capacitor Plugin Version 1.3.3.

The same issue persists and in fact more issues are being raised:

Caused by: java.lang.IllegalArgumentException: noticeHttpTransaction: URL is malformed: /svg/eye.svg
                                                                                                        at com.newrelic.agent.android.NewRelic.noticeHttpTransaction(NewRelic.java:579)

See attached New Relic Crash Report: JP Insider Android Crashreport Feb 14 2024 1351.txt

I can confirm on Version 1.3.2 the app can open the local URL while not being able to run in HTTPS Mode, whereas on Version 1.3.3 the app starts but as soon as local resources are loaded, like a local SVG file, the app just crashes with the before mentioned exception. The original issue persists, though.

ndesai-newrelic commented 7 months ago

@PrinzJuliano i fixed android crash in latest release, can you check it?

PrinzJuliano commented 7 months ago

I can confirm that with version 1.3.4 the app no longer crashes in HTTP Mode. However, ion-icons no longer load. And Fetch Requests fail as you try to set headers in the global fetch override, but some fetch requests are missing the second parameter "options".

Thus I get the error: Cannot set properties of undefined (setting 'headers')

Relevant Minified Code:

window.fetch = function() {
            var B = arguments
              , q = arguments[0]
              , _e = arguments[1];
            return me.getHTTPHeadersTrackingFor().then(j=>(console.log(j),
            me.generateDistributedTracingHeaders().then(be=>(console.log(be),
            H.startTime = Date.now(),
            q && "object" == typeof q ? (H.url = q.url,
            _e && "method"in _e ? H.method = _e.method : q && "method"in q && (H.method = q.method)) : (H.url = q,
            _e && "method"in _e && (H.method = _e.method)),
            _e && "headers"in _e ? (_e.headers.newrelic = be.newrelic,
            _e.headers.traceparent = be.traceparent,
            _e.headers.tracestate = be.tracestate,
            JSON.parse(j.headersList).forEach(Ae=>{
                void 0 !== _e.headers[Ae] && (H.params[Ae] = _e.headers[Ae])
            }
            )) : (_e.headers = {}, // Relevant broken line
            _e.headers.newrelic = be.newrelic,
            _e.headers.traceparent = be.traceparent,
            _e.headers.tracestate = be.tracestate,
            B[1] = _e),
            H.bytesSent = _e && "body"in _e ? _e.body.length : 0,

Doing my own regressional testing: IonIcons would still load in 1.3.2 and Fetch Requests still fetched data.

The original Error continues to occur in 1.3.4. Setting the scheme to "https" results in "NewRelicCapacitorPlugin" plugin is not implemented on android

ndesai-newrelic commented 7 months ago

@PrinzJuliano thanks for feedback, i will check this from my side also

ndesai-newrelic commented 7 months ago

@PrinzJuliano can you provide sample app where you are seeing this ? it is really helpful.

PrinzJuliano commented 7 months ago

@ndesai-newrelic I created a fresh Ionic Android app. https://github.com/PrinzJuliano/newrelic-test

This does not include web instrumentation. The app runs on https://newrelic-test.prinzjuliano.com for deep linking and autofill credential support on android.

ndesai-newrelic commented 7 months ago

@PrinzJuliano can you check on latest release?

PrinzJuliano commented 7 months ago

I have tested the current version 1.3.5. It seems to mostly work now.

I still only get []: [object Object] console.log and []: ERROR []: [object Object] console.error

I would assume this is a serialization issue with the global console logging system.

ndesai-newrelic commented 5 months ago

@PrinzJuliano we will fix it for next release

ndesai-newrelic commented 4 months ago

@PrinzJuliano i created PR for this fix, can you check it?

PrinzJuliano commented 4 months ago

Once a build version (i.e. 1.4.1) is available I will be able to test it. I cannot install the raw git repository as it does not contain the required declarations.

Cannot find module '@newrelic/newrelic-capacitor-plugin' or its corresponding type declarations.