@@ -21,35 +21,34 @@ function createFrameId() {
2121 . join ( "" ) } `;
2222}
2323
24- dbg . log ( "initializing scramjet client" ) ;
25- // if it already exists, that means the handlers have probably already been setup by the parent document
26- if ( ! ( SCRAMJETCLIENT in < Partial < typeof self > > self ) ) {
27- loadCodecs ( ) ;
28-
29- const client = new ScramjetClient ( self ) ;
30- const frame : HTMLIFrameElement = self . frameElement as HTMLIFrameElement ;
31- if ( frame && ! frame . name ) {
32- // all frames need to be named for our logic to work
33- frame . name = createFrameId ( ) ;
24+ export function clientInitHook ( ) {
25+ dbg . log ( "initializing scramjet client" ) ;
26+ // if it already exists, that means the handlers have probably already been setup by the parent document
27+ if ( ! ( SCRAMJETCLIENT in < Partial < typeof self > > self ) ) {
28+ loadCodecs ( ) ;
29+
30+ const client = new ScramjetClient ( self ) ;
31+ const frame : HTMLIFrameElement = self . frameElement as HTMLIFrameElement ;
32+ if ( frame && ! frame . name ) {
33+ // all frames need to be named for our logic to work
34+ frame . name = createFrameId ( ) ;
35+ }
36+
37+ if ( self . COOKIE ) client . loadcookies ( self . COOKIE ) ;
38+
39+ client . hook ( ) ;
40+
41+ if ( isemulatedsw ) {
42+ const runtime = new ScramjetServiceWorkerRuntime ( client ) ;
43+ runtime . hook ( ) ;
44+ }
45+
46+ const contextev = new ScramjetContextEvent ( client . global . window , client ) ;
47+ client . frame ?. dispatchEvent ( contextev ) ;
48+ const urlchangeev = new UrlChangeEvent ( client . url . href ) ;
49+ if ( ! client . isSubframe ) client . frame ?. dispatchEvent ( urlchangeev ) ;
3450 }
3551
36- if ( self . COOKIE ) client . loadcookies ( self . COOKIE ) ;
37-
38- client . hook ( ) ;
39-
40- if ( isemulatedsw ) {
41- const runtime = new ScramjetServiceWorkerRuntime ( client ) ;
42- runtime . hook ( ) ;
43- }
44-
45- const contextev = new ScramjetContextEvent ( client . global . window , client ) ;
46- client . frame ?. dispatchEvent ( contextev ) ;
47- const urlchangeev = new UrlChangeEvent ( client . url . href ) ;
48- if ( ! client . isSubframe ) client . frame ?. dispatchEvent ( urlchangeev ) ;
49- }
50-
51- Reflect . deleteProperty ( self , "WASM" ) ;
52- Reflect . deleteProperty ( self , "COOKIE" ) ;
53- if ( "document" in self && document ?. currentScript ) {
54- document . currentScript . remove ( ) ;
52+ Reflect . deleteProperty ( self , "WASM" ) ;
53+ Reflect . deleteProperty ( self , "COOKIE" ) ;
5554}
0 commit comments