Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

inapp-spy

shalanah21.3kMIT5.0.0TypeScript support: included

detect in-app browsers

inapp, in-app, iab, inapp-spy, in-app-spy, inappspy, detect-inapp, detect, browser, spy

readme

InAppSpy 🔎

Detect in-app browsers (a maintained fork and refactor of detect-inapp)

Installation

pnpm add inapp-spy
yarn add inapp-spy
npm install inapp-spy

Or via CDN

<script src="https://cdn.jsdelivr.net/npm/inapp-spy@latest/dist/index.global.min.js"></script>

Code Examples

Basic

import InAppSpy from "inapp-spy";

const { isInApp, appKey, appName } = InAppSpy();

API Reference

Return properties

{
  isInApp: boolean;

  appKey: "facebook" |
    "gsa" |
    "instagram" |
    "line" |
    "linkedin" |
    "snapchat" |
    "telegram" |
    "threads" |
    "tiktok" |
    "twitter" |
    "wechat" |
    "messenger" |
    undefined; // can be undefined even if `isInApp: true`

  // Pretty printed app name
  // - `appKey: 'tiktok', appName: 'TikTok'`
  // - May change, use `appKey` for programmatic use
  appName: string;

  ua: string; // The user agent figured out by `InAppSpy()`

  skipped: boolean; // debugging, if decided to skip this will be true
}

Parameters (optional)

InAppSpy({
  // User agent for server side - leave blank for better client in-app detection
  ua?: string;
  // Skip a specific appKey from detection
  skip?: {
    appKey: AppKey; // "messenger" | "facebook" etc
    platform?: "apple" | "android"; // use undefined for all platforms or leave blank
  }[];
})

NEW SFSafariViewController detection

With escape link usage: Always include a query string on escape links just in case false positives occur. If query string is present - ignore the detection.

This is a new experimental method to help you mitigate SFSafariViewController issues - ie awkward downloading experience

SFSVCExperimental may give false positives on Safari browser or change with OS updates. Test code on devices before pushing to prod. Feedback is appreciated!

JS usage

import InAppSpy, { SFSVCExperimental } from "inapp-spy";

const { isInApp, appKey, appName } = InAppSpy(); // normal detection

// Async needed - targets Safari 17+
SFSVCExperimental().then((isSFSVC) => /* ...`*/);

React usage

import InAppSpy, { SFSVCExperimental } from "inapp-spy";

export const App = () => {
  const [{ isInApp }] = useState(() => InAppSpy());
  const [isSFSVC, setIsSFSVC] = useState(false);

  useEffect(() => {
    // Async needed - targets Safari 17+
    SFSVCExperimental().then(setIsSFSVC);
  }, []);

  ...
};

Debugging

If SFSVCExperimental returns false positives on your app but not on InAppDebugger, try increasing the maxTime along with debug: true. You are possibly loading additional scripts dynamically immediately after the page loads that is delaying detection.

SFSVCExperimental({
  debug?: boolean; // (default: false) Debug mode - logs to console
  maxTime?: number; // (default: 300 (ms)) This is the max time used to detect if this is Safari and not SFSVC. If you are getting false positives try increasing this number first.
  maxVersion?: string; // (ie: "21.5.1", default: undefined) Max version of Safari to use this detection type - I hope it works forever! This is just in case stop gap if detection stops working :)
});

License

MIT License

Related

  • InAppDebugger - Debug in-app browsers. Uses both bowser and inapp-spy libraries.
  • Bowser - Browser + OS detection

Thanks

inapp-spy is a fork of detect-inapp with modifications. This wouldn't exist without the original work of the detect-inapp contributors.

changelog

inapp-spy

5.0.0

Major Changes

  • 95c2027: Fix global access to InAppSpy for non-global import/requires

4.4.0

Minor Changes

  • 72e877c: Removes browser field from package, adds explicit bundles for jsdelivr, unpkg, and adds exports for global

4.3.1

Patch Changes

  • 9c7bfd5: fix url for cdn in readme

4.3.0

Minor Changes

  • b6a51b3: Add ua optional param, update Readme with CDN

4.2.1

Patch Changes

  • 95ac4f9: Fix exports

4.2.0

Minor Changes

  • 6634e0f: Create iife build for CDNs

4.1.1

Patch Changes

  • e1f11ac: Update readme with bsky link over x link and order appkeys in alpha order

4.1.0

Minor Changes

  • 3c381dd: - Add recent Meta UAs to tests
    • Add threads appKey
    • Adjust messenger regex for newer UAs

4.0.2

Patch Changes

  • dc218c7: Removes post-install script that was only used for branch deploys

4.0.1

Patch Changes

  • 5e281f0: - Remove src from build (was only used in branch builds temporarily)

4.0.0

Major Changes

  • e5c457c: - Adds detection for telegram, gsa, and linkedin
    • Adds property skip and return property skipped
    • Adds SFSVCExperimental method
    • Removes (breaking) property ua for InAppSpy method
    • Refactors tests

3.0.1

Patch Changes

  • 98f9b98: Fix main path for commonjs

3.0.0

Major Changes

  • 59fb3bd: Remove isSFSafariViewController - still testing

2.1.1

Patch Changes

  • fd3bed2: return isSFSafariViewController always

2.1.0

Minor Changes

  • 09ac525: Adds experimental detection of SFSafariViewController

2.0.4

Patch Changes

  • cd2b859: edit readme for npm

2.0.3

Patch Changes

  • d5b926a: edit readme

2.0.2

Patch Changes

  • update readme for npm

2.0.1

Patch Changes

  • 0f5d5a6: Update readme for package

2.0.0

Major Changes

  • 166ce90: appName is not a pretty printed version of found app and appKey is the former appName

1.0.7

Patch Changes

  • e775e7d: Test out publishing workflow

1.0.6

Patch Changes

  • c1623de: Test workflow

1.0.5

Patch Changes

  • c18d453: Release testing

1.0.4

Patch Changes

  • Test out manual workflow
  • d781f07: More deploy testing
  • 223a227: More workflow testing
  • 07249f0: More workspace
  • dc91fba: Working on deploy setup
  • 2ab6131: more tests

1.0.3

Patch Changes

  • 57d318b: Work on deployment

1.0.2

Patch Changes

  • 16b2c8b: Testing out npm package publishing

1.0.1

Patch Changes

  • 2d2134e: Initial version