I can open my window, and do a lot of things inside of it, for example login via Linkedin or Facebook. But I cannot close it to return to my app.
1/ I tried to cat
I could find a way to solve this problem. It's weird and biased. But as I see I am not the only one, I'm writing here my solution and the way I could solve that bug.
First, I added another listener :
ref.addEventListener('exit', function(event)
{
if (debug) alert('exit');
});
Then, I used the inject script functionality and I called it every 5 seconds;
function getStateSecondWindow()
{
ref.executeScript(
{code: "localStorage.getItem('loginOauth')"},
function(data)
{
alert(data);
}
);
}
setInterval(getStateSecondWindow, 5000);
At that stage, I could see something weird in the logs : the first call to getStateSecondWindow was blocked. But then /everything/ started to work. I suddenly had all my event listeners working correctly. It was like I had a jam somewhere and the executeScript() just unblocked everything.
This solution worked for my 4 projects. The behaviour was the same for each of them.
In case the event had problems again, I used a double system to check my second page and find a way to close it at the right moment : in the second page, I used the local storage to set the value of my var : localStorage.setItem( "loginOauth", 'OK');
In my first page, I used the execute script to go to read that local storage :
function getStateSecondWindow() {
ref.executeScript(
{code: "localStorage.getItem('loginOauth')"},
function(data)
{
if (data=='OK')
{
//do what I need to do
ref.close();
}
}
);
With this system, I was not dependent of the (sometimes not) firing event. It works even if the page in the inappBrowser window comes from another server : as the javascript is interpreted in the second window, we are in the same domain where the original localStorage was made (no crossbrowsing problem).
So this is how I could go thought the inAppBroswer not firing events and find a way to close the second window when needed. Hope it helps :)