Adding tab into BrowserWindow that has BrowserView doesn't seem to be working
We are trying to validate whether we can load chrome extensions in the Electronjs application. The electron application has browser window which loads BrowserView inside. I had modified the code to have "extensions.addTab" method which is supposed to add a tab to the electron application , but it doesn't seem to be working .
This is the code portion, I had modified with the electron-chrome-extensions code:
`
view = new BrowserView({
webPreferences: {
sandbox: true,
nodeIntegration: false,
preload: preloadPath,
contextIsolation: true,
spellcheck: false
}
});
//targetWindow is the Bro
const { ElectronChromeExtensions } = require('electron-chrome-extensions')
const extensions = new ElectronChromeExtensions();
const session_1 = view.webContents.session;
session_1.loadExtension(path.join(__dirname, './extensions')).then((ext) => {
console.log('Extension loaded' + ext)
});
extensions.addTab(targetWindow.webContents, targetWindow)
console.log('Added tab into electron application')
await view.webContents.loadURL(urlOrPath);`
Here is the screenshot from chrome-extension's devtools window , saying that there is no active tab for the application
Let me know how to sort this out!
Ah yes we had experienced that quite often in our early use of this repo (which has great framework for many Chrome mv2 API)
We had to several things to prevent this.
Firstly we created a hidden tab that always exists, and it's transparent and selected when there are no other tabs present (Eg all tabs are closed)
Secondly, a key was to have also have your extension handling logic get the main window using window Electron APIs for other required commands.
We have a fork working quite well with many extensions, but the key is we had to create a specific extensions.js file to all handling of tabs correctly. Some extensions create tabs in different or unexpected ways (spawning a popup, or a window or a new tab)
Feel free to check ours out: https://github.com/MASQ-Project/MASQ-web3-dapp-store
I'll try to get a gist of our current file we used to adapt the extension handling. We have our browser closed source at the moment while we work on proprietary implementations (will be open sourced later this year most likely)