0
我正在使用Cordova的InAppBrowser插件(v1.1.1)進行OAuth登錄過程。不幸的是,InAppBrowser似乎沒有關閉瀏覽器。我的「closeBrowser」函數不斷觸發間隔,並且瀏覽器保持屏幕上的Android狀態(我目前還沒有試過其他設備。)InAppBrowser不關閉?
有沒有辦法強制關閉除.close()
之外的InAppBrowser,或隱藏它?或者,也許我的代碼中有一個缺陷,就是鎖定瀏覽器。
LogInPage.prototype.handleExternalLogin = function (externalLogin) {
var _this = this;
var ref = window.open(Environment_1.settings.baseUrl + externalLogin.route.url, "_blank", "location=no");
ref.addEventListener('loadstart', function (event) {
if (_.startsWith(event.url, Environment_1.settings.baseUrl + "/api/Account/account/ExternalLoginCallback")) {
// Now we want to load a different url that will give us the mobile access token
console.log('get external-mobile-token');
_this.closeBrowser(ref);
var ref2 = window.open(Environment_1.settings.baseUrl + "/api/Account/external-mobile-token", "_blank" /*, "location=no"*/);
ref2.addEventListener('loadstop', function (event) {
console.log('loadstop ' + event.url);
if (event.url == Environment_1.settings.baseUrl + "/api/Account/external-mobile-token") {
ref2.executeScript({ code: 'window.document.documentElement.innerText' }, function (contents) {
_this.login(contents);
_this.closeBrowser(ref2);
});
}
});
ref2.addEventListener('loaderror', function (event) {
console.log(event);
_this.closeBrowser(ref2);
// TODO - do something?
});
}
});
ref.addEventListener('loaderror', function (event) {
console.log(event);
_this.closeBrowser(ref);
// TODO - do something?
});
};
LogInPage.prototype.closeBrowser = function (browser) {
var interval = setInterval(function() {
console.log('closing');
browser.close();
}, 10);
browser.addEventListener('exit', function() {
console.log('closed');
clearInterval(interval);
});
};
LogInPage.prototype.login = function (token) {
console.log(token);
};
上面的代碼實際上是從TypeScript生成的,但我想我不會混淆這個問題。