diff --git a/devtools/client/debugger/src/client/firefox.js b/devtools/client/debugger/src/client/firefox.js index a1e92c5c58f3..97b382e2ea4f 100644 --- a/devtools/client/debugger/src/client/firefox.js +++ b/devtools/client/debugger/src/client/firefox.js @@ -4,27 +4,31 @@ // @flow -import { setupCommands, clientCommands } from "./firefox/commands"; -import { setupEvents, clientEvents } from "./firefox/events"; +import { + setupCommands, + setupCommandsTopTarget, + clientCommands, +} from "./firefox/commands"; +import { + setupEvents, + setupEventsTopTarget, + clientEvents, +} from "./firefox/events"; import { features, prefs } from "../utils/prefs"; export async function onConnect(connection: any, actions: Object) { const { debuggerClient, targetList } = connection; + setupCommands({ debuggerClient }); + setupEvents({ actions, debuggerClient }); + const currentTarget = targetList.targetFront; const threadFront = currentTarget.threadFront; if (!currentTarget || !threadFront || !debuggerClient) { return; } - - setupCommands({ - threadFront, - currentTarget, - debuggerClient, - }); - - setupEvents({ threadFront, currentTarget, actions, debuggerClient }); - + setupCommandsTopTarget(currentTarget); + setupEventsTopTarget(currentTarget); currentTarget.on("will-navigate", actions.willNavigate); currentTarget.on("navigate", actions.navigated); diff --git a/devtools/client/debugger/src/client/firefox/commands.js b/devtools/client/debugger/src/client/firefox/commands.js index c739fc1f0c47..41297aba421f 100644 --- a/devtools/client/debugger/src/client/firefox/commands.js +++ b/devtools/client/debugger/src/client/firefox/commands.js @@ -52,20 +52,21 @@ let eventBreakpoints: ?EventListenerActiveList; const CALL_STACK_PAGE_SIZE = 1000; type Dependencies = { - threadFront: ThreadFront, - currentTarget: Target, debuggerClient: DebuggerClient, }; function setupCommands(dependencies: Dependencies) { - currentThreadFront = dependencies.threadFront; - currentTarget = dependencies.currentTarget; debuggerClient = dependencies.debuggerClient; targets = {}; sourceActors = {}; breakpoints = {}; } +function setupCommandsTopTarget(targetFront: Target) { + currentTarget = targetFront; + currentThreadFront = targetFront.threadFront; +} + function createObjectFront(grip: Grip): ObjectFront { if (!grip.actor) { throw new Error("Actor is missing"); @@ -598,4 +599,4 @@ const clientCommands = { fetchAncestorFramePositions, }; -export { setupCommands, clientCommands }; +export { setupCommands, setupCommandsTopTarget, clientCommands }; diff --git a/devtools/client/debugger/src/client/firefox/events.js b/devtools/client/debugger/src/client/firefox/events.js index a86232b2d516..f3c55f360109 100644 --- a/devtools/client/debugger/src/client/firefox/events.js +++ b/devtools/client/debugger/src/client/firefox/events.js @@ -25,14 +25,13 @@ const { } = require("devtools/client/shared/workers-listener.js"); type Dependencies = { - threadFront: ThreadFront, - currentTarget: Target, actions: typeof Actions, debuggerClient: DebuggerClient, }; let actions: typeof Actions; let isInterrupted: boolean; +let workersListener: Object; function addThreadEventListeners(thread: ThreadFront) { Object.keys(clientEvents).forEach(eventName => { @@ -45,16 +44,21 @@ function attachAllTargets(currentTarget: Target) { } function setupEvents(dependencies: Dependencies) { - const { currentTarget, threadFront, debuggerClient } = dependencies; + const { debuggerClient } = dependencies; actions = dependencies.actions; sourceQueue.initialize(actions); - addThreadEventListeners(threadFront); - currentTarget.on("workerListChanged", () => threadListChanged()); debuggerClient.mainRoot.on("processListChanged", () => threadListChanged()); - if (features.windowlessServiceWorkers || attachAllTargets(currentTarget)) { - const workersListener = new WorkersListener(debuggerClient.mainRoot); + workersListener = new WorkersListener(debuggerClient.mainRoot); +} + +function setupEventsTopTarget(targetFront: Target) { + targetFront.on("workerListChanged", () => threadListChanged()); + addThreadEventListeners(targetFront.threadFront); + + workersListener.removeListener(); + if (features.windowlessServiceWorkers || attachAllTargets(targetFront)) { workersListener.addListener(() => threadListChanged()); } } @@ -130,4 +134,10 @@ const clientEvents = { replayFramePositions, }; -export { setupEvents, clientEvents, addThreadEventListeners, attachAllTargets }; +export { + setupEvents, + setupEventsTopTarget, + clientEvents, + addThreadEventListeners, + attachAllTargets, +};