@@ -295,6 +295,7 @@ async function expandShortMapUrlWithResponse(
295295async function fetchMapPageText (
296296 url : string ,
297297 options : ExpandShortMapUrlOptions = { } ,
298+ maxConsentRedirects = 2 ,
298299) : Promise < string | null > {
299300 const parsed = parseUrl ( url ) ;
300301 if ( ! parsed || ! isSupportedMapHost ( parsed ) ) return null ;
@@ -319,7 +320,23 @@ async function fetchMapPageText(
319320 ) ;
320321
321322 if ( typeof response . text !== "function" ) return null ;
322- return await withTimeout ( Promise . resolve ( response . text ( ) ) , timeoutMs ) ;
323+ const responseText = await withTimeout ( Promise . resolve ( response . text ( ) ) , timeoutMs ) ;
324+
325+ // Check if we got redirected to a consent page
326+ const responseUrl = typeof response . url === "string" ? parseUrl ( response . url ) : null ;
327+ if ( responseUrl && isGoogleConsentHost ( responseUrl . hostname ) && maxConsentRedirects > 0 ) {
328+ console . info ( "[share.debug] fetch_hit_consent_page" , { url, responseUrl : response . url } ) ;
329+ // Extract the real Maps URL from the consent page
330+ const extractedUrl =
331+ typeof response . url === "string" ? extractUrlFromGoogleConsent ( response . url ) : null ;
332+ if ( extractedUrl ) {
333+ console . info ( "[share.debug] fetch_extracted_from_consent" , extractedUrl ) ;
334+ // Recursively fetch the extracted URL, but limit redirects to prevent infinite loops
335+ return await fetchMapPageText ( extractedUrl , options , maxConsentRedirects - 1 ) ;
336+ }
337+ }
338+
339+ return responseText ;
323340 } catch {
324341 return null ;
325342 }
0 commit comments