fix(GeolocateControl): include all GeolocationPositionError properties in error event
Description
Addresses: https://github.com/mapbox/mapbox-gl-js/issues/13576
Problem
In versions 3.15.0+, the GeolocateControl error event is missing code, message, PERMISSION_DENIED, POSITION_UNAVAILABLE, and TIMEOUT properties. Users only receive { target, type } instead of the full error information.
Root Cause
GeolocationPositionError is a native DOM object with non-enumerable properties. When passed directly to new Event('error', error), the Event constructor uses Object.assign() which doesn't copy non-enumerable properties.
Solution
Explicitly extract properties from GeolocationPositionError when creating the error event, matching the pattern already used for the geolocate event (fixed in commit 9a1c893f8).
Before:
this.fire(new Event('error', error));
After:
this.fire(new Event('error', {
code: error.code,
message: error.message,
PERMISSION_DENIED: error.PERMISSION_DENIED,
POSITION_UNAVAILABLE: error.POSITION_UNAVAILABLE,
TIMEOUT: error.TIMEOUT
} as GeolocationPositionError));
Here is a screenshot where I tested it in Firefox
Launch Checklist
- [x] Make sure the PR title is descriptive and preferably reflects the change from the user's perspective.
- [x] Add additional detail and context in the PR description (with screenshots/videos if there are visual changes).
- [x] Manually test the debug page.
- [x] Write tests for all new functionality and make sure the CI checks pass.
- [ ] Document any changes to public APIs. (N/A - this restores existing documented behavior)
- [ ] Post benchmark scores if the change could affect performance. (N/A - no performance impact)
- [ ] Tag
@mapbox/map-design-team@mapbox/static-apisif this PR includes style spec API or visual changes. (N/A) - [ ] Tag
@mapbox/gl-nativeif this PR includes shader changes or needs a native port. (N/A) - [ ] Tag
@mapbox/gl-nativeif this PR disables any test because it also needs to be disabled on their side. (N/A) - [ ] Create a ticket for
gl-nativeto groom in the MAPSNAT JIRA queue if this PR includes shader changes or features not present in the native side or if it disables a test that's not disabled there. (N/A)