| 162 | } |
| 163 | |
| 164 | _onMessage(message) { |
| 165 | if (message.id) { |
| 166 | const { resolve, reject } = this._commandResponsePromises.get(message.id); |
| 167 | this._commandResponsePromises.delete(message.id); |
| 168 | if (message.result) |
| 169 | resolve(message.result); |
| 170 | else |
| 171 | reject(message.error); |
| 172 | } else { |
| 173 | if (message.method === 'Debugger.scriptParsed') { |
| 174 | const { scriptId, url } = message.params; |
| 175 | this._scriptsIdsByUrl.set(scriptId, url); |
| 176 | const fileUrl = url.startsWith('file:') ? |
| 177 | url : pathToFileURL(url).toString(); |
| 178 | if (fileUrl === this.scriptURL().toString()) { |
| 179 | this.mainScriptId = scriptId; |
| 180 | } |
| 181 | } |
| 182 | if (message.method === 'Debugger.paused') |
| 183 | this._pausedDetails = message.params; |
| 184 | if (message.method === 'Debugger.resumed') |
| 185 | this._pausedDetails = null; |
| 186 | |
| 187 | if (this._notificationCallback) { |
| 188 | // In case callback needs to install another |
| 189 | const callback = this._notificationCallback; |
| 190 | this._notificationCallback = null; |
| 191 | callback(message); |
| 192 | } else { |
| 193 | this._unprocessedNotifications.push(message); |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | unprocessedNotifications() { |
| 199 | return this._unprocessedNotifications; |