From ac340e2346247b5cd1878e1a814d4c151df3e892 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 27 Apr 2016 10:26:24 +0100 Subject: Unregister frame port on onDisconnect. I seems that we cannot rely upon either the "unload" event in the content script or the port's onDisconnect handler there to unregister frames. To see this, go to a frame-busy page like this one: - https://www.theguardian.com/technology/2016/apr/26/apple-iphone-first-revenue-decline-13-years and then navigate to any other simple page (in the same tab). Navigate back and forward with `H` and `L`. If you watch frames registering anf unregistering, almost all of the frames from the frame-busy page do not unregister. Here, we unregister frames on onDisconnect in the background page too. It is possible that this is the source of the problem mentioned as point 1 in this comment: - https://github.com/philc/vimium/issues/2081#issuecomment-210980903 And for which #2116 is a workaround. --- background_scripts/main.coffee | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index dca9df7e..9f04d1c0 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -289,6 +289,7 @@ for icon in [ENABLED_ICON, DISABLED_ICON, PARTIAL_ICON] Frames = onConnect: (sender, port) -> [tabId, frameId] = [sender.tab.id, sender.frameId] + port.onDisconnect.addListener -> Frames.unregisterFrame {tabId, frameId} port.postMessage handler: "registerFrameId", chromeFrameId: frameId # Return our onMessage handler for this port. @@ -390,9 +391,12 @@ HintCoordinator = # If an unregistering frame is participating in link-hints mode, then we need to tidy up after it. unregisterFrame: (tabId, frameId) -> - delete @tabState[tabId]?.ports?[frameId] - # We fake "postHintDescriptors" for an unregistering frame. - @postHintDescriptors tabId, frameId, hintDescriptors: [] if @tabState[tabId]?.frameIds + if @tabState[tabId]? + if @tabState[tabId].ports?[frameId]? + delete @tabState[tabId].ports[frameId] + if @tabState[tabId].frameIds? and frameId in @tabState[tabId].frameIds + # We fake an empty "postHintDescriptors" because the frame has gone away. + @postHintDescriptors tabId, frameId, hintDescriptors: [] # Port handler mapping portHandlers = -- cgit v1.2.3