• Stars
    star
    139
  • Rank 262,954 (Top 6 %)
  • Language
    TypeScript
  • Created over 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Implementation of Chrome extension APIs for Electron

Electron Chrome Extension

Build Status

Environment

Tested with Electron v4.0.4 - Node v8.9.0 - NPM v5.5.1

Setup

  • Renderer - preload
require('electron-chrome-extension/preload');

For some reasons the navigator user agent is not inherited from the session so you will need to redefine the user agent via the Object.defineProperty method after the import

  • Main
import ECx from 'electron-chrome-extension';

app.on('ready', async () => {
  createWindow();

  // Load Grammarly
  await ECx.load('kbfnbcaeplbcioakkpcpgfkobkghlhen');
});

Connect your application logic

Extensions react to browser events for trigger their own logic. ECx send inner webContents events to extensions subscribers but external events like creating new window, changing tab focus etc should be triggered on your side like this:

// main.js

ipcMain.on('YOUR_EVENT', (...) =>
  ECx.sendEvent({
    channel: 'tabs.onActivated',
    payload: [{ tabId, windowId }],
  })
);

Usage with DevTools extension

⚠️ electron-chrome-extension will break Electron's support for Devtools extensions.

If you wish to use devtools extensions, make sure to add the prelaod on the Session itself:

if (isDev) {
  app.on('session-created', session => {
    session.setPreloads([path.join(__dirname, 'node_modules/electron-chrome-extension/preload')]
  });
}

It is not recommended to have the preload added to Sessions outside developement environnement because it can lead to have extension's code run in priviledged contexts (BrowserWindows with nodeIntegration for instance).

Then install Chrome DevTools extensions with electron-chrome-extension:

import ECx from 'electron-chrome-extension';
// load React Dev Tools
ECx.load('jdkknkkbebbapilgoeccciglkfbmbnfm');

ECx APIs

  • ECx.load(extensionId: IExtension['id']): Promise<IExtension>
  • ECx.unload(extensionId: IExtension['id']): void
  • ECx.setConfiguration(configuration: Configuration = {}): Promise<ECx>
  • ECx.isLoaded(extensionId: IExtension['id']): boolean
  • ECx.isUpToDate(extensionId: IExtension['id']): Promise<boolean>
  • ECx.get(extensionId: IExtension['id']): Promise<IExtension>
  • ECx.sendEvent(event: ExtensionEventMessage): void

Tools

  • Start Playground
$ npm start

You can tweak the playground files at your convenience and extensions would automatically downloaded and clean app data with $ npm run playground:reset

  • Test
$ npm test

We use electron-mocha for run our test suit. Warning (because not explained in the lib): test assertions lives in the renderer, the main remains accessible for IPC calls and Electron Main API calls.

  • Publish
$ npm publish

References

Know supported extensions

as of 05/29/19 with their Chrome WebStore ID

  • Mixmax: ocpljaamllnldhepankaeljmeeeghnid
  • Gmelius: dheionainndbbpoacpnopgmnihkcmnkl
  • Mailtracker: pgbdljpkijehgoacbjpolaomhkoffhnl
  • Boomerang: mdanidgdpmkimeiiojknlnekblgmpdll
  • Clearbit Connect: pmnhcgfcafcnkbengdcanjablaabjplo
  • Grammarly: kbfnbcaeplbcioakkpcpgfkobkghlhen
  • React Developers Tools: fmkadmapgofadopljbjfkapdkoienihi
  • Redux DevTools: lmhkpmbekcpmknklioeibfkpmmfibljd
  • Apollo Client Developer Tools: jdkknkkbebbapilgoeccciglkfbmbnfm

More Repositories

1

desktop-app

One app to rule them all!
TypeScript
1,424
star
2

electron-process-manager

Process manager UI for Electron applications
JavaScript
189
star
3

electron-google-oauth2

A Google OAuth2 module for your Electron app
TypeScript
76
star
4

getstation.github.io

https://getstation.com/
JavaScript
24
star
5

electron-package-manager

Dynamically install and require modules in electron
TypeScript
16
star
6

repackage-chrome-extension-for-electron

Repackage a Chrome extension to be loaded via Electron's `addDevToolsExtension`
JavaScript
16
star
7

electron-process-reporter

Utility to extract interesting process reports of an Electron application
TypeScript
9
star
8

apollo-link-webextensions-messaging

Apollo Link that, in a WebExtension, forwards GraphQL operations between processes
TypeScript
9
star
9

catalog

Station's UI catalog
TypeScript
7
star
10

tapas

Collection of delicious technical challenges
TypeScript
4
star
11

electron-better-web-request

Extended behaviour for Electron WebRequest : add multiple listeners capabilities.
TypeScript
4
star
12

station-canary

Canary releases of Station
4
star
13

apollo-link-reactive-schema

Apollo Link that provides a reactive-graphql execution environment to perform operations on a provided reactive schema
TypeScript
4
star
14

hookstate-plugin-web-extension

Sync and persist state between background page and content_script using browser.storage
TypeScript
3
star
15

zeplin-JSS-extension

JSS snippets from colors, text styles and layers
JavaScript
3
star
16

electron-intercom-messenger

Integrate the Intercom messenger widget into an electron application.
JavaScript
2
star
17

stream-json-rpc

Easy bi-directionnal RPC for node/electron/browser, using the transport that you need.
TypeScript
2
star
18

theme

Station Theme & Styleguide
TypeScript
2
star
19

redux-broadcast-actions

A tiny middleware to broadcast your redux actions using the Broadcast Channel API
TypeScript
2
star
20

apollo-link-electron-ipc

Apollo link that transfers operations to main
TypeScript
2
star
21

tslint-config-station

The official Station TSLint config
JavaScript
1
star
22

electron-iframe-devtools

JavaScript
1
star
23

apollo-server-plugin-bugsnag

apollo-server plugin that sends errors to bugsnag
TypeScript
1
star
24

1password-node

TypeScript
1
star