0

I'm trying a relatively simple thing. I have the following link.

<a href={`https://www.google.com/search?q=rotten+tomatoes+${movie.title}+${movie.year}+review&btnI=`}>

Which leads me to a Google Redirect. The page this link lands on has a simple url:

https://www.google.com/url?q={THE_URL_I_WANT}

I'm trying to find a way to get the above url as a response to my click, after which I would be able to remove the "https://www.google.com/url?q=" part and then link to the actual URL I need.

Is this possible?

PS.
I've searched quite a bit but it appears to be very hard to bypass the redirect. Now I know there's stuff you can try with a service worker, or trying add headers with cors or even fake the request from a proxy but so far I have not managed and a lot of posts I find are either deprecated or a bit too complicated for something I hope can be done very simply.

EDIT
As per the last post on this solution, it was just a matter of allowing CORS for my localhost in Chrome.

daritimm
  • 65
  • 12

1 Answers1

0

this is fairly easy to accomplish. If you make a fetch to it, you can use the response.

fetch('https://www.google.com/search?q=rotten+tomatoe]s+${movie.title}+${movie.year}+review&btnI=')
.then(resp => {
   // resp = Response {type: "basic", url: "https://www.google.com/url?q=https://en.wikipedia.org/wiki/Rotten_Tomatoes", redirected: true, status: 200, ok: true, …}

})
  • I tried this but get a CORS error instead. I've tried a lot of things to get Access but at the moment only the cors-anywhere seems to work as a solution. Only problem is that the response object holds the search url (https://cors-anywhere.herokuapp.com/https://www.google.com/search?....) and not the redirect url. – daritimm Dec 09 '20 at 09:13
  • Nvm it was just because I was making the request from my localhost. Simply enabling the CORS extension for Chrome solved that problem, as per the last answer here: https://stackoverflow.com/questions/38542306/sending-a-details-request-to-google-places-api-cors-error – daritimm Dec 09 '20 at 09:50