Skip to content

Commit 88c50f4

Browse files
committed
feat: listen for tab updates with 'tab-updated' event
1 parent 891ed6f commit 88c50f4

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

packages/electron-chrome-extensions/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ module.exports = {
153153
- `removeWindow(browserWindow) => Promise<Electron.BrowserWindow>`
154154
(optional) - Called when `chrome.windows.remove` is invoked by an extension.
155155
- `browserWindow` Electron.BrowserWindow
156+
- `assignTabDetails(details, webContents) => void` (optional) - Called when `chrome.tabs` creates
157+
an object for tab details to be sent to an extension background script. Provide this function to
158+
assign custom details such as `discarded`, `frozen`, or `groupId`.
159+
- `details` [chrome.tabs.Tab](https://developer.chrome.com/docs/extensions/reference/api/tabs#type-Tab)
160+
- `webContents` Electron.WebContents - The tab for which details are being created.
156161

157162
```ts
158163
new ElectronChromeExtensions({
@@ -438,6 +443,13 @@ See [Electron's Notification tutorial](https://www.electronjs.org/docs/tutorial/
438443
- [ ] chrome.tabs.onReplaced
439444
- [x] chrome.tabs.onZoomChange
440445

446+
> [!NOTE]
447+
> Electron does not provide tab functionality such as discarded, frozen, or group IDs. If an
448+
> application developer wishes to implement this functionality, emit a `"tab-updated"` event on the
449+
> tab's WebContents for `chrome.tabs.onUpdated` to be made aware of changes. Tab properties can be
450+
> assigned using the `assignTabDetails` option provided to the `ElectronChromeExtensions`
451+
> constructor.
452+
441453
### [`chrome.webNavigation`](https://developer.chrome.com/extensions/webNavigation)
442454

443455
- [x] chrome.webNavigation.getFrame (Electron 12+)

packages/electron-chrome-extensions/src/browser/api/tabs.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ export class TabsAPI {
5656
'did-start-navigation', // url
5757
'did-redirect-navigation', // url
5858
'did-navigate-in-page', // url
59+
60+
// Listen for 'tab-updated' to handle all other cases which don't have
61+
// an official Electron API such as discarded tabs. App developers can
62+
// emit this event to trigger chrome.tabs.onUpdated if a property has
63+
// changed.
64+
'tab-updated',
5965
]
6066

6167
const updateHandler = () => {

0 commit comments

Comments
 (0)