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 Promisethat resolves to astringcontaining the generated value
 
| Context | Actual return value | 
|---|
| (MV2) Background page | Promisewhich resolves to astring | 
| (MV2) Foreground page | Promisewhich resolves to astring | 
| (MV3) Sandbox iframe | Promisewhich resolves to astring | 
| Public API Custom Integration | Promisewhich resolves to astring | 
return fakeData.getGeneratorValue('first_name'); 
 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 Promisethat resolves to astringcontaining the retrieved value
 
| Context | Actual return value | 
|---|
| (MV2) Background page | Promisewhich resolves to astring | 
| (MV2) Foreground page | Promisewhich resolves to astring | 
| (MV3) Sandbox iframe | Promisewhich resolves to astring | 
| Public API Custom Integration | Promisewhich resolves to astring | 
return fakeData.getLastGeneratedValue('first_name'); 
 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- idor- nameattribute on an input element).
 
- Returns: - Will return a Promisethat resolves to astringcontaining the generated value
 
| Context | Actual return value | 
|---|
| (MV2) Background page | Promisewhich resolves to astring | 
| (MV2) Foreground page | Promisewhich resolves to astring | 
| (MV3) Sandbox iframe | Promisewhich resolves to astring | 
| Public API Custom Integration | Promisewhich resolves to astring | 
return fakeData.getFakeValue('i_want_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 Promisethat resolves to astringcontaining the generated value
 
| Context | Actual return value | 
|---|
| (MV2) Foreground page | Promisewhich resolves to astring | 
| (MV3) Sandbox iframe | Promisewhich resolves to astring | 
| Public API Custom Integration | Promisewhich resolves to astring | 
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 Promisethat resolves to astringcontaining the generator name
 
| Context | Actual return value | 
|---|
| (MV2) Foreground page | Promisewhich resolves to astring | 
| (MV3) Sandbox iframe | Promisewhich resolves to astring | 
| Public API Custom Integration | Promisewhich resolves to astring | 
return fakeData.getGeneratorMatchForElement(document.querySelector('input')); 
 getUniqueSelector
- Details: - Get the a unique selector string for a DOM element
 
- Arguments: - element- The DOM element from page
 
- Returns - Will return stringcontaining the selector. Can also return aPromisethat resolves to astringdepending on the context on which is called - See the table below.
 
| Context | Actual return value | 
|---|
| (MV2) Foreground page | string | 
| (MV3) Sandbox iframe | Promisewhich resolves to astring | 
| Public API Custom Integration | Promisewhich resolves to astring | 
return fakeData.getUniqueSelector(document.querySelector('input')); 
- 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 trueon success. Can also return aPromisewhich resolves to valuetruedepending on the context on which is called - See the table below.
 
| Context | Actual return value | 
|---|
| (MV2) Foreground page | boolean | 
| (MV3) Sandbox iframe | Promisewhich resolves to aboolean | 
| Public API Custom Integration | Promisewhich resolves to aboolean | 
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: 
- Returns: - Will return a value containing a unique identifier for the fill session
 
| Context | Actual return value | 
|---|
| (MV2) Background page | stringvalue | 
| (MV2) Foreground page | intvalue | 
| (MV3) Sandbox iframe | Promisewhich resolves to astring | 
return fakeData.getFillSessionId(); 
 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 stringcontaining the filled session type
 
| Context | Actual return value | 
|---|
| (MV2) Background page | stringvalue | 
- Possible return values: - single
- form
- page
- multiple-fields
- preview
 
- Usage: 
return fakeData.getFillSessionType(); 
 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 stringcontaining a random value from the requested column in the requested dataset
- If the Proversion is not activated, the function returnsnullsince the Dataset feature is not available.
 
| Context | Actual return value | 
|---|
| (MV2) Background page | stringvalue | 
| (MV3) Sandbox iframe | stringvalue | 
return fakeData.getDatasetValue('test dataset', 'First Name'); 
 getCurrentGeneratorLabel
- Details: - Retrieves the name of the generator that called the function.
 
- Returns: - On MV2 will return a stringcontaining the generated name that called the function.
- On MV3 will return a Promisethat resolves to astringcontaining the generated name that called the function.
- Will return null/ a Promise resolving tonullif the function is called from a Custom Code inside a Field.
 
| Context | Actual return value | 
|---|
| (MV2) Background page | stringvalue | 
| (MV3) Sandbox iframe | Promisewhich resolves to astring | 
return fakeData.getCurrentGeneratorLabel();