samuelmaddock / electron-browser-shell

A minimal, tabbed web browser with support for Chrome extensions—built on Electron.
GNU General Public License v3.0
335 stars 68 forks source link

[electron-chrome-extensions] event for chrome.tabs.update #79

Open Kilian opened 1 year ago

Kilian commented 1 year ago

One of my extensions calles chrome.tabs.update with a new URL like so:

const openInSuperposition = url => chrome.tabs.update({ url: `superposition://${url}` });

I'd like to be able to hook into that call and decide how to update or handle that URL change. Is that possible?

Kilian commented 1 year ago

Looking into this, it seems that because I dont provide a tabId, the current implementation picks the webcontents of the sender as the active tab but if that's not added to the extension manager (in my case, the main UI) then getting the tabid returns undefined and the chrome.tabs.update function is aborted:

https://github.com/samuelmaddock/electron-browser-shell/blob/master/packages/electron-chrome-extensions/src/browser/api/tabs.ts#L257

Is there a way to fall back to whatever webContents was last selected with selectExtensionTab?

samuelmaddock commented 1 year ago

I had a bug in the code which was trying to get the active tab from the window of the MV2 background page. I updated the code to get the active tab from the last focused window instead.