Skip to content

WebExtension API to execute external commands through native messaging

License

Notifications You must be signed in to change notification settings

faxal/webextension-shell

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shell for Chrome and FirefoxWebExtensions

WebExtension API to execute external commands through native messaging.

Dependencies

Installation

  1. Host
  2. Extension

Usage

// Environment variables
switch (true) {
  case (typeof browser !== 'undefined'):
    var PLATFORM = 'firefox'
    var SHELL_EXTENSION_ID = '[email protected]'
    break
  case (typeof chrome !== 'undefined'):
    var PLATFORM = 'chrome'
    var SHELL_EXTENSION_ID = 'ohgecdnlcckpfnhjepfdcdgcfgebkdgl'
    break
}

// Initialization
const shell = {}
shell.port = chrome.runtime.connect(SHELL_EXTENSION_ID)
shell.send = (command, ...arguments) => {
  shell.port.postMessage({ command, arguments })
}

// Usage
shell.send('mpv', 'https://youtu.be/7ky_itVPTnk')
Ping-pong
const ping = () => {
  shell.port.postMessage({
    id: 'ping-pong',
    command: 'echo',
    arguments: ['Ping']
  })
}

shell.port.onMessage.addListener((response) => {
  switch (response.id) {
    case 'ping-pong':
      console.log(response.output, 'Pong')
      break
  }
})

// Ping-pong
ping()

You can find some examples in Krabby.

See the source for a complete reference.

API

Request
{
  id: String?,
  command: String,
  arguments: Array(String)?,
  environment: Hash(String, String)?,
  shell: { type: Bool, default: false },
  input: String?,
  directory: String?
}
Response
{
  id: String?,
  status: Int32,
  output: String,
  error: String
}

About

WebExtension API to execute external commands through native messaging

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 54.0%
  • Crystal 23.5%
  • Makefile 14.7%
  • JavaScript 6.0%
  • Dockerfile 1.8%