14

I am facing some trouble adding chrome addons into my Electron BrowserWindow.

Before creating my window (and after the ready event has fired), I try to add a devtools extension that my browser needs to do screen sharing.

BrowserWindow.addDevToolsExtension('/home/USER/.config/chromium/Default/Extensions/dkjdkjlcilokfaigbckcipicchgoazeg/1.5_0');

I followed this Electron guide, and it worked for their example (adding the react develop tool). When I do the exact same thing with my own chrome extension I have this error:

[4735:1116/163422.268391:ERROR:CONSOLE(7701)] "Skipping extension with invalid URL: chrome-extension://extension-name", source: chrome-devtools://devtools/bundled/shell.js (7701)

I don't really get why the error specified is "invalid URL" since I'm doing the exact same thing / process with the react addon without a problem. I also have no idea what to do. Is it possible that my chrome addon is not Electron-compatible?

pushkin
  • 9,575
  • 15
  • 51
  • 95
jineb92
  • 189
  • 1
  • 4
  • 13
  • Are you trying to add a standard extension (React devtools for instance) or one you’ve created yourself? – MTCoster Nov 16 '18 at 15:49
  • @MTCoster It is one our company created in order to enable screen sharing on our platform. – jineb92 Nov 16 '18 at 16:04
  • According to the documentation, it seems you have to specify different URLs for different operating systems. Which operating system is this being used/developed on? – user3864563 Nov 16 '18 at 16:05
  • @user3864563 We are developing / testing this on Ubuntu. Different URL must be specified for each operating system ? I could not find that in the documentation – jineb92 Nov 29 '18 at 16:03
  • @jineb92 It's not a different path, per se, but a different location where it would be located. – user3864563 Nov 29 '18 at 16:09
  • @user3864563 I just found some forums concerning Electron stating that Electron does not support Chrome extension. I fear that it might be impossible to do – jineb92 Nov 29 '18 at 16:16
  • @jineb92 It used to be the case that Electron did not support extensions. It does now. –  Nov 29 '18 at 17:13
  • 1
    Update, here's some more support: https://github.com/electron/electron/blob/master/docs/api/extensions.md – caffeinum Apr 30 '20 at 14:28

4 Answers4

8

It looks like you're trying to add a regular Chrome extension instead of a Dev Tools extension.

The BrowserWindow.addExtension(path) method is for regular Chrome extensions:

BrowserWindow.addExtension(path)

  • path String

Adds Chrome extension located at path, and returns extension's name.

The method will also not return if the extension's manifest is missing or incomplete.

Note: This API cannot be called before the ready event of the app module is emitted.

- https://electronjs.org/docs/api/browser-window#browserwindowaddextensionpath

Conversely, the BrowserWindow.addDevToolsExtension(path) method is for Dev Tools extensions:

BrowserWindow.addDevToolsExtension(path)

  • path String

Adds DevTools extension located at path, and returns extension's name.

The extension will be remembered so you only need to call this API once, this API is not for programming use. If you try to add an extension that has already been loaded, this method will not return and instead log a warning to the console.

The method will also not return if the extension's manifest is missing or incomplete.

Note: This API cannot be called before the ready event of the app module is emitted.

- https://electronjs.org/docs/api/browser-window#browserwindowadddevtoolsextensionpath

Note that in both cases you need to wait for the ready event from the app module to be emitted:

const { BrowserWindow, app } = require('electron')

let mainWindow = null

function main() {
  BrowserWindow.addExtension('/path/to/extension')
  mainWindow = new BrowserWindow()
  mainWindow.loadURL('https://google.com')
  mainWindow.on('close', event => {
    mainWindow = null
  })
}

app.on('ready', main)
  • 1
    I should indeed use .addExtension since I am trying to add a regular chrome extension but it is still not working. I'm still having the same error "Skipping extension with invalide URL: chrome-extension://extension-name". I'm adding the extension on click after the ready event so that could not be error – jineb92 Nov 29 '18 at 16:06
  • I have tried with other extensions such as grammarly and I have the exact same problem. [Here](https://chrome.google.com/webstore/detail/wimi-airtime-screen-shari/dkjdkjlcilokfaigbckcipicchgofemg?hl=fr&gl=FR) is the one I'm trying to import I think it might not be related to the extension but rather how I try to import it. EDIT : I'm probably doing something wrong in the way I'm integrating the chrome-extension. Right now I'm taking it from the Extensions folder that is in .config/Chromium/Default/Extensions and paste it into my project. is it not how you're supposed to do it ? – jineb92 Nov 30 '18 at 13:18
  • 2
    Running into the same thing - has anyone found an answer? – CorrugatedAir Jan 04 '19 at 13:19
  • same issue, any help? – Rupesh Kumar prasad Apr 02 '20 at 21:34
  • 1
    It is deprecated as of May 1st 2021: https://www.electronjs.org/docs/api/browser-window#browserwindowaddextensionpath-deprecated – Arjuna Deva May 01 '21 at 03:12
7

Support for Chromium extensions in Electron is actively being worked on at the moment. The support isn't complete yet, but the GitHub issue seems to have regular updates being posted.

Fingers crossed!

A current pull request is open for 'just enough extensions [api] to load a simple ... extension'

David Wheatley
  • 426
  • 6
  • 16
5

Electron 9 has much more support for extensions!

To load them, use session.loadExtension: https://github.com/electron/electron/blob/master/docs/api/extensions.md

const { app, BrowserWindow, session } = require('electron')

// ... in your createWindow function, which is called after app.whenReady

const mainWindow = new BrowserWindow({...})

const ext = await session.defaultSession.loadExtension('/path/to/unpacked/chrome-ext')

console.log('ext', ext)
// outputs config file
// {
//   id: 'dcpdbjjnmhhlnlbibpeeiambicbbndim',
//   name: 'Up! – Free Social Bot',
//   path: '/Users/caffeinum/Development/GramUp/chrome-ext',
//   url: 'chrome-extension://dcpdbjjnmhhlnlbibpeeiambicbbndim/',
//   version: '1.7.0',
//   manifest: { ... }
// }


Read more: https://github.com/electron/electron/blob/master/docs/api/extensions.md

Also, there's another project that helps you do that, also adds additional functionality: https://github.com/sentialx/electron-extensions

caffeinum
  • 401
  • 5
  • 13
2

While there is a documented method to register a normal extension, in majority of cases it won't do much, as Electron supports only an accessibility subset of the chrome.* APIs (apparently only the stuff required by Spectron and Devtron) and as they've stated a while ago, they don't have any plans to support Chrome extension APIs at a full scale.

jayarjo
  • 16,124
  • 24
  • 94
  • 138