apache / apache/cordova-plugin-inappbrowser
postMessage on Android requires that message string is wrapped with {}
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 2.2k
- PR merge metrics
- No merged PRs in 30d
Description
# Bug Report
## Problem
postMessage on Android requires that message string is wrapped with {} and causes a silent error that is seen only in logcat and not in js console.
### What is expected to happen?
I would expect that either
- any string would be valid for postMessage
or
- explicit error in JS console and clear statement in documentation that message needs to be a json object
### What does actually happen?
String needs to be valid JSON object and code fails silently if it is not.
## Information
Java [JSONObject](https://stleary.github.io/JSON-java/org/json/JSONObject.html#JSONObject-java.lang.String-) constructor that is causing the issue.
### Command or Code
var message = 42;
var stringifiedMessage = JSON.stringify(message);
webkit.messageHandlers.cordova_iab.postMessage(stringifiedMessage);
### Environment, Platform, Device
Environment:
- OS: darwin
- Node: v10.15.1
- npm: 6.11.1
id: 1 or "android-28"
- Name: Android API 28
- Type: Platform
- API level: 28
- Revision: 6
### Version information
cordova-plugin-inappbrowser 3.1.0 "InAppBrowser"
## 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
Start by locating the Android implementation behind the cordova_iab postMessage handler and inspect the Java JSONObject constructor mentioned in the report. Reproduce the case with JSON.stringify(42) on Android API 28, then verify that the resulting behavior is either accepted consistently or reported clearly in the JavaScript console and documentation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java, javascript
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100