From 952667e85481b6dcfa4ae8ab70788cb523972bf0 Mon Sep 17 00:00:00 2001 From: Nick Patrick Date: Fri, 17 Oct 2025 09:57:48 -0400 Subject: [PATCH 1/5] freeze copy of navigator.geolocation --- README.md | 14 +++++++------- package-lock.json | 2 +- package.json | 2 +- src/navigator.ts | 18 ++++++++++++++++-- src/version.ts | 2 +- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 20542cc7..b40ac54f 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Radar.initialize('prj_test_pk_...', { /* options */ }); Add the following script in your `html` file ```html - + ``` Then initialize the Radar SDK @@ -73,8 +73,8 @@ To create a map, first initialize the Radar SDK with your publishable key. Then ```html - - + + @@ -98,8 +98,8 @@ To create an autocomplete input, first initialize the Radar SDK with your publis ```html - - + + @@ -130,8 +130,8 @@ To power [geofencing](https://radar.com/documentation/geofencing/overview) exper ```html - - + + diff --git a/package-lock.json b/package-lock.json index 51beccb4..820f9778 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "radar-sdk-js", - "version": "4.5.7", + "version": "4.5.8-beta.1", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/package.json b/package.json index fedb3cad..85bf96c5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "radar-sdk-js", - "version": "4.5.7", + "version": "4.5.8-beta.1", "description": "Web Javascript SDK for Radar, location infrastructure for mobile and web apps.", "homepage": "https://radar.com", "type": "module", diff --git a/src/navigator.ts b/src/navigator.ts index 71cc07ad..0456dd19 100644 --- a/src/navigator.ts +++ b/src/navigator.ts @@ -5,6 +5,20 @@ import { RadarLocationError, RadarPermissionsError } from './errors'; import type { LocationAuthorization, NavigatorPosition } from './types'; +const radarGeolocation = (() => { + const g = navigator.geolocation; + + if (!g) { + return null; + } + + return Object.freeze({ + getCurrentPosition: g.getCurrentPosition.bind(g), + watchPosition: g.watchPosition.bind(g), + clearWatch: g.clearWatch.bind(g) + }); +})(); + interface PositionOptionOverrides { desiredAccuracy?: string; } @@ -25,7 +39,7 @@ class Navigator { return new Promise((resolve, reject) => { const options = Config.get(); - if (!navigator || !navigator.geolocation) { + if (!radarGeolocation) { return reject(new RadarLocationError('navigator.geolocation is not available.')); } @@ -67,7 +81,7 @@ class Navigator { Logger.info(`Using geolocation options: ${JSON.stringify(positionOptions)}`); // get current location from browser - navigator.geolocation.getCurrentPosition( + radarGeolocation.getCurrentPosition( (position) => { if (!position || !position.coords) { return reject(new RadarLocationError('device location return empty coordinates.')); diff --git a/src/version.ts b/src/version.ts index 23653cbb..09c955f9 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export default '4.5.7'; +export default '4.5.8-beta.1'; From 677e33fc16a7349c4ff85ec5814e9839dbf3631f Mon Sep 17 00:00:00 2001 From: Nick Patrick Date: Fri, 17 Oct 2025 10:00:56 -0400 Subject: [PATCH 2/5] handle navigator undefined --- src/navigator.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/navigator.ts b/src/navigator.ts index 0456dd19..df802fa9 100644 --- a/src/navigator.ts +++ b/src/navigator.ts @@ -6,12 +6,16 @@ import { RadarLocationError, RadarPermissionsError } from './errors'; import type { LocationAuthorization, NavigatorPosition } from './types'; const radarGeolocation = (() => { + if (!navigator) { + return null; + } + const g = navigator.geolocation; if (!g) { return null; } - + return Object.freeze({ getCurrentPosition: g.getCurrentPosition.bind(g), watchPosition: g.watchPosition.bind(g), From 7b14b5e236ad8d18c7a41ceaa9626188f17b82a6 Mon Sep 17 00:00:00 2001 From: Nick Patrick Date: Fri, 17 Oct 2025 10:54:19 -0400 Subject: [PATCH 3/5] fix tests --- src/navigator.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/navigator.ts b/src/navigator.ts index df802fa9..fb0850e5 100644 --- a/src/navigator.ts +++ b/src/navigator.ts @@ -16,10 +16,12 @@ const radarGeolocation = (() => { return null; } + const emptyFn = () => {}; + return Object.freeze({ - getCurrentPosition: g.getCurrentPosition.bind(g), - watchPosition: g.watchPosition.bind(g), - clearWatch: g.clearWatch.bind(g) + getCurrentPosition: g.getCurrentPosition ? g.getCurrentPosition.bind(g) : emptyFn, + watchPosition: g.watchPosition ? g.watchPosition.bind(g) : emptyFn, + clearWatch: g.clearWatch ? g.clearWatch.bind(g) : emptyFn, }); })(); From f143fe27c90b2469b8020df07d6541c7ffaed3ac Mon Sep 17 00:00:00 2001 From: Nick Patrick Date: Fri, 17 Oct 2025 12:18:42 -0400 Subject: [PATCH 4/5] fix tests --- src/api/track.ts | 2 +- src/navigator.ts | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/api/track.ts b/src/api/track.ts index edf47233..12a97aa9 100644 --- a/src/api/track.ts +++ b/src/api/track.ts @@ -25,7 +25,7 @@ class TrackAPI { // if latitude & longitude are not provided, // try and retrieve device location (will prompt for location permissions) if (!latitude || !longitude) { - const deviceLocation = await Navigator.getCurrentPosition({ desiredAccuracy }); + const deviceLocation = await Navigator.getCurrentPosition({ desiredAccuracy }, fraud); latitude = deviceLocation.latitude; longitude = deviceLocation.longitude; accuracy = deviceLocation.accuracy; diff --git a/src/navigator.ts b/src/navigator.ts index fb0850e5..b7d8754e 100644 --- a/src/navigator.ts +++ b/src/navigator.ts @@ -41,11 +41,13 @@ const useHighAccuracy = (desiredAccuracy?: string) => ( ); class Navigator { - public static async getCurrentPosition(overrides: PositionOptionOverrides = {}): Promise { + public static async getCurrentPosition(overrides: PositionOptionOverrides = {}, fraud: Boolean = false): Promise { return new Promise((resolve, reject) => { const options = Config.get(); - if (!radarGeolocation) { + const g = fraud ? radarGeolocation : navigator.geolocation; + + if (!g) { return reject(new RadarLocationError('navigator.geolocation is not available.')); } @@ -87,7 +89,7 @@ class Navigator { Logger.info(`Using geolocation options: ${JSON.stringify(positionOptions)}`); // get current location from browser - radarGeolocation.getCurrentPosition( + g.getCurrentPosition( (position) => { if (!position || !position.coords) { return reject(new RadarLocationError('device location return empty coordinates.')); From 4604042c9577a815e70146dcb58e19c3997122e4 Mon Sep 17 00:00:00 2001 From: Nick Patrick Date: Fri, 17 Oct 2025 12:28:29 -0400 Subject: [PATCH 5/5] bump version --- README.md | 14 +++++++------- package-lock.json | 2 +- package.json | 2 +- src/version.ts | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b40ac54f..4fa5079d 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Radar.initialize('prj_test_pk_...', { /* options */ }); Add the following script in your `html` file ```html - + ``` Then initialize the Radar SDK @@ -73,8 +73,8 @@ To create a map, first initialize the Radar SDK with your publishable key. Then ```html - - + + @@ -98,8 +98,8 @@ To create an autocomplete input, first initialize the Radar SDK with your publis ```html - - + + @@ -130,8 +130,8 @@ To power [geofencing](https://radar.com/documentation/geofencing/overview) exper ```html - - + + diff --git a/package-lock.json b/package-lock.json index 820f9778..6f53cde5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "radar-sdk-js", - "version": "4.5.8-beta.1", + "version": "4.5.8-beta.0", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/package.json b/package.json index 85bf96c5..5f98f997 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "radar-sdk-js", - "version": "4.5.8-beta.1", + "version": "4.5.8-beta.0", "description": "Web Javascript SDK for Radar, location infrastructure for mobile and web apps.", "homepage": "https://radar.com", "type": "module", diff --git a/src/version.ts b/src/version.ts index 09c955f9..14c87d53 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export default '4.5.8-beta.1'; +export default '4.5.8-beta.0';