Question:
How to create a workaround for geolocation in Chromium 126 and later based browsers?
Product:
wixWindow.getCurrentGeolocation() fails with the following error in browsers based on Chromium 126 or later like Chrome, Edge, Opera, etc.:
comlink.ts:343 Uncaught (in promise) DOMException: Failed to execute ‘postMessage’ on ‘MessagePort’: function toJSON() { [native code] } could not be cloned.
at https://static.parastorage.com/services/wix-thunderbolt/dist/thunderbolt-commons.14431d95.bundle.min.js:1:18777
What are you trying to achieve:
The getCurrentGeolocation() uses the browser’s native geolocation capability to return user’s location coordinates. But the (Chrome Platform Status) change in Chromium 126 breaks the wix-thunderbolt library. It has been 2 weeks since Wix sites are unable to get geolocation but no fix is available from the Velo team.
What have you already tried:
Since Wix sites do not allow permissions policy for allowing geolocation on iframes, it is not possible to implement a native JS geolocation finding without using wixWindow. And wixWindow / wix-thunderbolt library is broken. So need another workaround.
Additional information:
Very easy to reproduce the issue with this code:
import wixWindow from ‘wix-window’;
async function getLocation() {
return await wixWindow.getCurrentGeolocation()
.then( (obj) => {
let locationLatitude = obj.coords.latitude;
let locationLongitude = obj.coords.longitude;
console.log('locationLatitude ' + locationLatitude)
console.log('locationLongitude ' + locationLongitude)
} )
.catch( (error) => {
console.log('error ' + error.message)
});
}
$w.onReady(function () {
getLocation()
});