Open freaktechnik opened 3 years ago
Hi @freaktechnik good suggestion, I like the workaround, I really should fix up some of the issues with the maps redirects though, or at the very least turn them off by default and mark them as experimental or something...
Sorry just going through all the open issues again now I've got a bit of time, isn't this already possible using the "Exceptions" tab in options?
Just add the URL or a regex matching the URL you want excluded.
Honestly that's a lot of work to get to, I'd think if this is only worked around at least having a quick way to add a rule from the poup would be great
The wording also doesnt make me think it'd work with embeds easily?
Hmm yeah I get your point, would be a bit of work to add exceptions if you encounter this a lot, it should work for embeds though, probably not explained very well, do you have some examples I could use for testing?
disabling the redirects on a per-host basis
Is basically what the exceptions feature does.
One I've recently come across is https://www.frisches.ch/freunde . I guess the solution would be to put https://www.google.com/maps/d/embed
on the exceptions list.
For that site you could add https:\/\/www.frisches.ch\/*
as a regex exception to stop the OSM redirects on it, not very practical if you encounter this a lot though.
It seems making an exception for the embed works though? Since I assume it also checks the rules for the URL of the frame subrequest?
The exceptions check the initiator of the request against those in the exceptions list, so you'd have to add an exception for every site you encounter this on...
OSM embed redirects only work in very specific circumstances, which I don't think are actually that common in the wild. There has to be either a latitude and longitude value, or a search query string in the URL somewhere for them to work currently. When there is just a Google place ID it doesn't work, there is no way for me to translate this into lat long values without sending a request to Google that I know of, I think this is the case with https://www.frisches.ch/freunde
.
But I have OSM redirects enabled and only have an exception for the embed URL and it's not redirecting it to the OSM embed now...?
My mistake, it looks like it checks for a match on both the initiator and and url itself:
function isException(url, initiator) {
return (
exceptions.some((regex) => regex.test(url.href)) ||
(initiator && exceptions.some((regex) => regex.test(initiator.href)))
);
}
So yeah adding the embed URL as an exception will work. I think a proper fix for this would be to add a permanent exception / bypass for maps URLs that contain a place ID, which I think is the mid
in:
https://www.google.com/maps/d/embed?mid=1jUMnLui0pdMBWILmblnrPM_kyOtTUGXK
Or some way to work out what the lat long is for a place ID
How would that work for collections/custom maps? Since those are usually multiple markers per embed.
The whole Google maps redirects function is all pretty messy, I had to reverse engineer all the different iterations of maps URLs I came across, there were quite a few variations, embeds in particular were trouble, I recall at the time I did it I even had trouble finding a few examples of sites with embedded maps to test 🙂
This is the maps embed part of redirectGoogleMaps()
, it looks like it doesn't handle multiple markers at the moment.
// Handle Google Maps Embed API
if (url.pathname.split("/").includes("embed")) {
let query = "";
if (url.searchParams.has("q")) {
query = url.searchParams.get("q");
} else if (url.searchParams.has("query")) {
query = url.searchParams.has("query");
} else if (url.searchParams.has("pb")) {
try {
query = url.searchParams.get("pb").split(/!2s(.*?)!/)[1];
} catch (error) {
console.error(error);
// Unable to find map marker in URL.
}
}
let marker, bbox;
mapsHelper.addressToLatLng(query, (coords, boundingbox) => {
marker = coords;
bbox = boundingbox;
});
redirect = `${osmInstance}/export/embed.html?bbox=${bbox}&layer=mapnik&marker=${marker}`;
// Handle Google Maps Directions
}
EDIT - sorry copied the wrong bit.
The current open street map redirect breaks google map embeds. There's two solutions, thus the extremely long title. One would be to solve the embeds being broken issue. But a potentially more generic and working around other issues too solution would be to allow disabling the redirects on a per-host basis, similar to how you can disable tracking protection or an ad blocker for a specific website.