@@ -12,7 +12,7 @@ export class History {
1212
1313 constructor ( private tab : Tab ) { }
1414
15- push ( url : URL , state : any , navigate : boolean = true ) : HistoryState {
15+ push ( url : URL , state : any = null , navigate : boolean = true ) : HistoryState {
1616 this . states . push ( { url, state } ) ;
1717 this . index ++ ;
1818
@@ -60,8 +60,9 @@ export class History {
6060 }
6161}
6262
63- export function injectHistoryEmulation ( frame : ScramjetFrame , tab : Tab ) {
63+ export function addHistoryListeners ( frame : ScramjetFrame , tab : Tab ) {
6464 frame . addEventListener ( "navigate" , ( e ) => {
65+ console . log ( "History push from navigate" , e , tab . history . states ) ;
6566 // this event is fired whenever location.href is set, or similar
6667 // importantly not fired when replaceState is called (we overwrite it ourselves in injectContext)
6768
@@ -71,12 +72,14 @@ export function injectHistoryEmulation(frame: ScramjetFrame, tab: Tab) {
7172
7273 console . log ( "History push from navigate" , url , tab . history . states ) ;
7374 } ) ;
74- frame . frame . addEventListener ( "beforeunload" , ( e : BeforeUnloadEvent ) => {
75+ }
76+
77+ export function injectHistoryEmulation ( client : ScramjetClient , tab : Tab ) {
78+ // this is extremely problematic in terms of security but whatever
79+ client . global . addEventListener ( "beforeunload" , ( e : BeforeUnloadEvent ) => {
7580 console . log ( "History beforeunload" , e ) ;
7681 } ) ;
77- }
7882
79- function injectContext ( client : ScramjetClient , tab : Tab ) {
8083 client . Proxy ( "History.prototype.pushState" , {
8184 apply ( ctx ) {
8285 console . log ( "STATE PUSH" , ctx . args ) ;
0 commit comments