fakeData API

Fake Data offers a set of helpful methods under fakeData object that you can use to take advantage of Fake Data's internal features.

Please not that some methods may work only in some execution contexts (background page, foreground page, and sandboxed iframe), and the return values may differ between them. Please check each method return value to see more details about this.

getGeneratorValue

  • Details:
    • Generate a random value from a specified generator.
  • Arguments:
    • generator name - The name of the generator that will be used. Can be a Default Generator or a Custom Generator.
  • Returns:
    • Will return a Promise that resolves to a string containing the generated value
ContextActual return value
(MV2) Background pagePromise which resolves to a string
(MV2) Foreground pagePromise which resolves to a string
(MV3) Sandbox iframePromise which resolves to a string
Public API Custom IntegrationPromise which resolves to a string
  • Usage:
return fakeData.getGeneratorValue('first_name'); // "Jackie"

getLastGeneratedValue

  • Details:
    • Retrieves the last generated value for a specific generator.
  • Arguments:
    • generator name - The name of the generator that will be used. Can be a Default Generator or a Custom Generator.
  • Returns:
    • Will return a Promise that resolves to a string containing the retrieved value
ContextActual return value
(MV2) Background pagePromise which resolves to a string
(MV2) Foreground pagePromise which resolves to a string
(MV3) Sandbox iframePromise which resolves to a string
Public API Custom IntegrationPromise which resolves to a string
  • Usage:
return fakeData.getLastGeneratedValue('first_name'); // "Jackie"

getFakeValue

  • Details:
    • Generate a random value based on the provided field name.
  • Arguments:
    • field name - The name of the field for which Fake Data will generate the value (similar to id or name attribute on an input element).
  • Returns:
    • Will return a Promise that resolves to a string containing the generated value
ContextActual return value
(MV2) Background pagePromise which resolves to a string
(MV2) Foreground pagePromise which resolves to a string
(MV3) Sandbox iframePromise which resolves to a string
Public API Custom IntegrationPromise which resolves to a string
  • Usage:
return fakeData.getFakeValue('i_want_a_full_name'); // may return a full name

fillElement

  • Details:
    • Fills an input element from page
  • Arguments:
    • element - The DOM element from page that should be filled
  • Returns
    • Will return a Promise that resolves to a string containing the generated value
ContextActual return value
(MV2) Foreground pagePromise which resolves to a string
(MV3) Sandbox iframePromise which resolves to a string
Public API Custom IntegrationPromise which resolves to a string
  • Usage:
fakeData.fillElement(document.querySelector('input'));

getGeneratorMatchForElement

  • Details:
    • Get the matching generator name for a DOM element
  • Arguments:
    • element - The DOM element from page
  • Returns
    • Will return a Promise that resolves to a string containing the generator name
ContextActual return value
(MV2) Foreground pagePromise which resolves to a string
(MV3) Sandbox iframePromise which resolves to a string
Public API Custom IntegrationPromise which resolves to a string
  • Usage:
return fakeData.getGeneratorMatchForElement(document.querySelector('input')); // "first_name" 

getUniqueSelector

  • Details:
    • Get the a unique selector string for a DOM element
  • Arguments:
    • element - The DOM element from page
  • Returns
    • Will return string containing the selector. Can also return a Promise that resolves to a string depending on the context on which is called - See the table below.
ContextActual return value
(MV2) Foreground pagestring
(MV3) Sandbox iframePromise which resolves to a string
Public API Custom IntegrationPromise which resolves to a string
  • Usage:
return fakeData.getUniqueSelector(document.querySelector('input')); // ":nth-child(3) > :nth-child(1) > div > input" 

triggerInputChangeEvent

  • Details:
    • Trigger a DOM event on a DOM element
  • Arguments:
    • element - The DOM element from page
    • event name - The DOM event that will be triggered on the element
  • Returns
    • Will true on success. Can also return a Promise which resolves to value true depending on the context on which is called - See the table below.
ContextActual return value
(MV2) Foreground pageboolean
(MV3) Sandbox iframePromise which resolves to a boolean
Public API Custom IntegrationPromise which resolves to a boolean
  • Usage:
fakeData.triggerInputChangeEvent(document.querySelector('button'), 'click'); 

getFillSessionId

  • Details:
    • Retrieves the current fill session id.
    • Fill session ids are unique identifiers that change every time you fill an element, a form, or the entire page. When filling multiple elements at once (like an entire form or an entire page), the session id will be the same for all inputs.
  • Arguments:
    • n/a
  • Returns:
    • Will return a value containing a unique identifier for the fill session
ContextActual return value
(MV2) Background pagestring value
(MV2) Foreground pageint value
(MV3) Sandbox iframePromise which resolves to a string
  • Usage:
return fakeData.getFillSessionId(); // "0-1330726229-204s50uy54n5s"

getFillSessionType

  • Details:
    • Retrieves the type of the current fill session
  • Arguments:
    • fill_session_id (optional) - A previous fill session id (will use the current session id if empty)
  • Returns:
    • Will return a string containing the filled session type
ContextActual return value
(MV2) Background pagestring value
  • Possible return values:

    • single
    • form
    • page
    • multiple-fields
    • preview
  • Usage:

return fakeData.getFillSessionType(); // "form"

getDatasetValue Pro only

  • Details:
    • Retrieves a random value from a Dataset column.
  • Arguments:
    • dataset name - The exact name of the dataset
    • dataset column - The exact column name from the dataset
  • Returns:
    • Will return a string containing a random value from the requested column in the requested dataset
ContextActual return value
(MV2) Background pagestring value
(MV3) Sandbox iframestring value
  • Usage:
return fakeData.getDatasetValue('test dataset', 'First Name'); // "John"