Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@posthog/core

Package Overview
Dependencies
Maintainers
22
Versions
118
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@posthog/core - npm Package Compare versions

Comparing version
1.30.14
to
1.31.0
+13
-2
dist/utils/user-agent-utils.d.ts

@@ -11,2 +11,11 @@ /**

/**
* Opt-in tweaks to UA-string detection. These change how existing traffic is
* attributed, so the host SDK gates them (behind its `2026-05-30` config
* defaults) rather than enabling them unconditionally — turning one on
* reattributes browsers that were previously reported as something else.
*/
export interface BrowserDetectionOptions {
detectGoogleSearchApp?: boolean;
}
/**
* This function detects which browser is running this script.

@@ -20,4 +29,6 @@ * The order of the checks are important since many user agents

* behaviour.
*
* `options` toggles opt-in UA-detection tweaks (see `BrowserDetectionOptions`).
*/
export declare const detectBrowser: (user_agent: string, vendor: string | undefined, hints?: BrowserDetectionHints) => string;
export declare const detectBrowser: (user_agent: string, vendor: string | undefined, hints?: BrowserDetectionHints, options?: BrowserDetectionOptions) => string;
/**

@@ -31,3 +42,3 @@ * This function detects which browser version is running this script,

*/
export declare const detectBrowserVersion: (userAgent: string, vendor: string | undefined, hints?: BrowserDetectionHints) => number | null;
export declare const detectBrowserVersion: (userAgent: string, vendor: string | undefined, hints?: BrowserDetectionHints, options?: BrowserDetectionOptions) => number | null;
export declare const detectOS: (user_agent: string) => [string, string];

@@ -34,0 +45,0 @@ export declare const detectDevice: (user_agent: string) => string;

+1
-1

@@ -1,1 +0,1 @@

{"version":3,"file":"user-agent-utils.d.ts","sourceRoot":"","sources":["../../src/utils/user-agent-utils.ts"],"names":[],"mappings":"AA+DA;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IAGpC,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAuCD;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,GACxB,YAAY,MAAM,EAClB,QAAQ,MAAM,GAAG,SAAS,EAC1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,MAAM,KAAG,CAAC,MAAM,EAAE,MAAM,CAUrE,CAAA;AAED,eAAO,MAAM,YAAY,GAAa,YAAY,MAAM,KAAG,MAuD1D,CAAA;AAED,eAAO,MAAM,gBAAgB,GAC3B,YAAY,MAAM,EAClB,UAAU;IACR,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B,KACA,MA4BF,CAAA"}

@@ -81,2 +81,3 @@ "use strict";

const BRAVE = 'Brave';
const GOOGLE_SEARCH_APP = 'Google Search App';
const BROWSER_VERSION_REGEX_SUFFIX = '(\\d+(\\.\\d+)?)';

@@ -109,6 +110,7 @@ const DEFAULT_BROWSER_VERSION_REGEX = new RegExp('Version/' + BROWSER_VERSION_REGEX_SUFFIX);

const safariCheck = (ua, vendor)=>vendor && (0, external_string_utils_js_namespaceObject.includes)(vendor, APPLE) || isSafari(ua);
const detectBrowser = function(user_agent, vendor, hints) {
const detectBrowser = function(user_agent, vendor, hints, options) {
vendor = vendor || '';
const fromHints = browserFromHints(hints);
if (fromHints) return fromHints;
if (options?.detectGoogleSearchApp && (0, external_string_utils_js_namespaceObject.includes)(user_agent, 'GSA/')) return GOOGLE_SEARCH_APP;
if ((0, external_string_utils_js_namespaceObject.includes)(user_agent, ' OPR/') && (0, external_string_utils_js_namespaceObject.includes)(user_agent, 'Mini')) return OPERA_MINI;

@@ -210,2 +212,5 @@ if ((0, external_string_utils_js_namespaceObject.includes)(user_agent, ' OPR/')) return OPERA;

],
[GOOGLE_SEARCH_APP]: [
new RegExp('GSA\\/' + BROWSER_VERSION_REGEX_SUFFIX)
],
[INTERNET_EXPLORER]: [

@@ -218,4 +223,4 @@ new RegExp('(rv:|MSIE )' + BROWSER_VERSION_REGEX_SUFFIX)

};
const detectBrowserVersion = function(userAgent, vendor, hints) {
const browser = detectBrowser(userAgent, vendor, hints);
const detectBrowserVersion = function(userAgent, vendor, hints, options) {
const browser = detectBrowser(userAgent, vendor, hints, options);
const regexes = versionRegexes[browser];

@@ -222,0 +227,0 @@ if ((0, external_type_utils_js_namespaceObject.isUndefined)(regexes)) return null;

@@ -49,2 +49,3 @@ import { includes } from "./string-utils.mjs";

const BRAVE = 'Brave';
const GOOGLE_SEARCH_APP = 'Google Search App';
const BROWSER_VERSION_REGEX_SUFFIX = '(\\d+(\\.\\d+)?)';

@@ -77,6 +78,7 @@ const DEFAULT_BROWSER_VERSION_REGEX = new RegExp('Version/' + BROWSER_VERSION_REGEX_SUFFIX);

const safariCheck = (ua, vendor)=>vendor && includes(vendor, APPLE) || isSafari(ua);
const detectBrowser = function(user_agent, vendor, hints) {
const detectBrowser = function(user_agent, vendor, hints, options) {
vendor = vendor || '';
const fromHints = browserFromHints(hints);
if (fromHints) return fromHints;
if (options?.detectGoogleSearchApp && includes(user_agent, 'GSA/')) return GOOGLE_SEARCH_APP;
if (includes(user_agent, ' OPR/') && includes(user_agent, 'Mini')) return OPERA_MINI;

@@ -178,2 +180,5 @@ if (includes(user_agent, ' OPR/')) return OPERA;

],
[GOOGLE_SEARCH_APP]: [
new RegExp('GSA\\/' + BROWSER_VERSION_REGEX_SUFFIX)
],
[INTERNET_EXPLORER]: [

@@ -186,4 +191,4 @@ new RegExp('(rv:|MSIE )' + BROWSER_VERSION_REGEX_SUFFIX)

};
const detectBrowserVersion = function(userAgent, vendor, hints) {
const browser = detectBrowser(userAgent, vendor, hints);
const detectBrowserVersion = function(userAgent, vendor, hints, options) {
const browser = detectBrowser(userAgent, vendor, hints, options);
const regexes = versionRegexes[browser];

@@ -190,0 +195,0 @@ if (isUndefined(regexes)) return null;

{
"name": "@posthog/core",
"version": "1.30.14",
"version": "1.31.0",
"license": "MIT",

@@ -70,3 +70,3 @@ "main": "dist/index.js",

"dependencies": {
"@posthog/types": "1.383.3"
"@posthog/types": "1.384.0"
},

@@ -73,0 +73,0 @@ "devDependencies": {

@@ -60,2 +60,3 @@ import { includes } from './string-utils'

const BRAVE = 'Brave'
const GOOGLE_SEARCH_APP = 'Google Search App'

@@ -84,2 +85,14 @@ const BROWSER_VERSION_REGEX_SUFFIX = '(\\d+(\\.\\d+)?)'

/**
* Opt-in tweaks to UA-string detection. These change how existing traffic is
* attributed, so the host SDK gates them (behind its `2026-05-30` config
* defaults) rather than enabling them unconditionally — turning one on
* reattributes browsers that were previously reported as something else.
*/
export interface BrowserDetectionOptions {
// Surface the Google Search App as its own browser via its `GSA/` UA marker
// instead of the underlying webview (Mobile Safari on iOS, Chrome on Android).
detectGoogleSearchApp?: boolean
}
const XBOX_REGEX = new RegExp(XBOX, 'i')

@@ -124,2 +137,4 @@ const PLAYSTATION_REGEX = new RegExp(PLAYSTATION + ' \\w+', 'i')

* behaviour.
*
* `options` toggles opt-in UA-detection tweaks (see `BrowserDetectionOptions`).
*/

@@ -129,3 +144,4 @@ export const detectBrowser = function (

vendor: string | undefined,
hints?: BrowserDetectionHints
hints?: BrowserDetectionHints,
options?: BrowserDetectionOptions
): string {

@@ -142,2 +158,10 @@ vendor = vendor || '' // vendor is undefined for at least IE9

// The Google Search App embeds a platform webview, so its UA otherwise looks
// like Mobile Safari (iOS) or Chrome (Android). The `GSA/` marker is present
// on every platform, so checking it first lets us attribute GSA consistently
// — it must precede the Chrome and Safari branches that would match instead.
if (options?.detectGoogleSearchApp && includes(user_agent, 'GSA/')) {
return GOOGLE_SEARCH_APP
}
if (includes(user_agent, ' OPR/') && includes(user_agent, 'Mini')) {

@@ -245,2 +269,3 @@ return OPERA_MINI

[WATERFOX]: [new RegExp(WATERFOX + '\\/' + BROWSER_VERSION_REGEX_SUFFIX)],
[GOOGLE_SEARCH_APP]: [new RegExp('GSA\\/' + BROWSER_VERSION_REGEX_SUFFIX)],
[INTERNET_EXPLORER]: [new RegExp('(rv:|MSIE )' + BROWSER_VERSION_REGEX_SUFFIX)],

@@ -261,5 +286,6 @@ Mozilla: [new RegExp('rv:' + BROWSER_VERSION_REGEX_SUFFIX)],

vendor: string | undefined,
hints?: BrowserDetectionHints
hints?: BrowserDetectionHints,
options?: BrowserDetectionOptions
): number | null {
const browser = detectBrowser(userAgent, vendor, hints)
const browser = detectBrowser(userAgent, vendor, hints, options)

@@ -266,0 +292,0 @@ // Desktop / Android Brave has no parseable UA version, so it returns null