The browser.extension API has utilities that can be used by any extension page. It includes support for exchanging messages between an extension and its content scripts or between extensions, as described in detail in Message Passing.

_GetViewsFetchProperties
_LastError
ViewType
inIncognitoContext
lastError
onRequest
onRequestExternal
getBackgroundPage
getURL
getViews
isAllowedFileSchemeAccess
isAllowedIncognitoAccess
setUpdateUrlData
ViewType: "tab" | "popup" | "sidebar"

The type of extension view.

inIncognitoContext: boolean | undefined

True for content scripts running inside incognito tabs, and for extension pages running inside an incognito process. The latter only applies to extensions with 'split' incognito_behavior.

lastError: browser.extension._LastError | undefined

Set for the lifetime of a callback if an ansychronous extension api has resulted in an error. If no error has occured lastError will be undefined.

Please use runtime.lastError. Not supported on manifest versions above 2.

onRequest:
    | WebExtEvent<
        (
            request: any,
            sender: MessageSender,
            sendResponse: (response?: any) => void,
        ) => void,
    >
    | undefined

Fired when a request is sent from either an extension process or a content script.

The request sent by the calling script.

Function to call (at most once) when you have a response. The argument should be any JSON-ifiable object, or undefined if there is no response. If you have more than one onRequest listener in the same document, then only one may send a response.

Please use runtime.onMessage.

onRequestExternal:
    | WebExtEvent<
        (
            request: any,
            sender: MessageSender,
            sendResponse: (response?: any) => void,
        ) => void,
    >
    | undefined

Fired when a request is sent from another extension.

The request sent by the calling script.

Function to call when you have a response. The argument should be any JSON-ifiable object, or undefined if there is no response.

Please use runtime.onMessageExternal.

  • Returns the JavaScript 'window' object for the background page running inside the current extension. Returns null if the extension has no background page.

    Returns void | Window

  • Converts a relative path within an extension install directory to a fully-qualified URL.

    Parameters

    • path: string

      A path to a resource within an extension expressed relative to its install directory.

    Returns string

    The fully-qualified URL to the resource.

    Please use runtime.getURL. Not supported on manifest versions above 2.

  • Returns an array of the JavaScript 'window' objects for each of the pages running inside the current extension.

    Parameters

    Returns Window[]

    Array of global objects

  • Retrieves the state of the extension's access to the 'file://' scheme (as determined by the user-controlled 'Allow access to File URLs' checkbox.

    Returns Promise<boolean>

  • Retrieves the state of the extension's access to Incognito-mode (as determined by the user-controlled 'Allowed in Incognito' checkbox.

    Returns Promise<boolean>

  • Sets the value of the ap CGI parameter used in the extension's update URL. This value is ignored for extensions that are hosted in the browser vendor's store.

    Parameters

    • data: string

    Returns void

    Unsupported on Firefox at this time.