33import { motion } from "framer-motion" ;
44import { useState , useEffect } from "react" ;
55import { AnimatedBackground } from "./AmbientLightBg" ;
6+ import { GradientTechBackground } from "./GradientTechBackground" ;
7+ import { isWebGLSupported } from "@/utils/webglDetect" ;
68
79export function ChromeBrowserBackground ( ) {
810 const [ backgroundReady , setBackgroundReady ] = useState ( false ) ;
11+ const [ webglSupported , setWebglSupported ] = useState < boolean | null > ( null ) ;
12+ const [ useFallback , setUseFallback ] = useState ( false ) ;
13+
14+ // Detect WebGL support on mount
15+ useEffect ( ( ) => {
16+ const supported = isWebGLSupported ( ) ;
17+ setWebglSupported ( supported ) ;
18+
19+ if ( ! supported ) {
20+ console . warn ( 'WebGL not supported, using fallback gradient background' ) ;
21+ setUseFallback ( true ) ;
22+ setBackgroundReady ( true ) ;
23+ }
24+ } , [ ] ) ;
925
1026 // Listen for background animation ready state
1127 useEffect ( ( ) => {
1228 const handleBackgroundReady = ( ) => {
1329 setBackgroundReady ( true ) ;
1430 } ;
1531
32+ const handleBackgroundError = ( event : Event ) => {
33+ const customEvent = event as CustomEvent ;
34+ console . error ( 'AnimatedBackground failed, falling back to gradient:' , customEvent . detail ?. error ) ;
35+ setUseFallback ( true ) ;
36+ setBackgroundReady ( true ) ;
37+ } ;
38+
1639 // Listen for ambient background loaded event
1740 window . addEventListener ( "ambientBgLoaded" , handleBackgroundReady ) ;
41+ window . addEventListener ( "ambientBgError" , handleBackgroundError ) ;
1842
1943 return ( ) => {
2044 window . removeEventListener ( "ambientBgLoaded" , handleBackgroundReady ) ;
45+ window . removeEventListener ( "ambientBgError" , handleBackgroundError ) ;
2146 } ;
2247 } , [ ] ) ;
2348
@@ -26,34 +51,49 @@ export function ChromeBrowserBackground() {
2651 { /* Black background - always visible as fallback */ }
2752 < div className = "fixed inset-0 bg-black z-0" />
2853
29- { /* AnimatedBackground with loading-based opacity control */ }
30- < motion . div
31- className = "fixed inset-0 z-0 overflow-hidden"
32- initial = { { opacity : 0 } }
33- animate = { { opacity : backgroundReady ? 1 : 0 } }
34- transition = { { duration : 0.8 , ease : "easeInOut" } }
35- style = { {
36- opacity : backgroundReady ? 1 : 0 ,
37- } }
38- >
39- { /* Animated background - render at desktop size for mobile consistency */ }
40- < div
41- className = "absolute"
54+ { /* Render background based on WebGL support and fallback state */ }
55+ { useFallback ? (
56+ /* Fallback: Gradient Tech Background (no WebGL required) */
57+ < motion . div
58+ className = "fixed inset-0 z-0 overflow-hidden"
59+ initial = { { opacity : 0 } }
60+ animate = { { opacity : 1 } }
61+ transition = { { duration : 0.8 , ease : "easeInOut" } }
62+ >
63+ < GradientTechBackground />
64+ { /* Black overlay with 40% opacity */ }
65+ < div className = "absolute inset-0 bg-black/40" />
66+ </ motion . div >
67+ ) : webglSupported !== false ? (
68+ /* WebGL supported: AnimatedBackground with loading-based opacity control */
69+ < motion . div
70+ className = "fixed inset-0 z-0 overflow-hidden"
71+ initial = { { opacity : 0 } }
72+ animate = { { opacity : backgroundReady ? 1 : 0 } }
73+ transition = { { duration : 0.8 , ease : "easeInOut" } }
4274 style = { {
43- width : "100vw" ,
44- height : "100vh" ,
45- minWidth : "1440px" , // Desktop width for consistent appearance
46- minHeight : "900px" , // Desktop height for consistent appearance
47- left : "50%" ,
48- top : "50%" ,
49- transform : "translate(-50%, -50%)"
75+ opacity : backgroundReady ? 1 : 0 ,
5076 } }
5177 >
52- < AnimatedBackground speed = { 0.25 } />
53- </ div >
54- { /* Black overlay with 40% opacity */ }
55- < div className = "absolute inset-0 bg-black/40" />
56- </ motion . div >
78+ { /* Animated background - render at desktop size for mobile consistency */ }
79+ < div
80+ className = "absolute"
81+ style = { {
82+ width : "100vw" ,
83+ height : "100vh" ,
84+ minWidth : "1440px" , // Desktop width for consistent appearance
85+ minHeight : "900px" , // Desktop height for consistent appearance
86+ left : "50%" ,
87+ top : "50%" ,
88+ transform : "translate(-50%, -50%)"
89+ } }
90+ >
91+ < AnimatedBackground speed = { 0.25 } />
92+ </ div >
93+ { /* Black overlay with 40% opacity */ }
94+ < div className = "absolute inset-0 bg-black/40" />
95+ </ motion . div >
96+ ) : null }
5797 </ >
5898 ) ;
5999}
0 commit comments