samuelmaddock/electron-browser-shell

eletron-browser-shell isn't firing functions of Chrome extension

Jenifer-TheCoder opened this issue · 6 comments

I had installed electron-browser-shell as mentioned in the link:https://github.com/samuelmaddock/electron-browser-shell.

  • I have my custom chrome extension which has its background.js with below contents:
    "chrome.tabs.onActivated.addListener(onActivatedHandler);
    chrome.windows.onFocusChanged.addListener(onFocusChangedHandler);
    chrome.tabs.onUpdated.addListener(onUpdatedHandler);
    chrome.runtime.onMessage.addListener(onRuntimeMessageHandler);"

  • I print messages whenever it hits any of the above mentioned callbacks,for an example: onRuntimeMessageHandler function

  • i dont see any log printing from the above mentioned function via electron-browser-shell.

  • I had loaded my custom extension(unpacked extension folder) under extensions directory i.e-electron-browser-shell-master\extensions\xxxxxxxxxxxxxxxxxxx

  • From the above code snippet ,i know that electron doesn't first three lines. But 4th line is obvious that it should get hit.

Any thoughts why it isn't hitting?

Hi, could you please try again with the latest changes on the master branch? I pushed a change which might fix the problems you were seeing.

@samuelmaddock ,not much difference between the previous and current one. Could make scripts available in content-scripts section by declaring content-scripts section in manifest.json.

I am trying to implement a generic chrome extension which would be working for both Chrome and Electron. So currently figuring how can I get active tab from background javascript files where this.tab might fail. Any suggestions?

@Jenifer-TheCoder I feel like I'm missing context to your comment. Electron by itself doesn't have a concept of an active tab. electron-chrome-extensions adds support for it.

What is this.tab that you're referring to? I don't know what the context for this is.

You can use chrome.tabs.query to get the active tab: https://developer.chrome.com/docs/extensions/reference/tabs/#method-query

@samuelmaddock ,let me try to rephrase to convey things right.

  • I am working on Electron-chrome extension support, we have our own chrome extension.
  • The requirement here is to make chrome extension work with Electron app as well.
  • Thanks for electron-chrome-extension which adds enhanced support for Electron-chrome extensions

My Question here is:

  • I would like to get active tab from background script of chrome extension, how can I retrieve from Electron-application?
  • Had seen " var electron__WEBPACK_IMPORTED_MODULE_0__ = webpack_require(/*! electron */ "electron");" in dist/index.js.
  • Background script files were using chrome.tabs.query before.

No changes should be required to a Chrome extension for it to work.

In order for electron-chrome-extensions to function properly, you'll need to inform your instance of the Extensions class of any tabs you create using

extensions.addTab(browserWindow.webContents, browserWindow)

This is mentioned in the readme https://github.com/samuelmaddock/electron-browser-shell/tree/master/packages/electron-chrome-extensions#basic

@samuelmaddock Thanks for the information. I am already using electron-browser-shell project only to load my custom action.

  • Help me understand your comment, do you mean to say main/renderer process code to have extensions instance been created? If that is the case, it is already there since I am using electron-browser-shell itself.

  • I could see the comment " Called when chrome.tabs.xxx is invoked by an extension".
    Does that mean electron-chrome-extensions has an ability to handle chrome.tabs.xxx/chrome.windows.xxx/chrome.webnavigation APIs, those are called from Chrome extension with zero code change from its background scripts?