Name | Description |
---|---|
getExtensionInfo | Returns an object describing the extension |
addMessageListener | Registers a message handler for the specified message name |
removeMessageListener | Removes a message handler that the addMessageListener method registered |
dispatchMessage | Dispatches a message |
invokeAsync | Calls function from background script |
invokeAsyncCallback | Calls asynchronous function from background script |
Returns a KangoExtensionInfo object describing the extension. Can be used in content scripts.
Returns: | object describing the extension |
---|---|
Return type: | KangoExtensionInfo |
Example:
var info = kango.getExtensionInfo();
kango.console.log(info.name); // shows extension name
Registers a message handler for the specified message name. Can be used in content scripts.
Arguments: |
|
---|
Message handler event:
event = {
data: variant, // JSON serializable data object attached to the message
target: object, // Point to object sent the message
source: KangoMessageSource // Message source
}
target field could be either KangoBrowserTab or kango objects.
For instance if message came from background to content script then target will be a kango object. If message came from content to background target will be KangoBrowserTab.
The event.source.dispatchMessage call could be used inside message handler function to send message back.
source KangoMessageSource object.
See Messaging API section for more details.
Example:
// background script
kango.addMessageListener('GetData', function(event) {
// send data back to content script
event.source.dispatchMessage('SetData', {a: 1});
});
// content script
kango.addMessageListener('SetData', function(event) {
kango.console.log(event.data);
});
kango.dispatchMessage('GetData');
Removes a message handler that the kango.addMessageListener() method registered. Can be used in content scripts.
Arguments: |
|
---|
Dispatches a message to background script.
See Messaging API section for more details.
Arguments: |
|
---|
Example:
/*
This will send a message to background scripts
In this Example message named 'action' will have two fields *data* object
It is possible to use any JSON serializable object
*/
kango.dispatchMessage('action', {name: 'DoABarrelRoll', count: 5});
Calls function from background script. Can be used in content scripts and options page.
Arguments: |
|
---|
Example:
kango.invokeAsync('kango.storage.setItem', 'Item1', 1);
kango.invokeAsync('kango.storage.getItem', 'Item1', function(data) {
kango.console.log(data);
});
kango.invokeAsync('kango.storage.removeItem', 'item1');
// invoke user defined function with name 'test_func'
// 'test_func' defined as function test_func(a, b){return a+b;} in background script
kango.invokeAsync('test_func', 1, 2, function(val) {
kango.console.log(val);
});
// invoke function 'foo' from object 'MyObj'
// 'MyObj' definition: var MyObj = {foo: function(x) {return x + 2;}};
kango.invokeAsync('MyObj.foo', 1, function(val) {
kango.console.log(val);
});
Calls asynchronous function from background script.
Arguments: |
|
---|
Example:
// background script
function foo(x, callback) {
window.setTimeout(1000, function() {
var y = x + 1;
callback(y);
});
}
// content script
kango.invokeAsyncCallback('foo', 2, function(result) {
alert(result);
});