IONIC Cordova retrieve InAppBrowser URL - javascript

I am creating an Ionic 3 application, I need to get the URL from the frame generated from inAppBrowser.
The frame is created here :
var browser = this.inAppBrowser.create("http://apache.org", "_blank", "location=no,clearsessioncache=yes,clearcache=yes");
browser.on('loadstop').subscribe(function(event) {
browser.show();
console.log(event.url);
});
I use the apache website for testing purposes but the url is meant to change as the user goes through the webpage, that is why I'm trying to retrieve it through an event.
My problem is that the "event.url" property keeps returning "null".
Version : IONIC 3.2.0 ; Cordova 8.0.0
Many thanks for whoever will help me!
FIX : I found the solution, the desktop browser is always returning null, I tried on a android simulator and it works !
Thanks for your answers.

Related

Branch.io Cordova API - init() fails on Android Device

I'm having problems getting Branch.io to work in a Cordova powered Android app. I have a landing page that parses the data from branch.io deep links and forwards the user to the correct page. My javascript for this page contains:
function onDeviceReady() {
console && console.log("Device Ready");
initBranch();
}
function initBranch() {
branch.init(<branchKey>, function(err, data) {
console && console.log("branch init error: " + err);
//then the parsing and forwarding follows - omitted here
}
I then created a Branch.io deep link to this landing page in the web api and tested it in chrome which works.
Then i tried to move to the Cordova app...
I followed this guide to prepare the app for branch.io:
https://dev.branch.io/recipes/quickstart_guide/cordova/ (I installed the plugin and adapted the Manifest file.)
But when i try to open the same link that worked in chrome on my Android device the app opens correctly and the landing page loads, but i'm not forwared. Instead i see the following error in logcat:
I/chromium(19382): [INFO:CONSOLE(22)] "Device Ready"
[...]
I/chromium(19382): [INFO:CONSOLE(29)] "branch init error: Error: API request /v1/open missing parameter device_fingerprint_id"
Can anyone tell me what i'm doing wrong? I'm just getting to know Cordova and Branch.io so it's probably something small i'm overlooking.
Thanks,
Lif
A colleague of mine figured it out:
Branch.io creates an entry branch_session in the local storage of the android device. On my device this session was corrupted somehow and the device_fingerprint_id was empty:
{"session_id":"198413861345316824","identity_id":"198398707320770300","device_fingerprint_id":null,"browser_fingerprint_id":null,"link":"<link>","data":"{\"+is_first_session\":false,\"+clicked_branch_link\":false}"}
After clearing the local storage* the session was freshly created, and now looks like this:
{"session_id":"198413861345316824","identity_id":"198398707320770300","device_fingerprint_id":"118176839880411216","browser_fingerprint_id":null,"link":<link>,"data":"{\"+is_first_session\":false,\"+clicked_branch_link\":false}"}
And now deep linking works.
Kr,
Lif
* To clear the local storage i used chrome://inspect --> inspect webview, go to resources tab, choose "local storage" and the the correct url, then remove all values.

Phonegap 3.0 Angular.js unable to use InAppBrowser

I'm working on a project based on PhoneGap 3.0 and Angular.js. I try to use InAppBrowser with the following controller :
function AccueilCtrl($scope,$window) {
$scope.openUrl = function() {
var ref = $window.open('http://www.google.fr', '_blank', 'location=yes');
};
}
I call this function, in a view, with :
<a ng-click="openUrl()">Open Page</a>
I followed insctructions, and used the cli version of PhoneGap 3.0 :
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git
phonegap build ios
But when I launch the app, either in simulator, or on a real device, the window does not show nav bars at all, it's just full screen. Replacing "_blank" with "_system" doesn't change anything, Safari does not launch.
Do you think this is a bug in PhoneGap or Angular, or am I missing something? How can I debug or trace to find what's wrong? Thx

Back variables from InAppBrowser

im using cordova 2.5.0 and I have problems to communicate a new window with my app with the InAppBrowser. It is possible to send back information from a page opened with InAppBrowser plugin to my cordova app.
This used to be a little involved (like polling or custom urls), but since inAppBrowser 3.0.0 you can use AllowedSchemes with the customscheme event. This is not documented yet, but can be used as follows.
To your config.xml, add
<preference name="AllowedSchemes" value="myscheme" />
with the following code in your Cordova app:
function onCustomScheme(e) {
if (e.url.match(/^myscheme:\/\/message\b/)) {
var q = parseQueryString(e.url);
console.log("Got foo message: " + q.text);
}
}
url = "https://my.example.com/";
app = cordova.InAppBrowser.open(url, "_blank");
app.addEventListener("customscheme", onCustomScheme, false);
Then from the website opened in the inAppBrowser, you can embed a link like this, which shows the message hi there in the console if you follow it.
Test
This won't work with Cordova 2.5 (it looks like you'll need at least 3.1), but as 8 is out now, it's probably a good idea to upgrade anyway.

Jquery internal ajax (get) not working on phonegap + android 2.2

I don't know for sure if the problem is in the request or in the display of the results, but this is not working for me, when I tap on the link on the phone I get a white screen, on desktop (Chrome) works without problems.
$('a').on('click', function(click_event){
$.get($(this).attr('href'),function(response_text){
$('body').html(response_text)
})
click_event.preventDefault()
return false
})
'Debugging' with weinre it tells me it enters on the get function...
I'm using PhoneGap Build and have not set a config.xml, but when I install the app on the phone, it ask permission to access to the Internet...
Any help would be appreciated.
What is the URL within the href?
Is it an external URL or a local path?
If the latter, read in to the Whitelist Guide here...
http://docs.phonegap.com/en/2.5.0/guide_whitelist_index.md.html#Domain%20Whitelist%20Guide
I solved the problem by adding the last parameter 'dataType' as 'html' on the get call, for some reason it was assuming another type of content (xml or json I guess). Everything is working fine now :)

Loading Meteor .js in a local Html file in android

I am trying to work with Meteor. Now I have the entire setup running in my localmachine with apache2 and the meteor.js also works when browsing the same URL from Android Emulator's Browser . Now the main problem is that I need the functionality in my android app from a local URL and here the page is not able to load the remote js. I am loading the following html using WebViews loadURL method after setting the javascript as enabled .The js embedded in the html will be something like this
<script type="text/javascript" src="http://meteor.mywebserver.com/meteor.js"></script>
<script type="text/javascript">
window.onload = function()
{
Meteor.host = "meteor.mywebserver.com";
alert(textStatus);
// Call the test() function when data arrives
Meteor.registerEventCallback("process", commentsUpdate);
// Join the demo channel and get last five events, then stream
Meteor.joinChannel("demo", 0);
Meteor.mode = 'longpoll';
// Start streaming!
Meteor.connect();
// Handle incoming events
function commentsUpdate(data)
{
alert(data);
};});
After searching around a lot I tried this stackoverflow answer
To no avail . Can anybody help me find a work around here , I cant use a local meteor.js as it wont work.
Thanks
This has since been addressed in Meteor by way of integrated Cordova, which you can read about here. Basically, you tell Meteor that you want to add the Android platform to your app, and it builds the Android project files for you. Your app will look as if it's running native, but it's really just running in a light app surrounding a "web view". In iOS this is done using WebKit, but I think in Android it depends on the version of the OS.
You will still need to deploy your app to the Play store, which requires signing the app and all.

Categories

Resources