@@ -69,15 +69,52 @@ export class Browser extends StatefulClass {
6969 frame . frame . addEventListener ( "load" , ( e ) => {
7070 tab . url = frame . client . url . href ;
7171 } ) ;
72- frame . addEventListener ( "contextInit" , ( e ) => {
73- const framedoc = frame . frame . contentDocument ! ;
72+ frame . addEventListener ( "contextInit" , ( ctx ) => {
73+ const framedoc = ctx . window . document ;
7474
7575 framedoc . addEventListener ( "contextmenu" , ( e ) => {
76- createMenu ( e . x , e . y , [
76+ // need to calculate the real position of the frame relative to the top
77+ let xoff = 0 ;
78+ let yoff = 0 ;
79+ let currentwin = ctx . window ;
80+ while ( currentwin . parent && currentwin . frameElement ) {
81+ // this will return true until the end of the scramjet boundary
82+ let { x, y } = currentwin . frameElement . getBoundingClientRect ( ) ;
83+ xoff += x ;
84+ yoff += y ;
85+ currentwin = currentwin . parent ;
86+ }
87+ // parent is trapped, so it won't calculate the topmost iframe. do that manually
88+ let { x, y } = frame . frame . getBoundingClientRect ( ) ;
89+ xoff += x ;
90+ yoff += y ;
91+ createMenu ( xoff + e . pageX , yoff + e . pageY , [
92+ {
93+ label : "Back" ,
94+ action : ( ) => {
95+ frame . back ( ) ;
96+ } ,
97+ } ,
98+ {
99+ label : "Forward" ,
100+ action : ( ) => {
101+ frame . forward ( ) ;
102+ } ,
103+ } ,
104+ {
105+ label : "Reload" ,
106+ action : ( ) => {
107+ frame . reload ( ) ;
108+ } ,
109+ } ,
77110 {
78- label : "??" ,
111+ label : "Bookmark" ,
112+ action : ( ) => {
113+ console . log ( "Bookmarking" , tab . title , tab . url ) ;
114+ } ,
79115 } ,
80116 ] ) ;
117+ e . preventDefault ( ) ;
81118 } ) ;
82119 const head = framedoc . querySelector ( "head" ) ! ;
83120 const observer = new MutationObserver ( ( ) => {
0 commit comments