Description
The chrome.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.
Types
ViewType
The type of extension view.
Enum
"tab"  "popup" 
 
 
Properties
inIncognitoContext
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.
Type
boolean
lastError
Please use runtime.lastError.
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.
Type
object
Properties
- 
    messagestring Description of the error that has taken place. 
Methods
getBackgroundPage()
chrome.extension.getBackgroundPage(): Window | undefined
Returns the JavaScript 'window' object for the background page running inside the current extension. Returns null if the extension has no background page.
Returns
- 
            Window | undefined 
getExtensionTabs()
chrome.extension.getExtensionTabs(
windowId?: number,
): Window[]
Please use extension.getViews {type: "tab"}.
Returns an array of the JavaScript 'window' objects for each of the tabs running inside the current extension. If windowId is specified, returns only the 'window' objects of tabs attached to the specified window.
Parameters
- 
    windowIdnumber optional 
Returns
- 
            Window[] Array of global window objects 
getURL()
chrome.extension.getURL(
path: string,
): string
Please use runtime.getURL.
Converts a relative path within an extension install directory to a fully-qualified URL.
Parameters
- 
    pathstring A path to a resource within an extension expressed relative to its install directory. 
Returns
- 
            string The fully-qualified URL to the resource. 
getViews()
chrome.extension.getViews(
fetchProperties?: object,
): Window[]
Returns an array of the JavaScript 'window' objects for each of the pages running inside the current extension.
Parameters
- 
    fetchPropertiesobject optional - 
    tabIdnumber optional Chrome 54+Find a view according to a tab id. If this field is omitted, returns all views. 
- 
    typeViewType optional The type of view to get. If omitted, returns all views (including background pages and tabs). 
- 
    windowIdnumber optional The window to restrict the search to. If omitted, returns all views. 
 
- 
    
Returns
- 
            Window[] Array of global objects 
isAllowedFileSchemeAccess()
chrome.extension.isAllowedFileSchemeAccess(
callback?: function,
): Promise<boolean>
Retrieves the state of the extension's access to the 'file://' scheme. This corresponds to the user-controlled per-extension 'Allow access to File URLs' setting accessible via the chrome://extensions page.
Parameters
- 
    callbackfunction optional The callbackparameter looks like:(isAllowedAccess: boolean) => void - 
    isAllowedAccessboolean True if the extension can access the 'file://' scheme, false otherwise. 
 
- 
    
Returns
- 
            Promise<boolean> Chrome 99+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
isAllowedIncognitoAccess()
chrome.extension.isAllowedIncognitoAccess(
callback?: function,
): Promise<boolean>
Retrieves the state of the extension's access to Incognito-mode. This corresponds to the user-controlled per-extension 'Allowed in Incognito' setting accessible via the chrome://extensions page.
Parameters
- 
    callbackfunction optional The callbackparameter looks like:(isAllowedAccess: boolean) => void - 
    isAllowedAccessboolean True if the extension has access to Incognito mode, false otherwise. 
 
- 
    
Returns
- 
            Promise<boolean> Chrome 99+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
sendRequest()
chrome.extension.sendRequest(
extensionId?: string,
request: any,
callback?: function,
): Promise<any>
Please use runtime.sendMessage.
Sends a single request to other listeners within the extension. Similar to runtime.connect, but only sends a single request with an optional response. The extension.onRequest event is fired in each page of the extension.
Parameters
- 
    extensionIdstring optional The extension ID of the extension you want to connect to. If omitted, default is your own extension. 
- 
    requestany 
- 
    callbackfunction optional Chrome 99+The callbackparameter looks like:(response: any) => void - 
    responseany The JSON response object sent by the handler of the request. If an error occurs while connecting to the extension, the callback will be called with no arguments and runtime.lastErrorwill be set to the error message.
 
- 
    
Returns
- 
            Promise<any> Chrome 99+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
setUpdateUrlData()
chrome.extension.setUpdateUrlData(
data: string,
): void
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 Chrome Extension Gallery.
Parameters
- 
    datastring 
Events
onRequest
chrome.extension.onRequest.addListener(
callback: function,
)
Please use runtime.onMessage.
Fired when a request is sent from either an extension process or a content script.
Parameters
- 
    callbackfunction The callbackparameter looks like:(request: any, sender: runtime.MessageSender, sendResponse: function) => void - 
    requestany 
- 
    sender
- 
    sendResponsefunction The sendResponseparameter looks like:() => void 
 
- 
    
onRequestExternal
chrome.extension.onRequestExternal.addListener(
callback: function,
)
Please use runtime.onMessageExternal.
Fired when a request is sent from another extension.
Parameters
- 
    callbackfunction The callbackparameter looks like:(request: any, sender: runtime.MessageSender, sendResponse: function) => void - 
    requestany 
- 
    sender
- 
    sendResponsefunction The sendResponseparameter looks like:() => void 
 
-