@@ -48,6 +48,9 @@ export class Tab extends StatefulClass {
4848 devtoolsOpen : boolean = false ;
4949 devtoolsWidth = 200 ;
5050
51+ sendToChobitsu : ( ( message : string ) => void ) | null = null ;
52+ onChobitsuMessage : ( ( message : string ) => void ) | null = null ;
53+
5154 constructor ( public url : URL = new URL ( "puter://newtab" ) ) {
5255 super ( createState ( Object . create ( Tab . prototype ) ) ) ;
5356
@@ -74,6 +77,7 @@ export class Tab extends StatefulClass {
7477 let injected = false ;
7578 frame . addEventListener ( "contextInit" , ( ctx ) => {
7679 injectContextMenu ( ctx . client , this ) ;
80+ injectChobitsu ( ctx . client , this ) ;
7781
7882 // make sure it's top level, ctxInit calls for all frames too
7983 if ( ctx . window == frame . frame . contentWindow ) {
@@ -167,6 +171,23 @@ export class Tab extends StatefulClass {
167171 }
168172}
169173
174+ function injectChobitsu ( client : ScramjetClient , tab : Tab ) {
175+ // the fake origin is defined in sw.js
176+ const devtoolsUrl = "https://fake-devtools.invalid" ;
177+ // make sure to create the element through the proxied document
178+ let devtoolsScript = client . global . document . createElement ( "script" ) ;
179+ devtoolsScript . setAttribute ( "src" , devtoolsUrl + "/chobitsu_inject.js" ) ;
180+
181+ // @ts -expect-error
182+ client . global . $onChobitsuMessage = ( message : string ) => {
183+ tab . onChobitsuMessage ( message ) ;
184+ } ;
185+ tab . sendToChobitsu = ( message : string ) => {
186+ // @ts -expect-error
187+ client . global . $sendToChobitsu ( message ) ;
188+ } ;
189+ }
190+
170191function injectDevtools ( client : ScramjetClient , tab : Tab ) {
171192 // right here there's three contexts, the main window, the page frame, and the empty devtools frame
172193 // chobitsu is injected into the page frame (loaded from https://fake-devtools.invalid/target.js), and then will try and inject
0 commit comments