このページは大阪弁化フィルタによって翻訳生成されたんですわ。

翻訳前ページへ


chrome.extension - Google Chrome
The Wayback Machine - http://web.archive.org/web/20140107052417/https://developer.chrome.com/extensions/extension.html

chrome.extension

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.
Availability: Stable since Chrome 5.

Support for content scripts

Unlike the other chrome.* APIs, parts of chrome.extension can be used by content scripts:

runtime.sendMessage and runtime.onMessage
Simple communication with extension pages
runtime.connect and runtime.onConnect
Extended communication with extension pages
getURL
Access to extension resources such as image files

For details, see Content Scripts.

chrome.extension reference

Properties

lastError

chrome.extension.lastError
lastError ( object )
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.

Properties of lastError

message ( string )

Description of the error that has taken place.

inIncognitoContext

chrome.extension.inIncognitoContext
inIncognitoContext ( boolean )
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.

Methods

sendRequest

sendRequest is deprecated. Please use runtime.sendMessage.

chrome.extension.sendRequest(string extensionId, any request, function responseCallback)

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 onRequest event is fired in each page of the extension.

Parameters

extensionId ( optional string )

The extension ID of the extension you want to connect to. If omitted, default is your own extension.

request ( any )

responseCallback ( optional function )

If you specify the responseCallback parameter, it should specify a function that looks like this:

function(any response) {...};

response ( any )

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.lastError will be set to the error message.

getURL

string chrome.extension.getURL(string path)

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.

getViews

array of window chrome.extension.getViews(object fetchProperties)

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

Parameters

fetchProperties ( optional object )

Properties

type ( optional enum of "tab", "infobar", "notification", or "popup" )

The type of view to get. If omitted, returns all views (including background pages and tabs). Valid values: 'tab', 'infobar', 'notification', 'popup'.

windowId ( optional integer )

The window to restrict the search to. If omitted, returns all views.

getBackgroundPage

window chrome.extension.getBackgroundPage()

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

Properties of return type

getExtensionTabs

getExtensionTabs is deprecated. Please use getViews {type: "tab"}.

array of window chrome.extension.getExtensionTabs(integer windowId)

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

windowId ( optional integer )

isAllowedIncognitoAccess

chrome.extension.isAllowedIncognitoAccess(function callback)

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

Parameters

callback ( function )

The callback parameter should specify a function that looks like this:

function(boolean isAllowedAccess) {...};

isAllowedAccess ( boolean )

True if the extension has access to Incognito mode, false otherwise.

isAllowedFileSchemeAccess

chrome.extension.isAllowedFileSchemeAccess(function callback)

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

Parameters

callback ( function )

The callback parameter should specify a function that looks like this:

function(boolean isAllowedAccess) {...};

isAllowedAccess ( boolean )

True if the extension can access the 'file://' scheme, false otherwise.

setUpdateUrlData

chrome.extension.setUpdateUrlData(string data)

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

data ( string )

Events

onRequest

onRequest is deprecated. Please use runtime.onMessage.

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

addListener

chrome.extension.onRequest.addListener(function callback)

Parameters

callback ( function )

The callback parameter should specify a function that looks like this:

function(any request, runtime.MessageSender sender, function sendResponse) {...};

request ( optional any )

The request sent by the calling script.

sendResponse ( function )

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.

onRequestExternal

onRequestExternal is deprecated. Please use runtime.onMessageExternal.

Fired when a request is sent from another extension.

addListener

chrome.extension.onRequestExternal.addListener(function callback)

Parameters

callback ( function )

The callback parameter should specify a function that looks like this:

function(any request, runtime.MessageSender sender, function sendResponse) {...};

request ( optional any )

The request sent by the calling script.

sendResponse ( function )

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