From b66608eed6489ef44faaca15b232ed172a02e213 Mon Sep 17 00:00:00 2001 From: "Joakim L. Christiansen" <{ID}+{username}@users.noreply.github.com> Date: Tue, 4 Jun 2024 18:53:13 +0200 Subject: [PATCH] small fix --- jlc-cdp.js | 9 +++++---- package.json | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/jlc-cdp.js b/jlc-cdp.js index e9e9bb5..1b7a9bc 100644 --- a/jlc-cdp.js +++ b/jlc-cdp.js @@ -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}) } @@ -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 @@ -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} @@ -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) { diff --git a/package.json b/package.json index fdad72c..908c14a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "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": { @@ -10,6 +10,6 @@ "url": "https://github.com/joakimch/jlc-cdp" }, "dependencies": { - "jlc-websocket": "^0.9.2" + "jlc-websocket": "^0.9.3" } }