You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "svanlang (via GitHub)" <gi...@apache.org> on 2025/05/07 15:03:33 UTC

[I] Script errors with window.onerror privide no information [cordova-ios]

svanlang opened a new issue, #1534:
URL: https://github.com/apache/cordova-ios/issues/1534

   # Bug Report
   
   ## Problem
   
   In my cordova app all js errors are captured through window.onerror = function( errorMsg, url, lineNumber, column, errorObj )
   This works fine on Android devices with line numbers, column number and stack trace.
   On IOs devices this just gives a SCRIPT ERROR with no further information. 
   
   ### What is expected to happen?
   
   I expect the error to have a bit more detail to it, like a stack trace
   
   
   ### What does actually happen?
   
   On IOs devices this just gives a SCRIPT ERROR with no further information. 
   
   ## Information
   
   I have created a small test app and inside the index.js added 
   
     window.onerror = function (message, source, lineno, colno, error) {
       console.log('[window.onerror]');
       console.log('Message:', message);
       console.log('Source:', source);
       console.log('Line:', lineno, 'Col:', colno);
       console.log('Error object:', error);
       console.log('Stack trace:', error?.stack);
     };
   
   I tried the same with   window.addEventListener('error', function (e) { but same result.
   
   for error i used
   
    setTimeout(() => {
       throw new Error("Simulated error for testing");
     }, 5000);
   
   
   
   ### Environment, Platform, Device
   Device:
   Macbook pro m1
   
   OS:
   macOS 15.4.1
   
   ### Version information
   
   Cordova 12.0.0 (cordova-lib@12.0.2)
   ios platform version ios 7.1.1
   xcode 16.3
   
   
   
   ## Checklist
   <!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
   
   - [ x] I searched for existing GitHub issues
   - [x ] I updated all Cordova tooling to most recent version
   - [ x] I included all the necessary information above
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


Re: [I] Script errors with window.onerror privide no information [cordova-ios]

Posted by "svanlang (via GitHub)" <gi...@apache.org>.
svanlang commented on issue #1534:
URL: https://github.com/apache/cordova-ios/issues/1534#issuecomment-2861891102

   Yes Thanks, That did the trick. Did not find this anywhere in the documentation but perhaps i overlooked.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


Re: [I] Script errors with window.onerror privide no information [cordova-ios]

Posted by "breautek (via GitHub)" <gi...@apache.org>.
breautek commented on issue #1534:
URL: https://github.com/apache/cordova-ios/issues/1534#issuecomment-2863224071

   > Yes Thanks, That did the trick. Did not find this anywhere in the documentation but perhaps i overlooked.
   
   In all likeliness the quirk is probably not documented.
   
   > iOS defaults to file:// strategy, mainly for legacy reasons. 
   
   I forgot to expand on this (while trying to keep my post short) is that by switching to from file:// to url schemes, you're document origin will change, which means that any web storage containers (cookies, local storage, indexeddb, etc) that you might have used will not be accessible as web storage containers are tied to the document origin.
   
   The data will still exist on disk in your app data, but the webview will be accessing a different container under the new origin. If you store important data in these containers, this is something to keep in mind if your working on an app that is already deployed to production and a migration strategy might be needed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


Re: [I] Script errors with window.onerror privide no information [cordova-ios]

Posted by "svanlang (via GitHub)" <gi...@apache.org>.
svanlang closed issue #1534: Script errors with window.onerror privide no information
URL: https://github.com/apache/cordova-ios/issues/1534


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


Re: [I] Script errors with window.onerror privide no information [cordova-ios]

Posted by "breautek (via GitHub)" <gi...@apache.org>.
breautek commented on issue #1534:
URL: https://github.com/apache/cordova-ios/issues/1534#issuecomment-2859851927

   This is standard behaviour for Safari **IF** the document is a cross-origin document which I'm guessing is the case here.
   
   If you're using the `file://` based strategy for the webview app host, then you're document will be considered cross-origin.
   
   If you use URL schemes, then all your source files that is bundled within the app (and loaded over the url scheme) will be considered same origin and you should get the behaviour that you'd expect.
   
   iOS defaults to `file://` strategy, mainly for legacy reasons. It is generally recommended to opt in to url schemes. To do this, specify a scheme/hostname preference:
   
   ```xml
   <platform name="ios">
       <preference name="scheme" value="app" />
       <preference name="hostname" value="localhost" />
   </platform>
   ```
   
   Note that the preferences should be inside an `ios` platform block, because android & ios cannot share the same scheme/hostname settings due to platform-specific limitations.
   
   Cordova Android defaults to use their equivalent URL scheme feature, namely because Google considers using file:// strategy as insecure and a potential vulnerability. It defaults to `https://localhost`, and it's not necessary to explicitly specify the scheme/hostname for android.
   
   Please let us know if using url schemes helps.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


Re: [I] Script errors with window.onerror privide no information [cordova-ios]

Posted by "breautek (via GitHub)" <gi...@apache.org>.
breautek commented on issue #1534:
URL: https://github.com/apache/cordova-ios/issues/1534#issuecomment-2863867017

   > Thanks for the info. local storage seems indeed gone for my app after this change. That will complicate things a bit
   
   Migration is possible. Back when migrating from UIWebView to WKWebView, the exact same issue happened, different webview implementations used different data containers. At the end of the day, they are just sqlite databases on disk stored in a particular directory, under a particular name.
   
   So on app launch, using a plugin you can check to see if the old sqlite db exists, and if the new sqlite db location doesn't exist, then move/copy the old sqlite to the new location.
   
   Back in the day I used https://github.com/totalpave/cordova-plugin-migrate-localstorage, it won't be usable as is you'll need to fork and make some adjustments but the premise should be the same, assuming wkwebview sitll uses sqlite storage containers.
   
   The naming scheme is `<protocol>_<hostname>_0.localstorage`, so the old filename will be `file__0.localstorage` (file protocols has a null hostname). So you just need to copy/move the sqlite db to `app_localhost_0.localstorage`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


Re: [I] Script errors with window.onerror privide no information [cordova-ios]

Posted by "svanlang (via GitHub)" <gi...@apache.org>.
svanlang commented on issue #1534:
URL: https://github.com/apache/cordova-ios/issues/1534#issuecomment-2863361140

   Thanks for the info. local storage seems indeed gone for my app after this change. That will complicate things a bit


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org