Add debug logging for OO_STATE keys and title tag fallback

- Log all top-level keys in __OO_STATE__ to diagnose why Restaurant
  key isn't being found
- Extract business name from HTML title tag as fallback

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
John Mizerek 2026-02-13 09:19:32 -08:00
parent 5c49054e78
commit e8dfd0ba7d

View file

@ -172,6 +172,21 @@
</cfloop>
</cfif>
<!--- Try to extract business name from title tag --->
<cfset titleMatch = reMatchNoCase('<title>([^<]+)</title>', pageHtml)>
<cfif arrayLen(titleMatch)>
<cfset titleText = reReplaceNoCase(titleMatch[1], '.*<title>([^<]+)</title>.*', '\1')>
<cfset titleText = trim(titleText)>
<!--- Toast titles are usually "Restaurant Name | Online Ordering" --->
<cfif findNoCase("|", titleText)>
<cfset titleText = trim(listFirst(titleText, "|"))>
</cfif>
<cfif len(titleText) AND NOT structKeyExists(toastBusiness, "name")>
<cfset toastBusiness["name"] = titleText>
<cfset arrayAppend(response.steps, "Extracted business name from title: " & titleText)>
</cfif>
</cfif>
<!--- Also try to extract from __OO_STATE__ for images and business info --->
<cfif findNoCase("window.__OO_STATE__", pageHtml)>
<cfset ooStateMatch = reMatchNoCase("window\.__OO_STATE__\s*=\s*(\{.*?\});\s*window\.", pageHtml)>
@ -180,6 +195,9 @@
<cfset ooStateJson = reReplace(ooStateJson, ";\s*window\.$", "")>
<cftry>
<cfset ooState = deserializeJSON(ooStateJson)>
<!--- Debug: log all top-level keys in OO_STATE --->
<cfset ooStateKeys = structKeyList(ooState)>
<cfset arrayAppend(response.steps, "OO_STATE keys: " & left(ooStateKeys, 500))>
<!--- Build name -> image URL map from OO_STATE --->
<cfset imageMap = structNew()>
<cfloop collection="#ooState#" item="key">