Extending Fake Data


Writing Custom Generators is the best way to extend Fake Data and set it up to fill the forms in any way you want. In the following tutorials you will see how easy it is to create a Custom Generator and how powerful Fake Data can be.

MV2 vs MV3

In the upcoming examples and explanations, there will be many occurrences of the terms "MV2" and "MV3". MV stands for Manifest Version, which is the API version that the browser offers for extensions to interact with it.

At this time, Fake Data runs on MV2 (Manifest Version 2) on Firefox and Edge, and on MV3 on Chrome. Below is a table where you can see which Manifest version is used based on Fake Data version and browser.

Fake Data versionBrowserManifest version
Starting with 4.9.0ChromeMV3
Up to 4.8.5ChromeMV2

How is the code executed

There are a few ways that Fake Data executes the code that you write, and it would be useful to know about them.

In MV3 version of Fake Data:

The code is executed in a sandboxed iframe. Your code will not have direct access to DOM elements, but an API for that is provided to make your life easier.

In MV3 version, you don't have access to any of the chrome.* API methods, in case you were using them for something (there are very high chances that you weren't using them).

In MV2 version of Fake Data:

By default, the code is executed in the background script of the extension. This means that you don't have direct access to DOM elements, but you can return a function that will be executed in the content script (this will be described later).

Functions that are executed in the content script of the extension, will have direct access to DOM elements, so you can manipulate them directly.

In MV2 version, you will also have direct access to chrome.* API.

Enough talking, let's see exactly how to write code for Fake Data!