Google Chrome Extensions

chrome.runtime

API Reference: chrome.runtime

Properties

lastError

chrome.runtime.lastError
lastError ( optional object )
This will be defined during an API method callback if there was an error

Properties of lastError

message ( optional string )
Details about the error which occurred.

id

chrome.runtime.id
id ( string )
The ID of the extension/app.

Methods

getBackgroundPage

chrome.runtime.getBackgroundPage()

Retrieves the JavaScript 'window' object for the background page running inside the current extension. 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.

getManifest

object chrome.runtime.getManifest()

Returns details about the app or extension from the manifest. The object returned is a serialization of the full manifest file.

getURL

string chrome.runtime.getURL(string path)

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

Parameters

path ( string )
A path to a resource within an app/extension expressed relative to its install directory.

Events

onStartup

chrome.runtime.onStartup.addListener(function() {...});

Fired when the browser first starts up.

onInstalled

chrome.runtime.onInstalled.addListener(function(object details) {...});

Fired when the extension is first installed, and on each update to a new version.

Listener Parameters

details ( object )
reason ( enumerated string ["install", "update"] )
The reason that this event is being dispatched.
previousVersion ( optional string )
Indicates the previous version of the extension, which has just been updated. This is present only if 'reason' is 'update'.

onSuspend

chrome.runtime.onSuspend.addListener(function() {...});

Sent to the event page just before it is unloaded. This gives the extension opportunity to do some clean up. Note that since the page is unloading, any asynchronous operations started while handling this event are not guaranteed to complete. If more activity for the event page occurs before it gets unloaded the onSuspendCanceled event will be sent and the page won't be unloaded.

onSuspendCanceled

chrome.runtime.onSuspendCanceled.addListener(function() {...});

Sent after onSuspend() to indicate that the app won't be unloaded after all.

Sample Extensions that use chrome.runtime

  • Context Menus Sample (with Event Page) – Shows some of the features of the Context Menus API using an event page
  • Event Page Example – Demonstrates usage and features of the event page
  • WebNavigation Tech Demo – Demonstration of the WebNavigation extension API.
  • Catifier – Moar cats!
  • Google Mail Checker – Displays the number of unread messages in your Google Mail inbox. You can also click the button to open your inbox.