SimonBrazell / privacy-redirect

A simple web extension that redirects Twitter, YouTube, Instagram & Google Maps requests to privacy friendly alternatives.
GNU General Public License v3.0
2k stars 114 forks source link

Allow disabling on specific host/don't break google maps embeds #117

Open freaktechnik opened 3 years ago

freaktechnik commented 3 years ago

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.

SimonBrazell commented 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...

SimonBrazell commented 3 years ago

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?

Screen Shot 2021-04-16 at 12 37 45

Just add the URL or a regex matching the URL you want excluded.

freaktechnik commented 3 years ago

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?

SimonBrazell commented 3 years ago

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?

SimonBrazell commented 3 years ago

disabling the redirects on a per-host basis

Is basically what the exceptions feature does.

freaktechnik commented 3 years ago

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.

SimonBrazell commented 3 years ago

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.

Screen Shot 2021-04-18 at 00 26 03
freaktechnik commented 3 years ago

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?

SimonBrazell commented 3 years ago

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.

freaktechnik commented 3 years ago

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...?

SimonBrazell commented 3 years ago

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

SimonBrazell commented 3 years ago

Or some way to work out what the lat long is for a place ID

freaktechnik commented 3 years ago

How would that work for collections/custom maps? Since those are usually multiple markers per embed.

SimonBrazell commented 3 years ago

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.