Globals

The Globals package is a kernel that manages the globals of the application (e.g., window) and uses the globalsHelper to expose an API.

Globals helper

This helper injects to the plugins a set of methods to retrieve these globals.

Note: It is highly encouraged to use this helper whenever a global is needed. It will allow securing the application if needed and it provides a better testing experience by avoiding mocking and un-mocking globals.

getConsole

Gets the Console property of Window object.

Usage
Copy
getConsole(): object
Returns
  • Object

    A reference to the Console object.

Example
Copy
class PluginExample {
  constructor({ getConsole }) {
    this.console = getConsole();
    this.console.log('Hello World');
  }
}

getCookies

Gets cookies of the application and parses them.

Usage
Copy
getCookies(): object
Returns
  • Object

    Cookies.

Example
Copy
class PluginExample {
  constructor({ getCookies }) {
    this.cookies = getCookies();
    const { my_cookie } = this.cookies;
  }
}

getDocument

Gets the document property of Window object.

Usage
Copy
getDocument(): object
Returns
  • Object

    A reference to the document contained in the window.

Example
Copy
class PluginExample {
  constructor({ getDocument }) {
    this.document = getDocument();
    const { baseURI } = this.document;
  }
}

getGlobal

Gets the Global object.

Usage
Copy
getGlobal(): object
Example
Copy
class PluginExample {
  constructor({ getGlobal }) {
    this.global = getGlobal();
    this.global.alert('Hello World');
  }
}

getWindow

Gets the Window object. This function is an alias of getGlobal().

Usage
Copy
getWindow(): object
Returns
  • Object

    Window object.

Example
Copy
class PluginExample {
  constructor({ getWindow }) {
    this.window = getWindow();
    this.window.alert('Hello World');
  }
}