Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexherbo2/webextension-shell
WebExtension API to execute external commands through native messaging
https://github.com/alexherbo2/webextension-shell
api chrome firefox native-messaging webextension
Last synced: about 1 month ago
JSON representation
WebExtension API to execute external commands through native messaging
- Host: GitHub
- URL: https://github.com/alexherbo2/webextension-shell
- Owner: alexherbo2
- License: unlicense
- Created: 2019-10-03T16:54:35.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-10-21T17:46:44.000Z (about 1 year ago)
- Last Synced: 2024-05-21T04:25:01.599Z (8 months ago)
- Topics: api, chrome, firefox, native-messaging, webextension
- Language: Shell
- Homepage:
- Size: 31.3 KB
- Stars: 16
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING
Awesome Lists containing this project
README
# Shell for [Chrome] and [Firefox] – [WebExtensions]
[Chrome]: https://google.com/chrome/
[Firefox]: https://mozilla.org/firefox/
[WebExtensions]: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions[WebExtension][WebExtensions] API to execute external commands through [native messaging].
[Native messaging]: https://developer.chrome.com/extensions/nativeMessaging
## Dependencies
- [Crystal]
- [jq][Crystal]: https://crystal-lang.org
[jq]: https://stedolan.github.io/jq/## Installation
1. [Host](host)
2. [Extension](extension)## Usage
``` javascript
// Environment variables
switch (true) {
case (typeof browser !== 'undefined'):
var PLATFORM = 'firefox'
var SHELL_EXTENSION_ID = 'shell@alexherbo2.github.com'
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
``` javascript
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].
[Krabby]: https://krabby.netlify.app
See the [source](host/src) for a complete reference.
## API
###### Request
``` crystal
{
id: String?,
command: String,
arguments: Array(String)?,
environment: Hash(String, String)?,
shell: { type: Bool, default: false },
input: String?,
directory: String?
}
```###### Response
``` crystal
{
id: String?,
status: Int32,
output: String,
error: String
}
```