@capacitor/inappbrowser
The InAppBrowser Plugin provides a web browser view that allows you to load any web page externally. It behaves as a standard web browser and is useful to load untrusted content without risking your application's security. It offers three different ways to open URLs; in a WebView, in an in-app system browser (Custom Tabs for Android and SFSafariViewController for iOS), and in the device's default browser.
Install
npm install @capacitor/inappbrowser
npx cap sync
Supported Platforms
- iOS
- Android
Android
The InAppBrowser plugin requires a minimum Android SDK target of 26. This is higher than the default that comes with your Capacitor application. You can update this value in your android/variables.gradle
file.
ext {
minSdkVersion = 26
}
Usage Example
Open In External Browser
import { InAppBrowser } from '@capacitor/inappbrowser';
await InAppBrowser.openInExternalBrowser({
url: "https://www.google.com"
});
Open In System Browser (Custom Tabs for Android, SFSafariViewController for iOS)
import { InAppBrowser, DefaultSystemBrowserOptions } from '@capacitor/inappbrowser';
await InAppBrowser.openInSystemBrowser({
url: "https://www.google.com",
options: DefaultSystemBrowserOptions
});
Open In Web View
import { InAppBrowser, DefaultWebViewOptions } from '@capacitor/inappbrowser';
await InAppBrowser.openInWebView({
url: "https://www.google.com",
options: DefaultWebViewOptions
});
Close (Web View or System Browser)
import { InAppBrowser } from '@capacitor/inappbrowser';
await InAppBrowser.close();
Add Listeners
import { InAppBrowser } from '@capacitor/inappbrowser';
await InAppBrowser.addListener('browserClosed', () => {
console.log("browser was closed.");
});
await InAppBrowser.addListener('browserPageLoaded', () => {
console.log("browser was loaded.");
});
Remove All Listeners
import { InAppBrowser } from '@capacitor/inappbrowser';
InAppBrowser.removeAllListeners();