Documentation
¶
Overview ¶
Package serviceworker owns origin-scoped Service Worker registrations.
Index ¶
- Constants
- Variables
- func IsSecureContext(target *url.URL) bool
- type Cache
- type CacheStorage
- func (storage *CacheStorage) Delete(origin, name string) bool
- func (storage *CacheStorage) Has(origin, name string) bool
- func (storage *CacheStorage) Keys(origin string) []string
- func (storage *CacheStorage) Match(origin string, request *network.Request) (*network.Response, bool)
- func (storage *CacheStorage) Open(origin, name string) (*Cache, error)
- type FetchScript
- type Manager
- func (manager *Manager) Caches() *CacheStorage
- func (manager *Manager) Close() error
- func (manager *Manager) Controller(clientURL *url.URL) *runtimemodel.ServiceWorkerRegistration
- func (manager *Manager) DispatchFetch(ctx context.Context, request *network.Request, fallback NetworkFallback) (*network.Response, error)
- func (manager *Manager) GetRegistration(clientURL *url.URL, clientValue string) (*runtimemodel.ServiceWorkerRegistration, error)
- func (manager *Manager) GetRegistrations(clientURL *url.URL) ([]runtimemodel.ServiceWorkerRegistration, error)
- func (manager *Manager) Register(ctx context.Context, clientURL *url.URL, scriptValue, scopeValue string, ...) (runtimemodel.ServiceWorkerRegistration, error)
- func (manager *Manager) Unregister(clientURL *url.URL, scopeValue string) (bool, error)
- func (manager *Manager) Update(ctx context.Context, clientURL *url.URL, scopeValue string, fetch FetchScript) (runtimemodel.ServiceWorkerRegistration, error)
- type NetworkFallback
Constants ¶
const ( MaxCachesPerOrigin = 32 MaxCacheEntries = 4096 MaxCacheResponseBytes = 4 << 20 MaxCacheOriginBytes = 128 << 20 )
const ( MaxRegistrations = 64 MaxWorkerScriptBytes = 2 << 20 )
Variables ¶
var ( ErrCacheQuota = errors.New("service worker Cache Storage quota exceeded") ErrCacheRequest = errors.New("service worker Cache only stores GET requests") )
var ( ErrInsecureContext = errors.New("service worker requires a secure context") ErrCrossOrigin = errors.New("service worker script and scope must be same-origin") ErrScope = errors.New("service worker scope exceeds the script directory") ErrQuota = errors.New("service worker registration quota exceeded") )
var ( ErrPersistenceIO = errors.New("service worker persistence I/O failure") ErrPersistenceCorrupt = errors.New("corrupt service worker profile data") )
var ErrServiceWorkerProcess = errors.New("service worker process failure")
Functions ¶
func IsSecureContext ¶
IsSecureContext accepts HTTPS and HTTP loopback development origins.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a handle to one named origin cache.
type CacheStorage ¶
type CacheStorage struct {
// contains filtered or unexported fields
}
CacheStorage is a concurrency-safe, origin-partitioned response store.
func (*CacheStorage) Delete ¶
func (storage *CacheStorage) Delete(origin, name string) bool
Delete removes a named cache and releases its quota atomically.
func (*CacheStorage) Has ¶
func (storage *CacheStorage) Has(origin, name string) bool
Has reports whether a named cache exists for origin.
func (*CacheStorage) Keys ¶
func (storage *CacheStorage) Keys(origin string) []string
Keys returns cache names in deterministic order.
type FetchScript ¶
FetchScript retrieves one Service Worker script through Browser-owned I/O.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager stores registrations for one browser profile.
func NewManager ¶
func NewManager() *Manager
NewManager creates an empty in-memory registration store.
func NewPersistentManager ¶
NewPersistentManager restores Service Worker profile state below dataRoot. A corrupt file is quarantined without suppressing healthy Origins.
func (*Manager) Caches ¶
func (manager *Manager) Caches() *CacheStorage
Caches returns the origin-partitioned Cache Storage owned by this profile.
func (*Manager) Close ¶
Close stops every idle or active Service Worker process owned by the profile.
func (*Manager) Controller ¶
func (manager *Manager) Controller(clientURL *url.URL) *runtimemodel.ServiceWorkerRegistration
Controller returns the active claimed worker for a client, if any.
func (*Manager) DispatchFetch ¶
func (manager *Manager) DispatchFetch(ctx context.Context, request *network.Request, fallback NetworkFallback) (*network.Response, error)
DispatchFetch delivers a controlled request to the longest matching active worker. A worker that does not synchronously call respondWith uses fallback.
func (*Manager) GetRegistration ¶
func (manager *Manager) GetRegistration(clientURL *url.URL, clientValue string) (*runtimemodel.ServiceWorkerRegistration, error)
GetRegistration returns the longest active scope matching clientValue.
func (*Manager) GetRegistrations ¶
func (manager *Manager) GetRegistrations(clientURL *url.URL) ([]runtimemodel.ServiceWorkerRegistration, error)
GetRegistrations returns same-origin registrations ordered by scope.
func (*Manager) Register ¶
func (manager *Manager) Register(ctx context.Context, clientURL *url.URL, scriptValue, scopeValue string, fetch FetchScript) (runtimemodel.ServiceWorkerRegistration, error)
Register fetches and atomically installs or updates one scope.
func (*Manager) Unregister ¶
Unregister removes one same-origin scope and makes its workers redundant.
func (*Manager) Update ¶
func (manager *Manager) Update(ctx context.Context, clientURL *url.URL, scopeValue string, fetch FetchScript) (runtimemodel.ServiceWorkerRegistration, error)
Update revalidates the currently configured script URL.