Blog ยท
How to mask the same data automatically with DataMask Scripts
If you hide the same names and numbers on the same website before every demo, you can stop doing it by hand. DataMask can save a mask as a script and run it every time that website loads. Scripts have been in the extension since version 2.5 and we never wrote about them, so here is how they work.
What a script is
A script is one saved rule with two parts: what to find on the page and what to do with it.
- What to do is an action you already know from DataMask: Scramble, Blur, Blur+ or Edit, which replaces the text with your own.
- What to find is a selector. It can be a CSS selector, a text pattern or an XPath.
Scripts are kept per website. They are saved in your browser's storage for that website and are not sent to DataMask.
Scripts are a Pro feature, so you need a Pro license or the free 7 day trial.
Open the Scripts panel
Open DataMask on a page and click Scripts in the bar.
The browser's side panel opens. It shows the current website, a Run on load switch and the scripts saved for that website.
Two ways to create a script
Click on the page
Turn on Persist in the bar, choose Manual, click an element and pick Blur, Blur+, Scramble or Edit. DataMask saves each of these as a script for the website, and it shows up in the panel. This is the quickest way to cover one particular element, such as the account name in a page header.
Write a rule in the panel
A rule can cover many elements at once. Click Create New Script, then:
- Choose the Action. For Edit/Replace, also type the replacement text.
- Choose the Selector Type and type the Selector Query.
- Click Test. DataMask outlines every match on the page in red and tells you how many it found.
- Click Save.
Three kinds of selector
- CSS Selector matches every element the selector finds.
.demo-table td:nth-child(2)matches every cell in the second column of a table. - Text Regex matches every element whose text fits a pattern, ignoring upper and lower case.
\(\d{3}\) \d{3}-\d{4}matches phone numbers written like (415) 555-0132. The whole element is masked, not only the characters that match. - XPath matches one element, the first one the path leads to. This is the kind DataMask writes itself when you click on the page.
These examples come from our demo page, where every record is made up, so you can try them there.
Run on load
Scripts run on their own only when Run on load is on for the website. It is the same setting as Persist in the bar. While it is on:
- The scripts run each time a page of that website loads. The page stays hidden until they have been applied, so the real values don't flash on screen.
- DataMask keeps watching the page and masks new content as it appears, for example when you scroll a long list or move between views inside an app.
With Run on load off, your scripts stay saved but the page loads unmasked. They are applied when you open DataMask on the page.
Share scripts and back them up
- Export downloads the website's scripts as a JSON file. Import loads such a file and replaces the scripts the website has now. Send the file to a colleague and you both mask the same things.
- Backup stores the website's scripts in your browser's sync storage, and Restore brings them back. This also works on another computer where you use the same browser profile with sync turned on. Sync storage is small, so a very long list may not fit.
- Edit and Delete change a single script. Clear Domain Scripts removes all of them for the website.
Undo all in the DataMask bar also deletes the website's scripts, so export them first if you want to keep them.
Good to know
- Auto, blur rectangles you draw, text size changes and removed elements are not saved as scripts.
- A CSS selector or a text pattern masks every match, so use Test before you save.
- Scripts depend on how a page is built. If a website changes its layout, a selector may stop matching and you will need to update it. For scripts made by clicking, DataMask also remembers the start of the element's text and uses it to find the element again if it has moved.
Try it
Scripts are part of DataMask Pro. You can try Pro free for 7 days: open DataMask, click Try Pro and sign in. The demo page is a safe place to practice.
If you have questions about Scripts or want to report a bug, please reach out via email: support@datamask.tech.