Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Implement chrome.tabs.onReplaced.addEventListener #487

Closed
petemill opened this issue Feb 11, 2018 · 3 comments
Closed

Implement chrome.tabs.onReplaced.addEventListener #487

petemill opened this issue Feb 11, 2018 · 3 comments
Assignees

Comments

@petemill
Copy link
Member

petemill commented Feb 11, 2018

When a tab becomes discarded from a previously-loaded state, its tabId is changed permanently. The previous Tab/WebContents is destroyed, and a new Tab/WebContents is created. The same happens for Chrome as for muon. However, in Chrome, an event (tabs.onReplaced) is exposed which provides the translation between the oldTabId and the newTabId.

This is important for consuming apps in order to present new incoming Tab/WebContents objects as 'new' by animating in, and not performing that animation for new Tab/WebContents objects which are previously known to the app. Since there is no other property to represent the Tab object uniquely, there is no other way to differentiate a 'new' tab versus a 'replaced' tab.

The only way to do this currently is to always have the tab attached to a <webview> object in a renderer window, and handle the tab-id-changed event inside the renderer window. This prevents being able to have only the active tab attached to a renderer window at a time, which has performance implications.

image

@petemill
Copy link
Member Author

Some options for implementing this could be:

  • Implement chrome-tabs-replaced event similar to -created, -updated and -removed that exist currently.
  • When web-contents-created is emitted, provide the old contents ID if it is being replaced.
  • During TabHelper::TabReplacedAt emit a new tab-id-changed event

@petemill
Copy link
Member Author

@bridiver suggests that when we receive add-new-contents we should replace the existing contents if it there is one occupying the same index in the same windowId as the incoming contents.
If a tab is being inserted to an index (e.g. attached to a specific index), will the other tabs receive new indexes before this contents is inserted at the previously-occupied index?

@petemill
Copy link
Member Author

petemill commented Feb 13, 2018

...and another question about whether we'll get the new replacement Tab/WebContents before the old Tab/WebContents is destroyed, otherwise we'll still only know that a tab has been removed.

The answer appears to be yes based on the current sequence of events:

Tab [50] event 'will-discard'
Tab [54] created in window -1
Tab [50] event 'will-detach'
Tab [50] event 'discarded'
Tab [50] event 'devtools-closed'
Tab [50] event 'will-destroy'
tab [50 via process] - chrome-tabs-removed
Tab [probably 50] event 'destroyed'

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants