question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cordova plugins can't execute javascript code with webView.loadUrl

See original GitHub issue

Description of the problem:

It seems like Capacitor does not allow for Cordova cordova.fireDocumentEvent to be received using document.addEventListener.

I’m using the Cordova Admob Free plugin with Capacitor. The plugin installs and works as expected, meaning the bridge calls work and it displays test ads, however, my Capacitor app does not receive any of the plugin issued cordova.fireDocumentEvent events.

Affected platform

  • Android
  • iOS
  • electron
  • web

OS of the development machine

  • Windows
  • macOS
  • linux

Other information:

I’ve tried with both Cordova framework 7.0.0 and 8.0.0 as dependencies in the Android project.

Capacitor version: 1.0.0-beta.19

node version: 11.7.0

npm version: 6.5.0

CocoaPods version:

Steps to reproduce:

  1. Clone and build the repository at https://github.com/petarov/capacitor-cordova-fireevent
  2. npx cap open android to open the app in Android Studio.
  3. Build & run the app on an Android device.
  4. Open Logcat in Android Studio.
  5. Press the Show Ad button in the app on the device.
  6. None of the admob.interstitial.events.* events in app.js get displayed in Logcat.

Link to sample project: https://github.com/petarov/capacitor-cordova-fireevent

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jcesarmobilecommented, Mar 28, 2019

Ok, I got the test APPLICATION_ID and was able to test and fix it.

BTW, don’t manually edit anything in capacitor-cordova-android-plugins, all that is recreated on update and sync commands.

You can add the id on the app’s AndroidManifest.xml like this

<meta-data tools:replace="android:value"
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-3940256099942544~3347511713"/>

(It requires to add the tools namespace to the manifest tag xmlns:tools="http://schemas.android.com/tools")

0reactions
petarovcommented, Mar 28, 2019

I’ve just tested the fix and it all works great! Thank you again @jcesarmobile and thanks for the id hint.

I’m sorry about the missing capacitor-cordova-android-plugins folder. Looks like it was in the .gitignore file Capacitor generated and I completely missed it. My bad!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to execute Js code in WebView in Cordova Project
I have two activity, one main activity(A) is an CordovaActivity, then I use intent to start another activity(B), in B i have an...
Read more >
Communicating Between JavaScript and Java Through the ...
1. Install the plugin.​ ... Run the cordova plugin add @hmscore/cordova-plugin-hms-push command to install the latest plugin. After the command is ...
Read more >
InAppWebView: the real power of WebViews in Flutter
It's a Flutter plugin that allows you to incorporate WebView widgets into your Flutter app, to use headless WebViews or to use in-app ......
Read more >
469099 - Cordova 3.6.0 app crashes on startup - chromium
Been playing with this a while. It seems to occur if we load a javascript url of the form "javascript:someVar=true" before we've loaded...
Read more >
IWebView | 3D WebView Documentation
It contains methods and properties for common browser-related functionality, like LoadUrl(), GoBack(), Reload(), and ExecuteJavaScript(). To create an IWebView, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found