NFC with Custom Scripts in TheFlex
Introduction: NFC in TheFlex – Overview & Typical Use Cases
With integrated NFC functionality in TheFlex, you can significantly simplify and accelerate common workflows, especially in industrial environments. NFC-based processes allow fast, contactless, and convenient transfer and reading of important data.
Typical use cases include:
- Fast device login (e.g., at manufacturing terminals, production lines or kiosks)
- Automated form filling
- Access control for machines or rooms via individual NFC chips
- Confirmation of process steps or checks with a chip swipe
- Contactless reading of employee badges
Writing Login Data to Your NFC Chip in TheFlex
Note:
The built-in NFC Writer tool in TheFlex can be found under Settings > Useful Tools > NFC Writer.
This small writer tool is mainly intended for testing purposes and simple use cases.
TheFlex is specifically designed for reading NFC tags and using the data for browser automation workflows.For professional and secure writing of login data to NFC tags, we recommend using dedicated apps or tools with advanced configuration and security—especially for encrypted storage.
Warning:
For security reasons, passwords should never be stored on NFC chips in plain text, especially in production environments!
Always use encryption to protect sensitive data and choose specialized, secure NFC writer solutions for critical use cases.
To store login data on an NFC chip using TheFlex, proceed as follows:
- Navigate to Settings > Useful Tools > NFC Writer.
- Select text/pg from the dropdown menu.
- Enter your email address or username in the first input field.
- Enter your password in the second input field.
- Hold your NFC chip to the back of your device until it vibrates.
- Tap the blue button to write the data onto the NFC chip.
If no error message appears, you can return and open the NFC Reader. Again, select text/pg from the dropdown menu. Hold the chip to your device—your previously saved information should now be displayed.
Creating a Custom Script to Read the NFC Chip
To ensure that the script is only executed on the intended login page, the exact URL should be specified.
Below is an example of an automated NFC login script for Microsoft. Once the NFC chip is read, the login process will automatically proceed:
document.addEventListener("deviceready", function() {
function showNFCData(username, password) {
alert("Username: " + username + "\nPassword: " + password);
var emailInput = document.querySelector('input[type="email"]');
var checkEmailInterval;
if (emailInput) {
var emailAddress = username.toLowerCase();
emailInput.value = emailAddress;
emailInput.blur();
checkEmailInterval = setInterval(function() {
var emailConfirmationButton = document.querySelector('button, input[type="submit"]');
if (emailConfirmationButton) {
clearInterval(checkEmailInterval);
emailConfirmationButton.click();
checkPassword(password);
}
}, 1000);
}
}
function checkPassword(userPassword) {
var checkPasswordInterval = setInterval(function() {
var passwordInput = document.querySelector('input[type="password"]');
if (passwordInput) {
var confirmationButton = document.querySelector('input[type="submit"]');
if (confirmationButton) {
passwordInput.value = userPassword;
passwordInput.blur();
clearInterval(checkPasswordInterval);
confirmationButton.click();
}
}
}, 1000);
}
function checkCheckbox() {
var checkCheckboxInterval = setInterval(function() {
var confirmationCheckbox = document.querySelector('input[type="checkbox"]');
if (confirmationCheckbox) {
clearInterval(checkCheckboxInterval);
confirmationCheckbox.checked = true;
var backButton = document.getElementById('idBtn_Back');
if (backButton) {
backButton.focus();
backButton.click();
}
}
}, 1000);
}
checkCheckbox();
nfc.addNdefListener(
function (nfcEvent) {
var message = nfcEvent.tag.ndefMessage;
var usernamePayload = message[0];
var username = nfc.bytesToString(usernamePayload.payload).toLowerCase();
var password = "";
if (message.length > 1) {
var passwordPayload = message[1];
password = nfc.bytesToString(passwordPayload.payload);
}
showNFCData(username, password);
},
function () {
console.log('Scan failed');
}
);
});