@@ -29,7 +29,7 @@ if (/^(?:file|ftp):$/.test(location.protocol)) {
2929 ns . pendingSyncFetchPolicy = false ;
3030 ns . syncFetchPolicy = ( ) => { } ;
3131
32- let url = document . URL ;
32+ const url = document . URL ;
3333
3434 // Here we've got no CSP header yet (file: or ftp: URL), we need one
3535 // injected in the DOM as soon as possible.
@@ -77,6 +77,18 @@ if (/^(?:file|ftp):$/.test(location.protocol)) {
7777 && document . readyState !== "complete" ;
7878
7979 if ( mustFreeze ) {
80+ const normalizeDir = e => {
81+ // Chromium does this automatically. We need it to understand we're a directory earlier and allow browser UI scripts.
82+ if ( document . baseURI === `${ url } /` ) {
83+ if ( e ) {
84+ document . removeEventListener ( e . type , normalizeDir ) ;
85+ e . stopImmediatePropagation ( ) ;
86+ }
87+ window . stop ( ) ;
88+ location . replace ( document . baseURI ) ;
89+ }
90+ }
91+ normalizeDir ( ) ;
8092 // Mozilla has already parsed the <head> element, we must take extra steps...
8193 try {
8294 DocumentFreezer . freeze ( ) ;
@@ -86,17 +98,9 @@ if (/^(?:file|ftp):$/.test(location.protocol)) {
8698 debug ( "Readystate: %s, suppressedScripts = %s, canScript = %s" , document . readyState , DocumentFreezer . suppressedScripts , ns . canScript ) ;
8799
88100 if ( ! ns . canScript ) {
89- queueMicrotask ( ( ) => DocumentFreezer . unfreezeLive ( ) ) ;
90- let normalizeDir = e => {
91- // Chromium does this automatically. We need it to understand we're a directory earlier and allow browser UI scripts.
92- if ( document . baseURI === document . URL + "/" ) {
93- if ( e ) {
94- document . removeEventListener ( e . type , normalizeDir ) ;
95- e . stopImmediatePropagation ( ) ;
96- }
97- window . stop ( ) ;
98- location . replace ( document . baseURI ) ;
99- }
101+ if ( url . endsWith ( "/" ) ) {
102+ DocumentFreezer . unfreezeLive ( ) ;
103+ return ;
100104 }
101105 if ( DocumentFreezer . firedDOMContentLoaded ) {
102106 normalizeDir ( ) ;
0 commit comments