Skip to content

Conversation

@iamEvanYT
Copy link
Contributor

Added

  • extensions.windowUpdated(window) - Update the details of a window from the main process.
  • extensions.tabUpdated(tab) - Update the details of a tab from the main process.

Fixes

  • Fixed incognito property of windows not being accurate (Flipped it)
  • Fixed windowDetailsCache not updating its tabs property.

✅ By sending this pull request, I agree to the Contributor License Agreement of this project.

@iamEvanYT iamEvanYT changed the title Add Windows and Tabs Updater feat: windows and tabs updater Apr 20, 2025

- `tab` Electron.WebContents

Update the details of a tab from the main process.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you tell me about how you plan to use these methods? Would it be possible to instead update automatically from within the module?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using the tabUpdated method here.

For example, I have a custom tab discarding system which would need manually updating.

{
  assignTabDetails: (tabDetails, tabWebContents) => {
    const tab = tabManager.getTabByWebContents(tabWebContents);
    if (!tab) return;

    tabDetails.title = tab.title;
    tabDetails.url = tab.url;
    tabDetails.favIconUrl = tab.faviconURL ?? undefined;
    tabDetails.discarded = tab.asleep;
    tabDetails.autoDiscardable = false;
  }
}

@iamEvanYT iamEvanYT requested a review from samuelmaddock April 24, 2025 16:38
@samuelmaddock
Copy link
Owner

The chrome.tabs implementation listens to a list of events in order to know when to trigger chrome.tabs.onUpdated.

const updateEvents = [
'page-title-updated', // title
'did-start-loading', // status
'did-stop-loading', // status
'media-started-playing', // audible
'media-paused', // audible
'did-start-navigation', // url
'did-redirect-navigation', // url
'did-navigate-in-page', // url
// Listen for 'tab-updated' to handle all other cases which don't have
// an official Electron API such as discarded tabs. App developers can
// emit this event to trigger chrome.tabs.onUpdated if a property has
// changed.
'tab-updated',
]
const updateHandler = () => {
this.onUpdated(tabId)
}

I've added a listener for "tab-updated" to handle all cases not already provided by Electron itself (88c50f4).

// Discard tab in your app's implementation
tab.discard()

// Emit tab-updated to make ElectronChromeExtensions aware of the change
tab.webContents.emit('tab-updated')

This eliminates the need for both windowUpdated and tabUpdated as the tab details will be invalidated properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants