apache / cordova-ios

Apache Cordova iOS
https://cordova.apache.org/
Apache License 2.0
2.15k stars 987 forks source link

console.log() not working #1319

Closed MichalPleban closed 1 year ago

MichalPleban commented 1 year ago

Bug Report

Problem

What is expected to happen?

Commands like console.log() are supposed to work.

What does actually happen?

When connecting through remote debugger (Safari: Develop -> iPhone -> index.html), console output is always empty. I can execute JavaScript commands, and other tabs (like "Network") work as expected. But no console functions produce any output.

Environment, Platform, Device

iOS 16.4

Version information

Cordova info output:

Cordova Packages:

    cli: 11.1.0
        common: 4.1.0
        create: 4.1.0
        lib: 11.1.0
            common: 4.1.0
            fetch: 3.1.0
            serve: 4.0.1

Project Installed Platforms:

    android: 10.1.2
    browser: 6.0.0
    ios: 6.3.0
    osx: 6.0.0

Project Installed Plugins:

    at.gofg.sportscomputer.powermanagement: 1.1.2
    cordova-custom-config: 5.1.1
    cordova-plugin-advanced-http: 3.3.1
    cordova-plugin-android-permissions: 1.1.5
    cordova-plugin-background-mode: 0.7.3
    cordova-plugin-compat: 1.2.0
    cordova-plugin-console: 1.1.0
    cordova-plugin-device: 2.1.0
    cordova-plugin-facebook-connect: 3.2.0
    cordova-plugin-ffmpeg: 2.0.1
    cordova-plugin-file: 7.0.0
    cordova-plugin-firebasex: 12.0.0-cli
    cordova-plugin-globalization: 1.11.0
    cordova-plugin-googleplus: 8.5.2
    cordova-plugin-inappbrowser: 5.0.0
    cordova-plugin-keyboard: 1.2.0
    cordova-plugin-media: 6.1.0
    cordova-plugin-network-information: 3.0.0
    cordova-plugin-purchase: 13.3.11
    cordova-plugin-saf-mediastore: 0.7.0
    cordova-plugin-sign-in-with-apple: 0.1.2
    cordova-plugin-splashscreen: 6.0.2
    cordova-plugin-statusbar: 3.0.0
    cordova-plugin-x-socialsharing: 6.0.4
    cordova.plugins.diagnostic: 7.1.1
    es6-promise-plugin: 4.2.2

Environment:

    OS: macOS Ventura 13.2.1 (22D68) (darwin 22.3.0) x64
    Node: v18.15.0
    npm: 9.5.0

android Environment:

    android:
ERROR: Command failed with ENOENT: avdmanager list target
spawn avdmanager ENOENT

ios Environment:

    xcodebuild:
Xcode 14.3
Build version 14E222b

Project Setting Files:

    config.xml:
<?xml version='1.0' encoding='utf-8'?>
<widget id="pl.notuj.app" version="0.3.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>Notuj.pl</name>
    <description>Sample Apache Cordova App</description>
    <author email="dev@cordova.apache.org" href="https://cordova.apache.org">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />

    <allow-navigation href="*" />

    <platform name="android">
      <resource-file src="res/values/colors.xml" target="/app/src/main/res/values/colors.xml" />
      <preference name="StatusBarOverlaysWebView" value="false" />
      <preference name="android-minSdkVersion" value="22" />
      <preference name="android-targetSdkVersion" value="31" />
      <preference name="SplashMaintainAspectRatio" value="true" />
      <splash density="land-hdpi" src="res/screen/android/drawable-hdpi/screen.png" />
      <splash density="land-mdpi" src="res/screen/android/drawable-mdpi/screen.png" />
      <splash density="land-xhdpi" src="res/screen/android/drawable-xhdpi/screen.png" />
      <splash density="land-xxhdpi" src="res/screen/android/drawable-xxhdpi/screen.png" />
      <splash density="land-xxxhdpi" src="res/screen/android/drawable-xxxhdpi/screen.png" />
      <splash density="port-hdpi" src="res/screen/android/drawable-hdpi/screen.png" />
      <splash density="port-mdpi" src="res/screen/android/drawable-mdpi/screen.png" />
      <splash density="port-xhdpi" src="res/screen/android/drawable-xhdpi/screen.png" />
      <splash density="port-xxhdpi" src="res/screen/android/drawable-xxhdpi/screen.png" />
      <splash density="port-xxxhdpi" src="res/screen/android/drawable-xxxhdpi/screen.png" />
      <icon density="ldpi" src="res/icon/android/mipmap-ldpi/icon.png" background="@color/background" foreground="res/icon/android/mipmap-ldpi/fg.png"/>
      <icon density="mdpi" src="res/icon/android/mipmap-mdpi/icon.png" background="@color/background" foreground="res/icon/android/mipmap-mdpi/fg.png"/>
      <icon density="hdpi" src="res/icon/android/mipmap-hdpi/icon.png" background="@color/background" foreground="res/icon/android/mipmap-hdpi/fg.png"/>
      <icon density="xhdpi" src="res/icon/android/mipmap-xhdpi/icon.png" background="@color/background" foreground="res/icon/android/mipmap-xhdpi/fg.png"/>
      <icon density="xxhdpi" src="res/icon/android/mipmap-xxhdpi/icon.png" background="@color/background" foreground="res/icon/android/mipmap-xxhdpi/fg.png"/>
      <icon density="xxxhdpi" src="res/icon/android/mipmap-xxxhdpi/icon.png" background="@color/background" foreground="res/icon/android/mipmap-xxxhdpi/fg.png"/>
      <resource-file src="res/icon/android/mipmap-mdpi/notification_icon.png" target="app/src/main/res/drawable-mdpi/notification_icon.png"/>
      <resource-file src="res/icon/android/mipmap-hdpi/notification_icon.png" target="app/src/main/res/drawable-hdpi/notification_icon.png"/>
      <resource-file src="res/icon/android/mipmap-xhdpi/notification_icon.png" target="app/src/main/res/drawable-xhdpi/notification_icon.png"/>
      <resource-file src="res/icon/android/mipmap-xxhdpi/notification_icon.png" target="app/src/main/res/drawable-xxhdpi/notification_icon.png"/>
      <resource-file src="res/icon/android/mipmap-xxxhdpi/notification_icon.png" target="app/src/main/res/drawable-xxxhdpi/notification_icon.png"/>
      <config-file target="AndroidManifest.xml" parent="/*" xmlns:android="http://schemas.android.com/apk/res/android">
        <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
      </config-file>

      <!--
      <config-file parent="/manifest" target="AndroidManifest.xml">
        <queries>
          <intent>
            <action android:name="android.intent.action.SENDTO" />
            <data android:scheme="mailto" />
          </intent>
        </queries>
      </config-file>
      -->
      <config-file target="AndroidManifest.xml" parent="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
        <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/notification_icon" />
      </config-file>

    </platform>

    <platform name="ios">
      <config-file parent="CFBundleAllowMixedLocalizations" platform="ios" target="*-Info.plist">
        <true />
      </config-file>
      <preference name="scheme" value="app" />
      <preference name="hostname" value="localhost" />
      <preference name="StatusBarOverlaysWebView" value="true" />
      <splash src="res/screen/ios/Default@2x~universal~anyany.png" />
      <icon height="180" src="res/icon/ios/icon-60x60@3x.png" width="180" />
      <icon height="60" src="res/icon/ios/icon-60x60@1x.png" width="60" />
      <icon height="120" src="res/icon/ios/icon-60x60@2x.png" width="120" />
      <icon height="76" src="res/icon/ios/icon-76x76@1x.png" width="76" />
      <icon height="152" src="res/icon/ios/icon-76x76@2x.png" width="152" />
      <icon height="228" src="res/icon/ios/icon-76x76@3x.png" width="228" />
      <icon height="40" src="res/icon/ios/icon-40x40@1x.png" width="40" />
      <icon height="80" src="res/icon/ios/icon-40x40@2x.png" width="80" />
      <icon height="87" src="res/icon/ios/icon-29x29@3x.png" width="87" />
      <icon height="57" src="res/icon/ios/icon-57x57@1x.png" width="57" />
      <icon height="114" src="res/icon/ios/icon-57x57@2x.png" width="114" />
      <icon height="72" src="res/icon/ios/icon-72x72@1x.png" width="72" />
      <icon height="144" src="res/icon/ios/icon-72x72@2x.png" width="144" />
      <icon height="167" src="res/icon/ios/icon-83.5x83.5@2x.png" width="167" />
      <icon height="29" src="res/icon/ios/icon-29x29@1x.png" width="29" />
      <icon height="58" src="res/icon/ios/icon-29x29@2x.png" width="58" />
      <icon height="50" src="res/icon/ios/icon-50x50@1x.png" width="50" />
      <icon height="100" src="res/icon/ios/icon-50x50@2x.png" width="100" />
      <icon height="167" src="res/icon/ios/icon-83.5x83.5@2x.png" width="167" />
      <icon height="1024" src="res/icon/ios/icon-512x512@2x.png" width="1024" />
      <config-file platform="ios" target="*-Info.plist" parent="NSMicrophoneUsageDescription">
        <string>Tworzenie notatek głosowych.</string>
      </config-file>
      <config-file platform="ios" target="*-Info.plist" parent="NSCameraUsageDescription">
        <string>Tworzenie notatek wideo.</string>
      </config-file>
      <preference name="WKWebViewOnly" value="true" />
      <feature name="CDVWKWebViewEngine">
        <param name="ios-package" value="CDVWKWebViewEngine" />
      </feature>
      <preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />

    </platform>

    <platform name="osx">
      <icon src="res/icon/osx/icon-16x16.png" width="16" height="16" />
      <icon src="res/icon/osx/icon-32x32.png" width="32" height="32" />
      <icon src="res/icon/osx/icon-64x64.png" width="64" height="64" />
      <icon src="res/icon/osx/icon-128x128.png" width="128" height="128" />
      <icon src="res/icon/osx/icon-256x256.png" width="256" height="256" />
      <icon src="res/icon/osx/icon-512x512.png" width="512" height="512" />
      <icon src="res/icon/osx/icon-1024x1024.png" width="1024" height="1024" />
      <preference name="ShowSplashScreen" value="false" />
      <preference name="AutoHideSplashScreen" value="true" />
    </platform>

    <preference name="DisallowOverscroll" value="true" />
    <preference name="BackupWebStorage" value="local" />
    <preference name="AutoHideSplashScreen" value="false" />
    <preference name="ShowSplashScreenSpinner" value="false" />
    <preference name="SplashScreenDelay" value="0" />
    <preference name="Suppresses3DTouchGesture" value="true" />
    <preference name="Allow3DTouchLinkPreview" value="false" />
    <preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
    <preference name="AllowInlineMediaPlayback" value="true" />

    <preference name="cordova.plugins.diagnostic.modules" value="MICROPHONE WIFI LOCATION EXTERNAL_STORAGE" />

    <preference name="BackgroundColor" value="0x1c1c1dff"/>
    <preference name="SplashScreenBackgroundColor" value="#dcdcdc"/>
    <preference name="Orientation" value="portrait"/>

</widget>

    package.json:
--- Start of Cordova JSON Snippet ---
{
  "platforms": [
    "osx",
    "browser",
    "android"
  ],
  "plugins": {
    "cordova-plugin-splashscreen": {},
    "cordova-custom-config": {},
    "cordova-plugin-advanced-http": {},
    "cordova-plugin-android-permissions": {},
    "cordova-plugin-compat": {},
    "cordova-plugin-device": {},
    "cordova-plugin-file": {},
    "cordova-plugin-keyboard": {},
    "cordova-plugin-media": {},
    "cordova-plugin-network-information": {},
    "cordova-plugin-saf-mediastore": {},
    "cordova-plugin-statusbar": {},
    "cordova-plugin-x-socialsharing": {},
    "cordova.plugins.diagnostic": {},
    "es6-promise-plugin": {},
    "cordova-plugin-googleplus": {
      "REVERSED_CLIENT_ID": "com.googleusercontent.apps.45382520060-6nftp9mujb4ia4ndglmbulokbveiv30q",
      "WEB_APPLICATION_CLIENT_ID": "45382520060-me41qjmdsvvv3nol42asrvse5r6g7ut0.apps.googleusercontent.com"
    },
    "at.gofg.sportscomputer.powermanagement": {},
    "cordova-plugin-firebasex": {
      "FIREBASE_ANALYTICS_COLLECTION_ENABLED": "true",
      "FIREBASE_PERFORMANCE_COLLECTION_ENABLED": "true",
      "FIREBASE_CRASHLYTICS_COLLECTION_ENABLED": "true"
    },
    "cordova-plugin-ffmpeg": {},
    "cordova-plugin-background-mode": {},
    "cordova-plugin-inappbrowser": {},
    "cordova-plugin-purchase": {
      "BILLING_KEY": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxR3q9bmYKGwIFR1kmxeTuxsujaK0VLtYmUxOWjGfKT+Xc3+0lUQ8KjP/5/54FZKBMHhqyHPEToNRiI8tWIh8G6E9l4HhVxOGcBYt01sN8a8jJtckd1m441g5rTMHirY5Hkv/mM5b/hOwi3CEwR30pj+VeIkxnBsxrJXVP0sgw40WExp/dnRuokLwBgSk9pHqgzs00lUeIoe3XVtkxDahD0UTrEcnSKF55E3fOenbeA4ctpOkq1MR/fLvbjx/Vv3fzDV2qLJJnfUwhHhZqMzjhZ4O6hF9MOe4mWD9rfst4T09ju3pjAQjUxVoKiYGVbXlyqZU83GaY0FCpVfK+gedFwIDAQAB"
    },
    "cordova-plugin-facebook-connect": {
      "APP_ID": "1167315467356511",
      "APP_NAME": "Notuj.pl"
    },
    "cordova-plugin-globalization": {},
    "cordova-plugin-sign-in-with-apple": {},
    "cordova-plugin-console": {}
  }
}
--- End of Cordova JSON Snippet ---

Checklist

breautek commented 1 year ago

When connecting through remote debugger (Safari: Develop -> iPhone -> index.html), console output is always empty. I can execute JavaScript commands, and other tabs (like "Network") work as expected. But no console functions produce any output.

Can you clarify if the console outputs nothing at all (including console.log executions after the inspector is attached) vs only console outputs that may have occurred before the inspector was attached.

If only the latter then it's not a bug, that's just how Safari works... Safari doesn't record log data if there is no attached inspector and doesn't display said information retroactively should an inspector be attached later. Therefore log information is only recorded and displayed after the inspector is attached. If you need to get "webview startup" console logs, then you will have to open the inspector, and press cmd + r to refresh the webview. This may cause some side effects in plugins but should also present you the console.logs that occurred while the HTML is loading.

MichalPleban commented 1 year ago

It shows nothing at all, including console.log executions after the inspector is attached. After reloading the view with cmd+R there is also no console output whatsoever.

breautek commented 1 year ago

cordova-plugin-console: 1.1.0

I noticed you're using this console plugin which appears to override and clobbers the W3 console. This plugin is dated and deprecated. Can you remove this plugin and test to see if it solves your issue regarding the console?

MichalPleban commented 1 year ago

It does not. It was like that before I installed the plugin, I installed it in the hope it would help but it makes no difference.

breautek commented 1 year ago

It does not. It was like that before I installed the plugin, I installed it in the hope it would help but it makes no difference.

Ok.

I just tried creating a sample hello world project to see if the issue reproduces on a simple project, which it does not (for me). Can you clarify if the issue reproduces on a physical device or simulators or both?

For what it's worth my environment is as follows:

Mac Mini 2023 M2
MacOS Ventura 13.3.1

XCode 14.3 (14E222b)

iPhone 14 Pro iOS 16.4 Simulator
Safari 16.4 (18615.1.26.11.23)

Node v18.5.0
NPM v9.5.0

I'd suggest trying to see if you can build a simplified project that reproduces the issue that you can share. It will help isolate the issue and if it's indeed a bug within the Cordova Framework, then it could potentially be used as a test case for a solution. Please see How to Create a Reproduction App for tips and rationale on what we are looking for.

Generally speaking, issues are often caused by plugins or a combination of plugins that may conflict or produce undesirable results, though looking at your plugin list nothing seems obvious. I'd recommend creating a sample project and incrementally start adding in plugins and changing the config.xml configuration until the issue gets reproduced.

MichalPleban commented 1 year ago

I have just created an empty project by running:

cordova create
cordova platform add ios

And the problem is already there. Even when I type console.log('...') in the console, the output is not displayed.

breautek commented 1 year ago

Can you tell me the version of Safari you have on the Mac side?

I see that you're one minor version behind, so I'm thinking maybe your running Safari 16.3 and there is an incompatibility with iOS safari 16.4

MichalPleban commented 1 year ago

Yes, I have Safari 16.3 on MacOS and 16.4.1 on iOS. I don't see any update for my Safari though in MacOS App Store :(

breautek commented 1 year ago

Yes, I have Safari 16.3 on MacOS and 16.4.1 on iOS. I don't see any update for my Safari though in MacOS App Store :(

Safari I'm pretty sure is tied to the OS, so you need to update your Mac to 13.3 most likely, which probably includes Safari 16.4. I am on MacOS 13.3 and it contains Safari 16.4 on my machine.

Alternatively, you can try the tech preview but that should be reserved as a last resource since it is a preview and may be unstable.

MichalPleban commented 1 year ago

Thank you, it did the trick! After updating MacOS, the console works.