opera.extension.bgProcess

Description:

A reference to the window object of the background process. The bgProcess object can be used to set and get variables and functions between the background script and a popup window or preferences page. Note that it cannot be used in injected scripts for security reasons.

Example (variable):

The value of a variable in the background process is displayed when the preferences page is opened.

//
// The background process ('/background.js'). 
//

var data = 'This is some important data in the backround process';
//
// An extension environment (e.g. '/options.js')
//

window.addEventListener('DOMContentLoaded', function() {
  var myElement = document.createElement('p');
  myElement.textContent = opera.extension.bgProcess.data;
  document.body.appendChild(myElement);
}, false);

Example (function):

Executing a function in the background process from the preferences page.

//
// The background process ('/background.js'). 
//

function doReverse(text) {
  var output = '';
  for (var i = text.length - 1; i >= 0; i--) {
    output += text.charAt(i);
  }
  return output;
}
//
// An extension environment (e.g. '/options.js')
//

window.addEventListener('DOMContentLoaded', function() {
  var reversedText = opera.extension.bgProcess.doReverse('enihcam ym no skrow tI');
}, false);

This article is licensed under a Creative Commons Attribution 3.0 Unported license.

Comments

You must be logged in to write a comment. If you're not a registered member, please sign up.