apache / apache/cordova-plugin-inappbrowser
message event fires only once for same inAppBrowser window
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 2.2k
- PR merge metrics
- No merged PRs in 30d
Description
# Bug Report
## Problem
When message event listener contains another inAppBrowser call to open link in system browser, message event fires only once for one inAppBrowser window
### What is expected to happen?
Every time when postMessage is executed in inAppBrowser window, message event listener would be fired.
### What does actually happen?
Only first message is received by message event listener.
## Information
### Command or Code
This is code from remote web page that is opened in inAppBrowser:
```
$('.share-button').on('click', function(e) {
var href = $(this).attr('href');
e.preventDefault();
console.log('sending message', href);
webkit.messageHandlers.cordova_iab.postMessage(JSON.stringify({url: href}));
return false;
});
```
Code in application that calls inAppBrowser window and listens to message event:
```
element.on('click', function(e) {
e.preventDefault();
var browserWindow = cordova.InAppBrowser.open(element.attr('href'), element.attr('target'), 'location=no,zoom=no');
browserWindow.addEventListener('message', function(params) {
console.log('params', params);
if (params.data.url) {
cordova.InAppBrowser.open(params.data.url, '_system');
}
});
return false;
});
```
### Environment, Platform, Device
Platform: Android. Tested on emulator (API 26) and real device (Android 8.1) with same result.
### Version information
Cordova: 9.0.0 (cordova-lib@9.0.1)
cordova-plugin-inappbrowser 3.1.0 "InAppBrowser"
Cordova platform: android 7.1.4
## Checklist
- [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
Contributor guide
Research direction
Reproduce the Android behavior on the reported Cordova and cordova-plugin-inappbrowser versions using the supplied postMessage and message-listener snippets. Start at the cordova.InAppBrowser.open entry points and message event handling, then verify that repeated postMessage calls still reach the listener after opening a _system link.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, javascript
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100