chrome

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Rendered for js/wasm

Overview

Package chrome exposes Go versions of Chrome's extension APIs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BigStorage added in v0.0.20

type BigStorage struct {
	// contains filtered or unexported fields
}

BigStorage supports storing and retrieving keys and values of arbitrary sizes in persistent storage. Items that fit within the per-item quota are stored normally; larger ones are split into multiple chunks.

Overall storage quota still applies, but this bypasses the per-item quotas.

BigStorage implements the PersistentStore interface.

func (*BigStorage) Delete added in v0.0.20

func (b *BigStorage) Delete(keys []string, callback func(err error))

See PersistentStore.Delete().

func (*BigStorage) Get added in v0.0.20

func (b *BigStorage) Get(callback func(data map[string]js.Value, err error))

See PersistentStore.Get().

func (*BigStorage) Set added in v0.0.20

func (b *BigStorage) Set(data map[string]js.Value, callback func(err error))

See PersistentStore.Set().

type C

type C struct {
	// contains filtered or unexported fields
}

C provides access to Chrome's extension APIs.

func New

func New(chrome js.Value) *C

New returns an instance of C that can be used to access Chrome's extension APIs. Set chrome to nil to access the default Chrome API implementation; it should only be overridden for testing.

func (*C) Error

func (c *C) Error() error

Error returns the error (if any) from the last call. Returns nil if there was no error.

See https://developer.chrome.com/apps/runtime#property-lastError.

func (*C) OnConnectExternal

func (c *C) OnConnectExternal(callback func(port js.Value))

OnConnectExternal installs a callback that will be invoked when an external connection is received.

See https://developer.chrome.com/apps/runtime#event-onConnectExternal.

func (*C) SendMessage

func (c *C) SendMessage(msg js.Value, callback func(rsp js.Value))

SendMessage sends a message within our extension. While the underlying Chrome API supports sending a message to another extension, we only expose functionality to send within the same extension.

See https://developer.chrome.com/apps/runtime#method-sendMessage.

func (*C) SessionStorage added in v0.0.20

func (c *C) SessionStorage() PersistentStore

SessionStorage returns a PersistentStore object that can be used to to store data in memory. Data persists across Service Worker restarts.

See https://developer.chrome.com/apps/storage#property-session.

func (*C) SyncStorage

func (c *C) SyncStorage() PersistentStore

SyncStorage returns a PersistentStore object that can be used to to store persistent data that is synchronized with Chrome Sync.

See https://developer.chrome.com/apps/storage#property-sync.

type PersistentStore added in v0.0.20

type PersistentStore interface {
	// Set stores new data. See chrome.Storage.Set() for details.
	Set(data map[string]js.Value, callback func(err error))

	// Get gets data from storage. See chrome.Storage.Get() for details.
	Get(callback func(data map[string]js.Value, err error))

	// Delete deletes data from storage. See chrome.Storage.Delete() for
	// details.
	Delete(keys []string, callback func(err error))
}

PersistentStore provides access to underlying storage. See chrome.Storage for details on the methods; using this interface allows for alternate implementations during testing.

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

Storage supports storing and retrieving data using Chrome's Storage API.

Storage implements the PersistentStore interface.

func (*Storage) Delete

func (s *Storage) Delete(keys []string, callback func(err error))

Delete removes the items from storage with the specified keys. If a key is not found in storage, it will be silently ignored (i.e., no error will be returned). Callback is invoked when complete.

See remove() in https://developer.chrome.com/apps/storage#type-StorageArea.

func (*Storage) Get

func (s *Storage) Get(callback func(data map[string]js.Value, err error))

Get reads all the data items currently stored. The callback will be invoked when complete, suppliing the items read and indicating any errors. The data suppiled with the callback is a map of key-value pairs, with each representing a distinct item from storage.

See get() in https://developer.chrome.com/apps/storage#type-StorageArea.

func (*Storage) Set

func (s *Storage) Set(data map[string]js.Value, callback func(err error))

Set stores new data in storage. data is a map of key-value pairs to be stored. If a key already exists, it will be overwritten. Callback will be invoked when complete.

See set() in https://developer.chrome.com/apps/storage#type-StorageArea.

type TypedStore added in v0.0.20

type TypedStore[V any] struct {
	// contains filtered or unexported fields
}

TypedStore reads and writes typed values. They are serialized upon writing, and deserialized upon reading. If deserialization fails for a given value, it is ignored.

func NewTypedStore added in v0.0.20

func NewTypedStore[V any](store PersistentStore, keyPrefix string) *TypedStore[V]

NewTypedStore returns a new TypedStore using the underlying persistent store. keyPrefix is the prefix used to distinguish values from others in the same underlying store.

func (*TypedStore[V]) Delete added in v0.0.20

func (t *TypedStore[V]) Delete(test func(v *V) bool, callback func(err error))

Delete removes the value that matches the supplied test function. If multiple values match, all matching values are removed. callback is invoked upon completion.

func (*TypedStore[V]) Read added in v0.0.20

func (t *TypedStore[V]) Read(test func(v *V) bool, callback func(value *V, err error))

Read returns a single value that matches the supplied test function. If multiple values match, only the first is returned. callback is invoked with the returned value. If the value is not found, then the callback is invoked with a nil value.

func (*TypedStore[V]) ReadAll added in v0.0.20

func (t *TypedStore[V]) ReadAll(callback func(values []*V, err error))

ReadAll returns all the stored values. callback is invoked when complete.

func (*TypedStore[V]) Write added in v0.0.20

func (t *TypedStore[V]) Write(value *V, callback func(err error))

Write writes a new value to storage. callback is invoked when complete.

Directories

Path Synopsis
Package fakes implements fake implementations of Chrome's extension APIs to ease unit testing.
Package fakes implements fake implementations of Chrome's extension APIs to ease unit testing.

Jump to

Keyboard shortcuts

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