@@ -180,7 +180,37 @@ func (s *FrontendServer) injectSettings(settingsJSON []byte) []byte {
180180
181181 // Inject before </head>
182182 headClose := []byte ("</head>" )
183- return bytes .Replace (s .baseHTML , headClose , append (script , headClose ... ), 1 )
183+ result := bytes .Replace (s .baseHTML , headClose , append (script , headClose ... ), 1 )
184+
185+ // Replace <title> with custom site name so the browser tab shows it immediately
186+ result = injectSiteTitle (result , settingsJSON )
187+
188+ return result
189+ }
190+
191+ // injectSiteTitle replaces the static <title> in HTML with the configured site name.
192+ // This ensures the browser tab shows the correct title before JS executes.
193+ func injectSiteTitle (html , settingsJSON []byte ) []byte {
194+ var cfg struct {
195+ SiteName string `json:"site_name"`
196+ }
197+ if err := json .Unmarshal (settingsJSON , & cfg ); err != nil || cfg .SiteName == "" {
198+ return html
199+ }
200+
201+ // Find and replace the existing <title>...</title>
202+ titleStart := bytes .Index (html , []byte ("<title>" ))
203+ titleEnd := bytes .Index (html , []byte ("</title>" ))
204+ if titleStart == - 1 || titleEnd == - 1 || titleEnd <= titleStart {
205+ return html
206+ }
207+
208+ newTitle := []byte ("<title>" + cfg .SiteName + " - AI API Gateway</title>" )
209+ var buf bytes.Buffer
210+ buf .Write (html [:titleStart ])
211+ buf .Write (newTitle )
212+ buf .Write (html [titleEnd + len ("</title>" ):])
213+ return buf .Bytes ()
184214}
185215
186216// replaceNoncePlaceholder replaces the nonce placeholder with actual nonce value
0 commit comments