Skip to content

Commit

Permalink
small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Joakim L. Christiansen authored and Joakim L. Christiansen committed Jun 4, 2024
1 parent 4647cf7 commit b66608e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions jlc-cdp.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class CDP_Session extends EventEmitter {

/** Detach this session from its target. */
detach() {
console.log(this.#sessionId)
return this.#cdp.send('Target.detachFromTarget', {sessionId: this.#sessionId})
}

Expand Down Expand Up @@ -119,11 +118,9 @@ export class ChromeDevToolsProtocol extends EventEmitter {
if ((params && targetId) || (!params && !targetId)) throw Error(`Either supply 'params' (e.g. {url}) to create a new target for the session or a 'targetId' to attach the session to.`)
const session = new CDP_Session(this, {params, targetId})
session.ready.then(({sessionId}) => {
// console.log('session attached', sessionId)
this.#attachedSessions.set(sessionId, session)
})
session.once('detached', ({sessionId}) => {
// console.log('session detached', sessionId)
this.#attachedSessions.delete(sessionId)
})
return session
Expand Down Expand Up @@ -202,7 +199,7 @@ export class ChromeDevToolsProtocol extends EventEmitter {
throw Error('Id not awaiting result, but got one: '+id+', '+data)
}
} else if ('method' in data) {
const {method, params, sessionId} = data
let {method, params, sessionId} = data
if (this.debug) {
if (this.debug_skipParams && data.params) {
const toDebug = {...data}
Expand All @@ -213,6 +210,10 @@ export class ChromeDevToolsProtocol extends EventEmitter {
}
}
this.emit(method, params, sessionId)
if (!sessionId && params?.sessionId) {
// have the session emit events related to it, e.g. Target.detachedFromTarget
sessionId = params.sessionId
}
if (sessionId) {
const session = this.#attachedSessions.get(sessionId)
if (session) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"name": "jlc-cdp",
"main": "./jlc-cdp.js",
"type": "module",
"version": "0.9.0",
"version": "0.9.1",
"description": "A tiny Chrome DevTools Protocol interface which doesn't get in your way!",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/joakimch/jlc-cdp"
},
"dependencies": {
"jlc-websocket": "^0.9.2"
"jlc-websocket": "^0.9.3"
}
}

0 comments on commit b66608e

Please sign in to comment.