nativescript-inappbrowser
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -53,3 +53,3 @@ "use strict"; | ||
exports.BROWSER_ACTIVITY_EVENTS.set('message', 'chrome tabs activity closed'); | ||
exports.BROWSER_ACTIVITY_EVENTS.set('resultType', 'cancel'); | ||
exports.BROWSER_ACTIVITY_EVENTS.set('resultType', this.resultType); | ||
break; | ||
@@ -56,0 +56,0 @@ default: |
@@ -41,5 +41,5 @@ import { EventData } from 'tns-core-modules/data/observable'; | ||
isAvailable(): Promise<boolean>; | ||
open(url: string, inAppBrowserOptions?: InAppBrowserOptions): Promise<BrowserResult>; | ||
open(url: string, options?: InAppBrowserOptions): Promise<BrowserResult>; | ||
close(): void; | ||
openAuth(url: string, redirectUrl: string, inAppBrowserOptions?: InAppBrowserOptions): Promise<AuthSessionResult>; | ||
openAuth(url: string, redirectUrl: string, options?: InAppBrowserOptions): Promise<AuthSessionResult>; | ||
closeAuth(): void; | ||
@@ -46,0 +46,0 @@ onEvent(event: EventData): void; |
@@ -14,2 +14,3 @@ "use strict"; | ||
var InAppBrowser_common_1 = require("./InAppBrowser.common"); | ||
var utils_android_1 = require("./utils.android"); | ||
var CustomTabsIntent = (useAndroidX() ? androidx.browser : android.support).customtabs.CustomTabsIntent; | ||
@@ -29,4 +30,4 @@ function useAndroidX() { | ||
}; | ||
InAppBrowserModule.prototype.open = function (url, inAppBrowserOptions) { | ||
if (inAppBrowserOptions === void 0) { inAppBrowserOptions = {}; } | ||
InAppBrowserModule.prototype.open = function (url, options) { | ||
if (options === void 0) { options = {}; } | ||
var mOpenBrowserPromise = InAppBrowserModule.redirectResolve; | ||
@@ -44,6 +45,6 @@ if (mOpenBrowserPromise) { | ||
} | ||
var options = InAppBrowser_common_1.getDefaultOptions(url, inAppBrowserOptions); | ||
var inAppBrowserOptions = InAppBrowser_common_1.getDefaultOptions(url, options); | ||
var builder = new CustomTabsIntent.Builder(); | ||
if (options[InAppBrowserModule.KEY_TOOLBAR_COLOR]) { | ||
var colorString = options[InAppBrowserModule.KEY_TOOLBAR_COLOR]; | ||
if (inAppBrowserOptions[InAppBrowserModule.KEY_TOOLBAR_COLOR]) { | ||
var colorString = inAppBrowserOptions[InAppBrowserModule.KEY_TOOLBAR_COLOR]; | ||
try { | ||
@@ -56,4 +57,4 @@ builder.setToolbarColor(new color_1.Color(colorString).android); | ||
} | ||
if (options[InAppBrowserModule.KEY_SECONDARY_TOOLBAR_COLOR]) { | ||
var colorString = options[InAppBrowserModule.KEY_SECONDARY_TOOLBAR_COLOR]; | ||
if (inAppBrowserOptions[InAppBrowserModule.KEY_SECONDARY_TOOLBAR_COLOR]) { | ||
var colorString = inAppBrowserOptions[InAppBrowserModule.KEY_SECONDARY_TOOLBAR_COLOR]; | ||
try { | ||
@@ -66,15 +67,15 @@ builder.setSecondaryToolbarColor(new color_1.Color(colorString).android); | ||
} | ||
if (options[InAppBrowserModule.KEY_ENABLE_URL_BAR_HIDING]) { | ||
if (inAppBrowserOptions[InAppBrowserModule.KEY_ENABLE_URL_BAR_HIDING]) { | ||
builder.enableUrlBarHiding(); | ||
} | ||
if (options[InAppBrowserModule.KEY_DEFAULT_SHARE_MENU_ITEM]) { | ||
if (inAppBrowserOptions[InAppBrowserModule.KEY_DEFAULT_SHARE_MENU_ITEM]) { | ||
builder.addDefaultShareMenuItem(); | ||
} | ||
var context = utils_1.ad.getApplicationContext(); | ||
if (options[InAppBrowserModule.KEY_ANIMATIONS]) { | ||
var animations = options[InAppBrowserModule.KEY_ANIMATIONS]; | ||
if (inAppBrowserOptions[InAppBrowserModule.KEY_ANIMATIONS]) { | ||
var animations = inAppBrowserOptions[InAppBrowserModule.KEY_ANIMATIONS]; | ||
this.applyAnimation(context, builder, animations); | ||
} | ||
var customTabsIntent = builder.build(); | ||
var keyHeaders = options[InAppBrowserModule.KEY_HEADERS]; | ||
var keyHeaders = inAppBrowserOptions[InAppBrowserModule.KEY_HEADERS]; | ||
if (keyHeaders) { | ||
@@ -89,3 +90,3 @@ var headers = new Bundle(); | ||
} | ||
if (options[InAppBrowserModule.KEY_FORCE_CLOSE_ON_REDIRECTION]) { | ||
if (inAppBrowserOptions[InAppBrowserModule.KEY_FORCE_CLOSE_ON_REDIRECTION]) { | ||
customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); | ||
@@ -97,4 +98,4 @@ customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
intent.setData(Uri.parse(url)); | ||
if (options[InAppBrowserModule.KEY_SHOW_PAGE_TITLE]) { | ||
builder.setShowTitle(!!options[InAppBrowserModule.KEY_SHOW_PAGE_TITLE]); | ||
if (inAppBrowserOptions[InAppBrowserModule.KEY_SHOW_PAGE_TITLE]) { | ||
builder.setShowTitle(!!inAppBrowserOptions[InAppBrowserModule.KEY_SHOW_PAGE_TITLE]); | ||
} | ||
@@ -128,6 +129,6 @@ else { | ||
}; | ||
InAppBrowserModule.prototype.openAuth = function (url, redirectUrl, inAppBrowserOptions) { | ||
if (inAppBrowserOptions === void 0) { inAppBrowserOptions = {}; } | ||
InAppBrowserModule.prototype.openAuth = function (url, redirectUrl, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var options; | ||
var inAppBrowserOptions; | ||
var _this = this; | ||
@@ -137,11 +138,11 @@ return __generator(this, function (_a) { | ||
case 0: | ||
options = InAppBrowser_common_1.getDefaultOptions(url, inAppBrowserOptions); | ||
inAppBrowserOptions = InAppBrowser_common_1.getDefaultOptions(url, options); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, , 3, 4]); | ||
return [4, InAppBrowser_common_1.openAuthSessionPolyfillAsync(url, redirectUrl, options, function (startUrl, opt) { return _this.open(startUrl, opt); })]; | ||
return [4, utils_android_1.openAuthSessionPolyfillAsync(url, redirectUrl, inAppBrowserOptions, function (startUrl, opt) { return _this.open(startUrl, opt); })]; | ||
case 2: return [2, _a.sent()]; | ||
case 3: | ||
utils_android_1.closeAuthSessionPolyfillAsync(); | ||
this.close(); | ||
InAppBrowser_common_1.closeAuthSessionPolyfillAsync(); | ||
return [7]; | ||
@@ -154,4 +155,4 @@ case 4: return [2]; | ||
InAppBrowserModule.prototype.closeAuth = function () { | ||
utils_android_1.closeAuthSessionPolyfillAsync(); | ||
this.close(); | ||
InAppBrowser_common_1.closeAuthSessionPolyfillAsync(); | ||
}; | ||
@@ -158,0 +159,0 @@ InAppBrowserModule.prototype.onEvent = function (event) { |
@@ -0,1 +1,6 @@ | ||
export declare enum BROWSER_TYPES { | ||
CANCEL = "cancel", | ||
DISMISS = "dismiss", | ||
SUCCESS = "success" | ||
} | ||
export declare type RedirectEvent = { | ||
@@ -14,3 +19,1 @@ url: 'string'; | ||
export declare function getDefaultOptions(url: string, options: any): any; | ||
export declare function openAuthSessionPolyfillAsync(startUrl: string, returnUrl: string, options: any, open: (url: string, options?: any) => Promise<BrowserResult>): Promise<AuthSessionResult>; | ||
export declare function closeAuthSessionPolyfillAsync(): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var application_1 = require("tns-core-modules/application"); | ||
var BROWSER_TYPES; | ||
(function (BROWSER_TYPES) { | ||
BROWSER_TYPES["CANCEL"] = "cancel"; | ||
BROWSER_TYPES["DISMISS"] = "dismiss"; | ||
BROWSER_TYPES["SUCCESS"] = "success"; | ||
})(BROWSER_TYPES = exports.BROWSER_TYPES || (exports.BROWSER_TYPES = {})); | ||
function getDefaultOptions(url, options) { | ||
@@ -8,52 +13,2 @@ return __assign(__assign({}, options), { url: url, dismissButtonStyle: options.dismissButtonStyle || 'close', readerMode: !!options.readerMode, animated: options.animated !== undefined ? options.animated : true, modalEnabled: options.modalEnabled !== undefined ? options.modalEnabled : true, enableBarCollapsing: !!options.enableBarCollapsing }); | ||
exports.getDefaultOptions = getDefaultOptions; | ||
var _redirectHandler; | ||
function _waitForRedirectAsync(returnUrl) { | ||
return new Promise(function (resolve) { | ||
_redirectHandler = function (args) { | ||
var url = ''; | ||
if (application_1.android) { | ||
var currentActivity = args.object.foregroundActivity || args.object.startActivity; | ||
url += currentActivity.getIntent().getData(); | ||
} | ||
if (url.startsWith(returnUrl)) { | ||
resolve({ url: url, type: 'success' }); | ||
} | ||
}; | ||
application_1.on(application_1.resumeEvent, _redirectHandler); | ||
}); | ||
} | ||
function openAuthSessionPolyfillAsync(startUrl, returnUrl, options, open) { | ||
return Promise.race([ | ||
open(startUrl, options).then(function (result) { | ||
return _checkResultAndReturnUrl(returnUrl, result); | ||
}), | ||
_waitForRedirectAsync(returnUrl) | ||
]); | ||
} | ||
exports.openAuthSessionPolyfillAsync = openAuthSessionPolyfillAsync; | ||
function _checkResultAndReturnUrl(returnUrl, result) { | ||
return new Promise(function (resolve) { | ||
if (application_1.android && result.type !== 'cancel') { | ||
application_1.android.once(application_1.AndroidApplication.activityResumedEvent, function (args) { | ||
var url = '' + args.activity.getIntent().getData(); | ||
if (url.startsWith(returnUrl)) { | ||
resolve({ url: url, type: 'success' }); | ||
} | ||
else { | ||
resolve(result); | ||
} | ||
}); | ||
} | ||
else { | ||
resolve(result); | ||
} | ||
}); | ||
} | ||
function closeAuthSessionPolyfillAsync() { | ||
if (_redirectHandler) { | ||
application_1.off(application_1.resumeEvent, _redirectHandler); | ||
_redirectHandler = null; | ||
} | ||
} | ||
exports.closeAuthSessionPolyfillAsync = closeAuthSessionPolyfillAsync; | ||
//# sourceMappingURL=InAppBrowser.common.js.map |
@@ -12,2 +12,3 @@ import { BrowserResult, AuthSessionResult } from './InAppBrowser.common'; | ||
enableBarCollapsing?: boolean; | ||
ephemeralWebSession?: boolean; | ||
}; | ||
@@ -28,5 +29,5 @@ declare class InAppBrowserModule extends NSObject { | ||
isAvailable(): Promise<boolean>; | ||
open(authURL: string, inAppBrowserOptions?: InAppBrowserOptions): Promise<BrowserResult>; | ||
open(authURL: string, options?: InAppBrowserOptions): Promise<BrowserResult>; | ||
close(): void; | ||
openAuth(authUrl: string, redirectUrl: string): Promise<AuthSessionResult>; | ||
openAuth(authUrl: string, redirectUrl: string, options?: InAppBrowserOptions): Promise<AuthSessionResult>; | ||
closeAuth(): void; | ||
@@ -33,0 +34,0 @@ presentationAnchorForWebAuthenticationSession(session: ASWebAuthenticationSession): UIWindow; |
@@ -52,29 +52,29 @@ "use strict"; | ||
}; | ||
InAppBrowserModule.prototype.open = function (authURL, inAppBrowserOptions) { | ||
InAppBrowserModule.prototype.open = function (authURL, options) { | ||
var _this = this; | ||
if (inAppBrowserOptions === void 0) { inAppBrowserOptions = {}; } | ||
if (options === void 0) { options = {}; } | ||
return new Promise(function (resolve, reject) { | ||
if (!_this.initializeWebBrowser(resolve, reject)) | ||
return; | ||
var options = InAppBrowser_common_1.getDefaultOptions(authURL, inAppBrowserOptions); | ||
_this.animated = options.animated; | ||
var url = NSURL.URLWithString(options['url']); | ||
var inAppBrowserOptions = InAppBrowser_common_1.getDefaultOptions(authURL, options); | ||
_this.animated = inAppBrowserOptions.animated; | ||
var url = NSURL.URLWithString(inAppBrowserOptions['url']); | ||
if (utils_1.ios.MajorVersion >= 11) { | ||
var config = SFSafariViewControllerConfiguration.alloc().init(); | ||
config.barCollapsingEnabled = options.enableBarCollapsing; | ||
config.entersReaderIfAvailable = options.readerMode; | ||
config.barCollapsingEnabled = inAppBrowserOptions.enableBarCollapsing; | ||
config.entersReaderIfAvailable = inAppBrowserOptions.readerMode; | ||
_this.safariVC = SFSafariViewController.alloc().initWithURLConfiguration(url, config); | ||
} | ||
else { | ||
_this.safariVC = SFSafariViewController.alloc().initWithURLEntersReaderIfAvailable(url, options.readerMode); | ||
_this.safariVC = SFSafariViewController.alloc().initWithURLEntersReaderIfAvailable(url, inAppBrowserOptions.readerMode); | ||
} | ||
_this.safariVC.delegate = _this; | ||
if (utils_1.ios.MajorVersion >= 11) { | ||
if (options.dismissButtonStyle === 'done') { | ||
if (inAppBrowserOptions.dismissButtonStyle === 'done') { | ||
_this.safariVC.dismissButtonStyle = 0; | ||
} | ||
else if (options.dismissButtonStyle === 'close') { | ||
else if (inAppBrowserOptions.dismissButtonStyle === 'close') { | ||
_this.safariVC.dismissButtonStyle = 1; | ||
} | ||
else if (options.dismissButtonStyle === 'cancel') { | ||
else if (inAppBrowserOptions.dismissButtonStyle === 'cancel') { | ||
_this.safariVC.dismissButtonStyle = 2; | ||
@@ -84,16 +84,16 @@ } | ||
if (utils_1.ios.MajorVersion >= 10) { | ||
if (options.preferredBarTintColor) { | ||
_this.safariVC.preferredBarTintColor = new color_1.Color(options.preferredBarTintColor).ios; | ||
if (inAppBrowserOptions.preferredBarTintColor) { | ||
_this.safariVC.preferredBarTintColor = new color_1.Color(inAppBrowserOptions.preferredBarTintColor).ios; | ||
} | ||
if (options.preferredControlTintColor) { | ||
_this.safariVC.preferredControlTintColor = new color_1.Color(options.preferredControlTintColor).ios; | ||
if (inAppBrowserOptions.preferredControlTintColor) { | ||
_this.safariVC.preferredControlTintColor = new color_1.Color(inAppBrowserOptions.preferredControlTintColor).ios; | ||
} | ||
} | ||
var ctrl = UIApplication.sharedApplication.keyWindow.rootViewController; | ||
if (options.modalEnabled) { | ||
if (inAppBrowserOptions.modalEnabled) { | ||
var safariHackVC = UINavigationController.alloc().initWithRootViewController(_this.safariVC); | ||
safariHackVC.setNavigationBarHiddenAnimated(true, false); | ||
safariHackVC.modalPresentationStyle = getPresentationStyle(options.modalPresentationStyle); | ||
safariHackVC.modalPresentationStyle = getPresentationStyle(inAppBrowserOptions.modalPresentationStyle); | ||
if (_this.animated) { | ||
safariHackVC.modalTransitionStyle = getTransitionStyle(options.modalTransitionStyle); | ||
safariHackVC.modalTransitionStyle = getTransitionStyle(inAppBrowserOptions.modalTransitionStyle); | ||
} | ||
@@ -106,6 +106,6 @@ if (utils_1.ios.MajorVersion >= 13) { | ||
safariHackVC.presentationController.delegate = _this; | ||
ctrl.presentViewControllerAnimatedCompletion(safariHackVC, options.animated, null); | ||
ctrl.presentViewControllerAnimatedCompletion(safariHackVC, inAppBrowserOptions.animated, null); | ||
} | ||
else { | ||
ctrl.presentViewControllerAnimatedCompletion(_this.safariVC, options.animated, null); | ||
ctrl.presentViewControllerAnimatedCompletion(_this.safariVC, inAppBrowserOptions.animated, null); | ||
} | ||
@@ -126,7 +126,9 @@ }); | ||
}; | ||
InAppBrowserModule.prototype.openAuth = function (authUrl, redirectUrl) { | ||
InAppBrowserModule.prototype.openAuth = function (authUrl, redirectUrl, options) { | ||
if (options === void 0) { options = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var response; | ||
var inAppBrowserOptions, response; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
inAppBrowserOptions = __assign(__assign({}, options), { ephemeralWebSession: options.ephemeralWebSession !== undefined ? options.ephemeralWebSession : false }); | ||
if (utils_1.ios.MajorVersion >= 11) { | ||
@@ -152,3 +154,5 @@ return [2, new Promise(function (resolve, reject) { | ||
if (utils_1.ios.MajorVersion >= 13) { | ||
_this.authSession.presentationContextProvider = _this; | ||
var webAuthSession = _this.authSession; | ||
webAuthSession.prefersEphemeralWebBrowserSession = inAppBrowserOptions.ephemeralWebSession; | ||
webAuthSession.presentationContextProvider = _this; | ||
} | ||
@@ -155,0 +159,0 @@ _this.authSession.start(); |
@@ -38,3 +38,4 @@ declare module 'nativescript-inappbrowser' { | ||
modalEnabled?: boolean, | ||
enableBarCollapsing?: boolean | ||
enableBarCollapsing?: boolean, | ||
ephemeralWebSession?: boolean | ||
}; | ||
@@ -41,0 +42,0 @@ |
{ | ||
"name": "nativescript-inappbrowser", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "InAppBrowser for NativeScript", | ||
@@ -9,4 +9,4 @@ "main": "InAppBrowser", | ||
"platforms": { | ||
"android": "6.0.0", | ||
"ios": "6.0.1" | ||
"android": "6.5.0", | ||
"ios": "6.5.0" | ||
} | ||
@@ -61,9 +61,9 @@ }, | ||
"devDependencies": { | ||
"tns-core-modules": "^6.2.1", | ||
"tns-platform-declarations": "^6.2.1", | ||
"typescript": "~3.7.2", | ||
"tns-core-modules": "^6.5.1", | ||
"tns-platform-declarations": "^6.5.1", | ||
"typescript": "~3.8.3", | ||
"prompt": "^1.0.0", | ||
"rimraf": "^3.0.0", | ||
"tslint": "^5.20.1", | ||
"semver": "^6.3.0" | ||
"rimraf": "^3.0.2", | ||
"tslint": "^6.1.1", | ||
"semver": "^7.2.1" | ||
}, | ||
@@ -70,0 +70,0 @@ "dependencies": {}, |
@@ -69,2 +69,3 @@ <p align="center"> | ||
`enableBarCollapsing` (Boolean) | Determines whether the browser's tool bars will collapse or not. [`true`/`false`] | ||
`ephemeralWebSession` (Boolean) | Prevent re-use cookies of previous session (openAuth only) [`true`/`false`] | ||
@@ -146,2 +147,82 @@ ### Android Options | ||
### Authentication Flow using Deep Linking | ||
In order to redirect back to your application from a web browser, you must specify a unique URI to your app. To do this, | ||
define your app scheme and replace `my-scheme` and `my-host` with your info. | ||
- Enable deep linking (Android) - **[AndroidManifest.xml](https://github.com/proyecto26/nativescript-inappbrowser/blob/master/demo/app/App_Resources/Android/src/main/AndroidManifest.xml#L41)** | ||
``` | ||
<intent-filter> | ||
<action android:name="android.intent.action.VIEW" /> | ||
<category android:name="android.intent.category.DEFAULT" /> | ||
<category android:name="android.intent.category.BROWSABLE" /> | ||
<data android:scheme="my-scheme" android:host="my-host" android:pathPrefix="" /> | ||
</intent-filter> | ||
``` | ||
- Enable deep linking (iOS) - **[Info.plist](https://github.com/proyecto26/nativescript-inappbrowser/blob/master/demo/app/App_Resources/iOS/Info.plist#L21)** | ||
``` | ||
<key>CFBundleURLTypes</key> | ||
<array> | ||
<dict> | ||
<key>CFBundleTypeRole</key> | ||
<string>Editor</string> | ||
<key>CFBundleURLName</key> | ||
<string>my-scheme</string> | ||
<key>CFBundleURLSchemes</key> | ||
<array> | ||
<string>my-scheme</string> | ||
</array> | ||
</dict> | ||
</array> | ||
``` | ||
- utilities.ts | ||
```javascript | ||
import { android } from "tns-core-modules/application"; | ||
export const getDeepLink = (path = "") => { | ||
const scheme = 'my-scheme'; | ||
const prefix = android ? `${scheme}://my-host/` : `${scheme}://`; | ||
return prefix + path; | ||
} | ||
``` | ||
- home-page.ts | ||
```javascript | ||
import { openUrl } from 'tns-core-modules/utils/utils'; | ||
import InAppBrowser from 'nativescript-inappbrowser'; | ||
import { getDeepLink } from './utilities'; | ||
... | ||
async onLogin() { | ||
const deepLink = getDeepLink("callback") | ||
const url = `https://my-auth-login-page.com?redirect_uri=${deepLink}` | ||
try { | ||
if (await InAppBrowser.isAvailable()) { | ||
InAppBrowser.openAuth(url, deepLink, { | ||
// iOS Properties | ||
ephemeralWebSession: false, | ||
// Android Properties | ||
showTitle: false, | ||
enableUrlBarHiding: true, | ||
enableDefaultShare: false | ||
}).then((response) => { | ||
if ( | ||
response.type === 'success' && | ||
response.url | ||
) { | ||
openUrl(response.url) | ||
} | ||
}) | ||
} else openUrl(url) | ||
} catch (error) { | ||
openUrl(url) | ||
} | ||
} | ||
... | ||
``` | ||
### Authentication | ||
Using in-app browser tabs (like SFAuthenticationSession/ASWebAuthenticationSession and Android Custom Tabs) where available. Embedded user-agents, known as web-views (like UIWebView and WKWebView), are explicitly not supported due to the usability and security reasons documented in [Section 8.12 of RFC 8252](https://tools.ietf.org/html/rfc8252#section-8.12). | ||
## Credits 👍 | ||
@@ -148,0 +229,0 @@ * **React Native InAppBrowser:** [InAppBrowser for React Native](https://github.com/proyecto26/react-native-inappbrowser) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61096
24
886
271