@@ -236,12 +236,38 @@ const PomodoroTimer: React.FC<PomodoroTimerProps> = ({
236236 pip . document . title = t ( "navbar.pomodoro" ) ;
237237 pip . document . documentElement . className =
238238 document . documentElement . className ;
239- document
240- . querySelectorAll ( 'style, link[rel="stylesheet"]' )
241- . forEach ( ( el ) => {
242- const clone = el . cloneNode ( true ) as HTMLElement ;
243- pip . document . head . appendChild ( clone ) ;
244- } ) ;
239+ // Copy styles using styleSheets API to handle both inline and external styles robustly
240+ // and explicitly copy all computed styles if needed, but usually stylesheet copying is enough.
241+ Array . from ( document . styleSheets ) . forEach ( ( styleSheet ) => {
242+ try {
243+ if ( styleSheet . href ) {
244+ // It's a link tag, create a new link tag explicitly to ensure href is absolute/correct
245+ const link = pip ! . document . createElement ( "link" ) ;
246+ link . rel = "stylesheet" ;
247+ link . href = styleSheet . href ;
248+ pip ! . document . head . appendChild ( link ) ;
249+ } else {
250+ // It's an inline style or loaded via JS (Vite dev mode often does this)
251+ // We try to copy the rules content.
252+ const cssRules = Array . from ( styleSheet . cssRules )
253+ . map ( ( rule ) => rule . cssText )
254+ . join ( "" ) ;
255+ const style = pip ! . document . createElement ( "style" ) ;
256+ style . textContent = cssRules ;
257+ pip ! . document . head . appendChild ( style ) ;
258+ }
259+ } catch ( e ) {
260+ // If we can't access cssRules (CORS), fallback to cloning the link if possible
261+ console . warn ( "Could not copy stylesheet rules" , e ) ;
262+ if ( styleSheet . href ) {
263+ const link = pip ! . document . createElement ( "link" ) ;
264+ link . rel = "stylesheet" ;
265+ link . type = "text/css" ;
266+ link . href = styleSheet . href ;
267+ pip ! . document . head . appendChild ( link ) ;
268+ }
269+ }
270+ } ) ;
245271 pip . document . body . style . margin = "0" ;
246272 const container = pip . document . createElement ( "div" ) ;
247273 pip . document . body . appendChild ( container ) ;
0 commit comments