Coder Social home page Coder Social logo

alexherbo2 / webextension-shell Goto Github PK

View Code? Open in Web Editor NEW
16.0 1.0 5.0 32 KB

WebExtension API to execute external commands through native messaging

License: The Unlicense

Makefile 20.25% JavaScript 5.65% Shell 49.90% Crystal 22.72% Dockerfile 1.48%
chrome firefox webextension native-messaging api

webextension-shell's Introduction

Shell for Chrome and Firefox โ€“ WebExtensions

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
}

webextension-shell's People

Contributors

alexherbo2 avatar postsolar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

webextension-shell's Issues

host Make failed

The output is:
shards build --release
make: shards: No such file or directory
make: *** [Makefile:26: build] Error 127

System:
Gentoo/Linux x86_64

Docker version 20.10.0-dev, build 831ebeae96

Crystal 0.36.0 (2021-01-30)

LLVM: 11.0.1
Default target: x86_64-pc-linux-gnu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.