browser.runtime
API to retrieve the background page, return details about the manifest,
* and listen for and respond to events in the app or extension lifecycle. You can also use this API to convert the
* relative path of URLs to fully-qualified URLs.
*
* Comments found in source JSON schema files:
* Copyright 2014 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
import { Tabs } from "./tabs";
import { Manifest } from "./manifest";
import { Events } from "./events";
export namespace Runtime {
/**
* An object which allows two way communication with other pages.
*/
interface Port {
name: string;
disconnect(): void;
/**
* @param port
*/
onDisconnect: Events.Event<(port: Port) => void>;
/**
* @param message
* @param port
*/
onMessage: Events.Event<(message: any, port: Port) => void>;
/**
* Send a message to the other end. This takes one argument, which is a JSON object representing the message to send.
* It will be delivered to any script listening to the port's onMessage event, or to the native application if this port
* is connected to a native application.
*
* @param message
*/
postMessage(message: any): void;
/**
* This property will only be present on ports passed to onConnect/onConnectExternal listeners.
* Optional.
*/
sender?: MessageSender;
/**
* If the port was disconnected due to an error, this will be set to an object with a string property message,
* giving you more information about the error. See onDisconnect.
* Optional.
*/
error?: PortErrorType;
}
/**
* An object containing information about the script context that sent a message or request.
*/
interface MessageSender {
/**
* The $(ref:tabs.Tab) which opened the connection, if any. This property will only
* be present when the connection was opened from a tab (including content scripts), and only
* if the receiver is an extension, not an app.
* Optional.
*/
tab?: Tabs.Tab;
/**
* The $(topic:frame_ids)[frame] that opened the connection. 0 for top-level frames, positive for child frames.
* This will only be set when tab
is set.
* Optional.
*/
frameId?: number;
/**
* The ID of the extension or app that opened the connection, if any.
* Optional.
*/
id?: string;
/**
* The URL of the page or frame that opened the connection. If the sender is in an iframe,
* it will be iframe's URL not the URL of the page which hosts it.
* Optional.
*/
url?: string;
}
/**
* The operating system the browser is running on.
*/
type PlatformOs = "mac" | "win" | "android" | "cros" | "linux" | "openbsd";
/**
* The machine's processor architecture.
*/
type PlatformArch = "aarch64" | "arm" | "ppc64" | "s390x" | "sparc64" | "x86-32" | "x86-64";
/**
* An object containing information about the current platform.
*/
interface PlatformInfo {
/**
* The operating system the browser is running on.
*/
os: PlatformOs;
/**
* The machine's processor architecture.
*/
arch: PlatformArch;
}
/**
* An object containing information about the current browser.
*/
interface BrowserInfo {
/**
* The name of the browser, for example 'Firefox'.
*/
name: string;
/**
* The name of the browser vendor, for example 'Mozilla'.
*/
vendor: string;
/**
* The browser's version, for example '42.0.0' or '0.8.1pre'.
*/
version: string;
/**
* The browser's build ID/date, for example '20160101'.
*/
buildID: string;
}
/**
* Result of the update check.
*/
type RequestUpdateCheckStatus = "throttled" | "no_update" | "update_available";
/**
* The reason that this event is being dispatched.
*/
type OnInstalledReason = "install" | "update" | "browser_update";
/**
* The reason that the event is being dispatched. 'app_update' is used when the restart is needed because the application
* is updated to a newer version. 'os_update' is used when the restart is needed because the browser/OS is updated to a
* newer version. 'periodic' is used when the system runs for more than the permitted uptime set in the enterprise policy.
*/
type OnRestartRequiredReason = "app_update" | "os_update" | "periodic";
/**
* If an update is available, this contains more information about the available update.
*/
interface RequestUpdateCheckCallbackDetailsType {
/**
* The version of the available update.
*/
version: string;
}
interface ConnectConnectInfoType {
/**
* Will be passed into onConnect for processes that are listening for the connection event.
* Optional.
*/
name?: string;
/**
* Whether the TLS channel ID will be passed into onConnectExternal for processes that are listening for the connection
* event.
* Optional.
*/
includeTlsChannelId?: boolean;
}
interface SendMessageOptionsType {
[s: string]: unknown;
}
interface OnInstalledDetailsType {
/**
* The reason that this event is being dispatched.
*/
reason: OnInstalledReason;
/**
* Indicates the previous version of the extension, which has just been updated. This is present only if 'reason' is
* 'update'.
* Optional.
*/
previousVersion?: string;
/**
* Indicates whether the addon is installed as a temporary extension.
*/
temporary: boolean;
}
/**
* The manifest details of the available update.
*/
interface OnUpdateAvailableDetailsType {
/**
* The version number of the available update.
*/
version: string;
}
/**
* This will be defined during an API method callback if there was an error
*/
interface PropertyLastErrorType {
/**
* Details about the error which occurred.
* Optional.
*/
message?: string;
}
/**
* If the port was disconnected due to an error, this will be set to an object with a string property message,
* giving you more information about the error. See onDisconnect.
*/
interface PortErrorType {
message: string;
}
interface Static {
/**
* Retrieves the JavaScript 'window' object for the background page running inside the current extension/app.
* If the background page is an event page, the system will ensure it is loaded before calling the callback.
* If there is no background page, an error is set.
*/
getBackgroundPage(): PromiseOpen your Extension's options page, if possible.
The precise behavior may depend on your manifest's
* $(topic:optionsV2)[options_ui]
or $(topic:options)[options_page]
key,
* or what the browser happens to support at the time.
If your Extension does not declare an options page, * or the browser failed to create one for some other reason, the callback will set $(ref:lastError).
*/ openOptionsPage(): Promise