chrest

package module
v0.0.0-...-2762141 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 13 Imported by: 2

README

Chrest: healthier window and tab hygiene


Chrest is a CLI tool and Chrome extension that allow you to manage Chrome via REST. Chrest was inspired by (and somewhat forked from) TabFS.

Chrest consists of two parts:

  1. Chrome Extension: (/extension)
  2. Native Messaging Host & CLI Client: chrest (/)

Examples

Note: to keep Chrest slim, Chrest does not include pretty-print JSON or HTTP Request construction, but there are other wonderful tools you can use for that like http and jq.

  • Getting all windows and tabs:

    $ http --ignore-stdin --offline localhost/windows |
    $   chrest client |
    $   jq
    > [
    >   {
    >     "alwaysOnTop": false,
    >     "focused": false,
    >     "height": 1400,
    >     "id": 1531273373,
    >     "incognito": false,
    >     "left": 1411,
    >     "state": "normal",
    >     "tabs": [
    >       {
    >         "active": true,
    >         "audible": false,
    >         "autoDiscardable": true,
    >         "discarded": false,
    >         "favIconUrl": "https://github.githubassets.com/favicons/favicon.svg",
    >         "groupId": -1,
    >         "height": 1279,
    >         "highlighted": true,
    >         "id": 1531273367,
    >         "incognito": false,
    >         "index": 0,
    >         "mutedInfo": {
    >           "muted": false
    >         },
    >         "pinned": false,
    >         "selected": true,
    >         "status": "complete",
    >         "title": "friedenberg/chrest",
    >         "url": "https://github.com/friedenberg/chrest",
    >         "width": 1128,
    >         "windowId": 1531273373
    >       }
    >     ],
    >     "top": 20,
    >     "type": "normal",
    >     "width": 1128
    >   }
    > ]
    
  • Creating a new window with some URL's:

    $ http --ignore-stdin --offline localhost/windows \
    $   urls[]=https://github.com/friedenberg/chrest |
    $   chrest client |
    $   jq
    > {
    >   "alwaysOnTop": false,
    >   "focused": false,
    >   "height": 1400,
    >   "id": 1531273390,
    >   "incognito": false,
    >   "left": 0,
    >   "state": "normal",
    >   "tabs": [
    >     {
    >       "active": true,
    >       "audible": false,
    >       "autoDiscardable": true,
    >       "discarded": false,
    >       "groupId": -1,
    >       "height": 1279,
    >       "highlighted": true,
    >       "id": 1531273391,
    >       "incognito": false,
    >       "index": 0,
    >       "lastAccessed": 1708099951989.452,
    >       "mutedInfo": {
    >         "muted": false
    >       },
    >       "pendingUrl": "https://github.com/friedenberg/chrest",
    >       "pinned": false,
    >       "selected": true,
    >       "status": "loading",
    >       "title": "",
    >       "url": "",
    >       "width": 1128,
    >       "windowId": 1531273390
    >     }
    >   ],
    >   "top": 0,
    >   "type": "normal",
    >   "width": 1128
    > }
    
  • Closing a window:

    $ http --ignore-stdin --offline DELETE localhost/windows/1531273390 |
    $   chrest client |
    $   jq
    

Installation

  1. Clone this repo: git clone github.com/friedenberg/chrest

  2. Go to Chrome extensions

  3. Enable Developer mode (top-right corner)

  4. Load-unpacked the extension/ folder from this repo

    Take note of the extension ID, it looks like lbgclgjcapgipnneocphmhckebhbbkac

  5. go build

  6. ./chrest install <extension ID>

  7. Add $HOME/.local/bin to your $PATH

  8. Reload the extension in Chrome to start the service worker

  9. Try http --ignore-stdin --offline localhost/windows | ./chrest client | jq

Todo

  • mutate bookmark endpoints
  • proper PUT endpoints for windows and tabs
  • history endpoints

Known Issues

  • Chrome will turn off service workers when there are no windows left, so at least 1 window needs to exist for chrest to be running. I may add a fallback in chrest to use AppleScript to create a new window if the server is not running.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AskChrome

func AskChrome(c Config, req *http.Request) (response interface{}, err error)

func ByteArrayToInt32

func ByteArrayToInt32(arr [4]byte) int32

func Int32ToByteArray

func Int32ToByteArray(i int32) [4]byte

func ReadAllOrDieTrying

func ReadAllOrDieTrying(r io.Reader, b []byte) (n int, err error)

func ReadFromChrome

func ReadFromChrome(m interface{}) (n int64, err error)

func ReadInt32

func ReadInt32(r io.Reader, i *int32) (n int64, err error)

func ResponseFromReader

func ResponseFromReader(r io.Reader, conn net.Conn) (resp *http.Response, err error)

func ServeHTTP

func ServeHTTP(w http.ResponseWriter, req *http.Request)

func StateDirectory

func StateDirectory() (v string, err error)
func Symlink(oldPath, newPath string) (err error)

func WriteAllOrDieTrying

func WriteAllOrDieTrying(w io.Writer, b []byte) (n int, err error)

func WriteToChrome

func WriteToChrome(m interface{}) (n int64, err error)

Types

type Config

type Config struct {
	Home string `json:"-"`
	Port string `json:"port"`
}

func ConfigDefault

func ConfigDefault() (c Config, err error)

func (Config) Directory

func (c Config) Directory() (v string)

func (*Config) Read

func (c *Config) Read() (err error)

func (Config) ServerPath

func (c Config) ServerPath() string

func (Config) SocketPath

func (c Config) SocketPath() (v string, err error)

func (*Config) Write

func (c *Config) Write() (err error)

type InstallJSON

type InstallJSON struct {
	Name           string   `json:"name"`
	Description    string   `json:"description"`
	Path           string   `json:"path"`
	Type           string   `json:"type"`
	AllowedOrigins []string `json:"allowed_origins"`
}

func MakeInstallJSON

func MakeInstallJSON(p string, ids ...string) (ij InstallJSON, err error)

type JsonAnything

type JsonAnything = interface{}

type JsonObject

type JsonObject = map[string]JsonAnything

type Request

type Request JsonObject

func NewRequest

func NewRequest(in *http.Request, body JsonAnything) (out Request)

type ServerSocket

type ServerSocket struct {
	SockPath string
	Address  *net.UnixAddr
	Listener *net.UnixListener
}

func (*ServerSocket) Listen

func (s *ServerSocket) Listen() (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL