@@ -260,24 +260,54 @@ function rewriteAssetUrls(html, hash, currentPath) {
260260 const baseTag = document . createElement ( 'base' ) ;
261261 baseTag . href = basePath ? `${ baseUrl } ${ basePath } /` : baseUrl ;
262262 doc . head . prepend ( baseTag ) ;
263+
264+ // Remove problematic scripts that shouldn't be loaded in time travel mode
265+ const scriptsToRemove = [
266+ 'timeline.js' ,
267+ 'sw.js' ,
268+ 'chatbot.js' ,
269+ 'gc.zgo.at/count.js'
270+ ] ;
271+
272+ // Remove script tags with matching src attributes
273+ doc . querySelectorAll ( 'script' ) . forEach ( script => {
274+ const src = script . getAttribute ( 'src' ) ;
275+ if ( src && scriptsToRemove . some ( badScript => src . includes ( badScript ) ) ) {
276+ script . remove ( ) ;
277+ }
278+ } ) ;
279+
280+ // Also remove inline scripts related to service worker registration
281+ doc . querySelectorAll ( 'script:not([src])' ) . forEach ( script => {
282+ if ( script . textContent . includes ( 'serviceWorker.register' ) ||
283+ script . textContent . includes ( 'goatcounter' ) ) {
284+ script . remove ( ) ;
285+ }
286+ } ) ;
287+
288+ // Continue with the existing URL rewriting logic
263289 doc . querySelectorAll ( 'link[rel="stylesheet"]' ) . forEach ( link => {
264290 const href = link . getAttribute ( 'href' ) ;
265291 if ( href && ! href . startsWith ( 'http' ) && ! href . startsWith ( '//' ) ) {
266292 link . setAttribute ( 'href' , new URL ( href , baseUrl ) . href ) ;
267293 }
268294 } ) ;
295+
269296 doc . querySelectorAll ( 'img' ) . forEach ( img => {
270297 const src = img . getAttribute ( 'src' ) ;
271298 if ( src && ! src . startsWith ( 'http' ) && ! src . startsWith ( '//' ) ) {
272299 img . setAttribute ( 'src' , new URL ( src , baseUrl ) . href ) ;
273300 }
274301 } ) ;
302+
303+ // Only rewrite URLs for scripts we're keeping
275304 doc . querySelectorAll ( 'script' ) . forEach ( script => {
276305 const src = script . getAttribute ( 'src' ) ;
277306 if ( src && ! src . startsWith ( 'http' ) && ! src . startsWith ( '//' ) ) {
278307 script . setAttribute ( 'src' , new URL ( src , baseUrl ) . href ) ;
279308 }
280309 } ) ;
310+
281311 return new XMLSerializer ( ) . serializeToString ( doc ) ;
282312}
283313
0 commit comments