Skip to content

Commit

Permalink
fix and update initial feature: #13
Browse files Browse the repository at this point in the history
  • Loading branch information
june07 committed Nov 10, 2024
1 parent 9064d89 commit 2d8a62e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/devtoolsProtocolClient.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(async function (devtoolsProtocolClient) {
const userId = (await chrome.identity.getProfileUserInfo())?.id
devtoolsProtocolClient.sockets = {}

devtoolsProtocolClient.parseWebSocketUrl = (socketUrl) => socketUrl.match(/(wss?):\/\/(.*)\/(.*)$/)
Expand All @@ -19,8 +20,10 @@
delete devtoolsProtocolClient.sockets[dtpSocket.socket]
if (dtpSocket.ws.readyState !== WebSocket.CLOSED) dtpSocket.ws.close()
}
devtoolsProtocolClient.addEventListeners = (dtpSocket, autoClose, tabId) => {
devtoolsProtocolClient.addEventListeners = async (dtpSocket, autoClose, tabId) => {
googleAnalytics.fireEvent('Debugger Session Start', { ...dtpSocket, userId, tabId })
dtpSocket.ws.addEventListener('close', (reason) => {
googleAnalytics.fireEvent('Debugger Session End', { ...dtpSocket, reason, userId, tabId })
if (settings.debugVerbosity >= 1) console.log('ws closed: ', reason)
devtoolsProtocolClient.closeSocket(devtoolsProtocolClient.sockets[dtpSocket.socket])
/** First check to see if the tab was removed by the user in which case there should be a cache.removed entry from sw.js
Expand All @@ -42,10 +45,6 @@
//delete cache.tabs[dtpSocket.socket]?.promise
delete cache.tabs[dtpSocket.socket]
})
dtpSocket.ws.addEventListener('open', (event) => {
if (!settings.debuggingStatistics) return
event.currentTarget.send('{"id": 1, "method": "Debugger.enable"}')
})
dtpSocket.ws.addEventListener('message', (event) => {
const data = JSON.parse(event.data)
const { method, params } = data
Expand All @@ -56,7 +55,7 @@
if (method === 'Debugger.paused') {
details = { ...details, 'params.callFrames[0].location': params.callFrames[0]?.location }
}
googleAnalytics.fireEvent('Debugger Event', details)
googleAnalytics.fireEvent('Debugger Event', { userId, ...details })
}
})
async function logReadyState() {
Expand All @@ -77,6 +76,11 @@
// not sure this is needed anymore, seems to work fine now?! https://github.com/june07/nimv3/commit/5ee06e141e2dc6b33f08e394b89739152f723d50
// UPDATE 7/23/24... IT IS IN FACT NEEDED. Breaks autoClose without it
const interval = setInterval(logReadyState, 1000)
await async.until(
(cb) => cb(null, dtpSocket.ws.readyState === WebSocket.OPEN),
(next) => setTimeout(next, 500)
)
dtpSocket.ws.send('{"id": 1, "method": "Debugger.enable"}')
}
devtoolsProtocolClient.tasks = (socket, options) => {
const t1 = new Promise(resolve => {
Expand Down

0 comments on commit 2d8a62e

Please sign in to comment.