Skip to content

Instantly share code, notes, and snippets.

@juliandescottes
Created July 17, 2019 16:05
Show Gist options
  • Save juliandescottes/9dcd14021ffed248fab3e408745b9941 to your computer and use it in GitHub Desktop.
Save juliandescottes/9dcd14021ffed248fab3e408745b9941 to your computer and use it in GitHub Desktop.
diff --git a/devtools/server/actors/network-monitor/websocket-actor.js b/devtools/server/actors/network-monitor/websocket-actor.js
--- a/devtools/server/actors/network-monitor/websocket-actor.js
+++ b/devtools/server/actors/network-monitor/websocket-actor.js
@@ -18,17 +18,17 @@ const webSocketEventService = Cc[
*
* @see devtools/shared/spec/websocket.js for documentation.
*/
const WebSocketActor = ActorClassWithSpec(webSocketSpec, {
initialize(conn, targetActor) {
Actor.prototype.initialize.call(this, conn);
this.targetActor = targetActor;
- this.listening = false;
+ this.listenWindowID = null;
// Each connection's webSocketSerialID is mapped to a httpChannelId
this.connections = new Map();
// Register for backend events.
this.onNavigate = this.onNavigate.bind(this);
this.onWillNavigate = this.onWillNavigate.bind(this);
this.targetActor.on("navigate", this.onNavigate);
@@ -50,30 +50,33 @@ const WebSocketActor = ActorClassWithSpe
this.stopListening();
Actor.prototype.destroy.call(this);
},
// Actor API
startListening: function() {
// Register WS listener
- if (!this.listening) {
+ if (!this.listenWindowID) {
const innerWindowID = this.targetActor.window.windowUtils
.currentInnerWindowID;
webSocketEventService.addListener(innerWindowID, this);
- this.listening = true;
+ this.listenWindowID = innerWindowID;
}
},
stopListening() {
- if (this.listening) {
- const innerWindowID = this.targetActor.window.windowUtils
- .currentInnerWindowID;
- webSocketEventService.removeListener(innerWindowID, this);
- this.listening = false;
+ if (this.listenWindowID) {
+ try {
+ webSocketEventService.removeListener(this.listenWindowID, this);
+ } catch (e) {
+ // XXX: this can throw apparently, probably if the debugged window is
+ // already gone? check with platform?
+ }
+ this.listenWindowID = null;
}
},
// nsIWebSocketEventService
webSocketCreated(webSocketSerialID, uri, protocols) {},
webSocketOpened(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment