### Install Dependencies with pnpm Source: https://github.com/shalanah/inapp-spy/blob/main/CONTRIBUTING.md Installs project dependencies using the pnpm package manager. Ensure Node.js is managed with nvm. ```shell nvm use pnpm install ``` -------------------------------- ### Run Project Tests Source: https://github.com/shalanah/inapp-spy/blob/main/CONTRIBUTING.md Executes the project's test suite using the pnpm test command. This verifies the setup and code integrity. ```shell pnpm test ``` -------------------------------- ### Install InAppSpy via npm Source: https://github.com/shalanah/inapp-spy/blob/main/README.md This command installs the InAppSpy package using npm, making it available for use in your project. ```sh npm install inapp-spy ``` -------------------------------- ### SFSafariViewController Detection (React) Source: https://github.com/shalanah/inapp-spy/blob/main/README.md This React example demonstrates how to integrate InAppSpy's basic detection and the experimental SFSVCExperimental function within a React component, including state management and effect hooks. ```typescriptreact import InAppSpy, { SFSVCExperimental } from "inapp-spy"; import { useState, useEffect } from "react"; export const App = () => { const [{ isInApp }] = useState(() => InAppSpy()); const [isSFSVC, setIsSFSVC] = useState(false); useEffect(() => { // Detects in Safari 17+ - requires async SFSVCExperimental().then(setIsSFSVC); }, []); ... }; ``` -------------------------------- ### Include InAppSpy via CDN Source: https://github.com/shalanah/inapp-spy/blob/main/README.md This HTML snippet shows how to include the InAppSpy library directly from a CDN, making its global build available for use. ```html ``` -------------------------------- ### Record Version Changeset Source: https://github.com/shalanah/inapp-spy/blob/main/CONTRIBUTING.md Generates a changeset to record version bumps and changelog entries when changes affect the published output. This command is part of the changeset tool. ```shell pnpm changeset ``` -------------------------------- ### Basic InAppSpy Usage (JavaScript) Source: https://github.com/shalanah/inapp-spy/blob/main/README.md This JavaScript code demonstrates the basic usage of InAppSpy to detect if the current environment is an in-app browser and retrieve associated information like appKey and appName. ```javascript import InAppSpy from "inapp-spy"; const { isInApp, appKey, appName } = InAppSpy(); ``` -------------------------------- ### SFSafariViewController Debugging Options Source: https://github.com/shalanah/inapp-spy/blob/main/README.md This TypeScript snippet illustrates how to configure debugging options for SFSVCExperimental, such as enabling detailed logging, setting a maximum time for detection, or specifying a maximum Safari version. ```typescript SFSVCExperimental({ debug?: boolean; // log details (default: false) maxTime?: number; // ms before assuming Safari (default: 300) maxVersion?: string; // e.g. "21.5.1" (default: none) }); ``` -------------------------------- ### InAppSpy Core Detection Source: https://github.com/shalanah/inapp-spy/blob/main/README.md Provides the core functionality to detect if the current environment is an in-app browser and returns relevant information. ```APIDOC ## InAppSpy() ### Description Initializes InAppSpy for in-app browser detection. It analyzes the current environment to determine if it's within an in-app browser and provides details about the detected app. ### Method `InAppSpy()` ### Parameters #### Optional Parameters - **ua** (string) - Optional - Provide a User-Agent string for server-side detection. Leave blank on the client for better accuracy. - **skip** (Array<{ appKey: string; platform?: "apple" | "android" }>) - Optional - An array of objects to exclude specific apps or platforms from detection. `appKey` can be one of: `facebook`, `gsa`, `instagram`, `line`, `linkedin`, `snapchat`, `telegram`, `threads`, `tiktok`, `twitter`, `wechat`, `messenger`. `platform` can be `apple` or `android`. ### Return Properties - **isInApp** (boolean) - True if an in-app browser has been detected. - **appKey** (string) - A machine-friendly key representing the detected in-app browser (e.g., `facebook`, `instagram`). Can be undefined if `isInApp` is true and detection strategy fails. - **appName** (string) - A human-readable name of the detected in-app browser (e.g., "TikTok"). - **ua** (string) - The resolved or provided User-Agent string. - **skipped** (boolean) - True if the detection process was bypassed via the `skip` option. ### Request Example ```javascript import InAppSpy from "inapp-spy"; const { isInApp, appKey, appName, ua, skipped } = InAppSpy(); console.log(isInApp, appKey, appName, ua, skipped); ``` ### Response Example (Success) ```json { "isInApp": true, "appKey": "instagram", "appName": "Instagram", "ua": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 Instagram 312.0.0.44.108 (424887896; parseBuild/312.0.0.44.108; is20230927_082257)", "skipped": false } ``` ``` -------------------------------- ### SFSafariViewController Experimental Detection Source: https://github.com/shalanah/inapp-spy/blob/main/README.md Detects if a page is opened within Apple's SFSafariViewController, useful for addressing specific iOS browser behaviors. ```APIDOC ## SFSVCExperimental() ### Description Detects if a page is opened within Apple's SFSafariViewController. This is experimental and may have false positives or change with iOS updates. It is recommended to test on real devices. ### Method `SFSVCExperimental({ debug?: boolean; maxTime?: number; maxVersion?: string })` ### Parameters #### Optional Parameters - **debug** (boolean) - Optional - Logs detection details. Defaults to `false`. - **maxTime** (number) - Optional - The maximum time in milliseconds before assuming the page is loaded in Safari. Defaults to `300`. - **maxVersion** (string) - Optional - A maximum version string (e.g., "21.5.1") to check against. Defaults to no version restriction. ### Usage **JavaScript** ```javascript import { SFSVCExperimental } from "inapp-spy"; SFSVCExperimental().then((isSFSVC) => { console.log("Is SFSVC:", isSFSVC); }); // With options SFSVCExperimental({ debug: true, maxTime: 500, maxVersion: "21.0.0" }).then((isSFSVC) => { console.log("Is SFSVC (with options):", isSFSVC); }); ``` **React** ```javascript import InAppSpy, { SFSVCExperimental } from "inapp-spy"; import React, { useState, useEffect } from 'react'; export const App = () => { const [{ isInApp }] = useState(() => InAppSpy()); const [isSFSVC, setIsSFSVC] = useState(false); useEffect(() => { SFSVCExperimental().then(setIsSFSVC); }, []); return (
In App Browser Detected: {isInApp ? 'Yes' : 'No'}
SFSafariViewController Detected: {isSFSVC ? 'Yes' : 'No'}