Skip to content

Only trigger geolocation permission prompt on explicit "my location" click - #30

Merged
mmathieum merged 2 commits into
masterfrom
copilot/fix-index-html-location-permission
Sep 1, 2026
Merged

Only trigger geolocation permission prompt on explicit "my location" click#30
mmathieum merged 2 commits into
masterfrom
copilot/fix-index-html-location-permission

Conversation

Copilot AI commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

On index.html, loading the map page auto-triggered Chrome mobile's location permission dialog, even though the user hadn't interacted with the "my location" button.

Root cause

  • centerMapOnDeviceLocation() ran on page load and called centerMapOnDeviceLocationNavigator(), which invoked navigator.geolocation.getCurrentPosition() unconditionally.
  • The existing navigator.permissions.query() check only short-circuited for the denied state; the default prompt state still fell through to getCurrentPosition(), surfacing the native permission dialog on every load.

Fix

  • centerMapOnDeviceLocation() now checks the Permissions API result before deciding how to center the map on load:
    • granted → use navigator.geolocation directly (no dialog, since permission is already resolved).
    • anything else (prompt, denied, or Permissions API unsupported) → skip getCurrentPosition() entirely and fall back to IP-based geolocation (ipwho.is), silently, with no dialog.
  • The "my location" button handler (requestDeviceLocation) is unchanged — clicking it still explicitly calls getCurrentPosition() and can prompt for permission, as intended.
function centerMapOnDeviceLocation(map) {
	if (navigator.geolocation && navigator.permissions && navigator.permissions.query) {
		navigator.permissions.query({ name: 'geolocation' })
			.then(function (permissionStatus) {
				if (permissionStatus && permissionStatus.state === 'granted') {
					return centerMapOnDeviceLocationNavigator(map);
				}
				return centerMapOnDeviceLocationIpwhois(map);
			})
			.catch(function () { return centerMapOnDeviceLocationIpwhois(map); })
			.catch(function () { setDefaultMapCenter(map); });
		return;
	}
	centerMapOnDeviceLocationIpwhois(map).catch(function () { setDefaultMapCenter(map); });
}

Co-authored-by: mmathieum <177998+mmathieum@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix location permission dialog in Chrome mobile Only trigger geolocation permission prompt on explicit "my location" click Sep 1, 2026
Copilot AI requested a review from mmathieum September 1, 2026 13:17
@mmathieum
mmathieum marked this pull request as ready for review September 1, 2026 13:20
@mmathieum
mmathieum requested a lite review from Copilot September 1, 2026 13:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prevents the browser’s geolocation permission prompt from appearing automatically on index.html page load by only using navigator.geolocation when permission is already granted, and otherwise falling back to IP-based centering.

Changes:

  • Update centerMapOnDeviceLocation(map) to query the Permissions API and only call getCurrentPosition() when the geolocation permission state is granted.
  • For prompt / denied / Permissions API unsupported cases, skip navigator.geolocation entirely on load and fall back to ipwho.is, with a default-center fallback on failure.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@mmathieum
mmathieum merged commit 29a488c into master Sep 1, 2026
1 check passed
@mmathieum
mmathieum deleted the copilot/fix-index-html-location-permission branch September 1, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix /index.html still request 🛰️ location permission & show dialog 🗯️ in Chrome mobile

3 participants