deepLinkPrevented event
Copy a setup prompt with the install steps and the full markdown guide for this plugin.
When to use it
Section titled โWhen to use itโRequires @capgo/capacitor-inappbrowser 8.28.0 or newer from capacitor-inappbrowser #787.
Set preventDeeplink: true on openWebView() when taps on tel:, mailto:, custom schemes, or other external hand-offs should stay inside your managed WebView. The plugin emits deepLinkPrevented with { url, id? } so your app can show UI, route in-app, or log analytics.
Android and iOS emit this event. The web implementation does not emit deepLinkPrevented today.
Example
Section titled โExampleโopenWebView() resolves when the WebView is ready, not when the user closes it. Register deepLinkPrevented before opening, keep the listener for the whole browser session, and remove it when the session ends or your owning component tears down.
In the example below, the WebView loads a checkout page on one host. authorizedAppLinks lists a different partner host so iOS can emit deepLinkPrevented when the user taps a partner Universal Link, not when they stay on the checkout URL you opened.
import { InAppBrowser } from '@capgo/capacitor-inappbrowser';
const deepLinkListener = await InAppBrowser.addListener('deepLinkPrevented', ({ id, url }) => { console.log('Blocked hand-off', id, url);});
let sessionId: string | undefined;let closeListener = await InAppBrowser.addListener('closeEvent', async ({ id }) => { if (id !== sessionId) { return; } await deepLinkListener.remove(); await closeListener.remove();});
try { const { id } = await InAppBrowser.openWebView({ url: 'https://checkout.example.com/', preventDeeplink: true, authorizedAppLinks: ['https://partner.example'], }); sessionId = id;} catch (error) { await deepLinkListener.remove(); await closeListener.remove(); throw error;}Platform notes
Section titled โPlatform notesโ- iOS: Universal Links emit
deepLinkPreventedonly when the link matches an entry inauthorizedAppLinks(full URLs such ashttps://partner.example, not bare hostnames). Do not list the same URL you passed toopenWebView()unless you intend to handle navigation on that host. App Store hosts and custom schemes emit the event when prevention blocks the hand-off. - Android:
preventDeeplinkstill blocks non-http(s) URLs and emits the event for those links. Authorized App Links keep the existing external launch behavior on Android.