@@ -153,6 +153,19 @@ class CDPServer {
153153import type Protocol from "devtools-protocol" ;
154154import { browser } from "./main" ;
155155import type { Tab } from "./Tab" ;
156+
157+ function createTargetInfo ( tab : Tab ) : Protocol . Target . TargetInfo {
158+ return {
159+ browserContextId : "0" ,
160+ targetId : String ( tab . id ) ,
161+ type : "page" ,
162+ title : tab . title || "New Tab" ,
163+ url : tab . url . href ,
164+ attached : true ,
165+ canAccessOpener : false ,
166+ } ;
167+ }
168+
156169const Scopes = {
157170 Browser : {
158171 getVersion ( ) : Protocol . Browser . GetVersionResponse {
@@ -189,15 +202,7 @@ const Scopes = {
189202 {
190203 sessionId : sessionid ,
191204 waitingForDebugger : false ,
192- targetInfo : {
193- browserContextId : "0" ,
194- targetId : String ( tab . id ) ,
195- type : "page" ,
196- title : "test" ,
197- url : "https://google.com" ,
198- attached : false ,
199- canAccessOpener : false ,
200- } ,
205+ targetInfo : createTargetInfo ( tab ) ,
201206 }
202207 ) ;
203208
@@ -206,9 +211,21 @@ const Scopes = {
206211 } ;
207212 } ,
208213
209- async setAutoAttach ( params : Protocol . Target . SetAutoAttachRequest ) {
210- console . log ( "Target.setAutoAttach" , params ) ;
214+ async closeTarget ( params : Protocol . Target . CloseTargetRequest ) {
215+ let tab = browser . tabs . find ( ( x ) => x . id === Number ( params . targetId ) ) ;
216+ if ( ! tab ) {
217+ throw new Error ( `Target ${ params . targetId } not found` ) ;
218+ }
219+ browser . destroyTab ( tab ) ;
220+ server . emit < Protocol . Target . TargetDestroyedEvent > (
221+ "Target.targetDestroyed" ,
222+ {
223+ targetId : String ( tab . id ) ,
224+ }
225+ ) ;
226+ } ,
211227
228+ async setAutoAttach ( params : Protocol . Target . SetAutoAttachRequest ) {
212229 return { } ;
213230 } ,
214231 getTargetInfo (
0 commit comments