Skip to main content

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.

caution

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:

  1. Navigate to Settings > Useful Tools > NFC Writer.
  2. Select text/pg from the dropdown menu.
  3. Enter your email address or username in the first input field.
  4. Enter your password in the second input field.
  5. Hold your NFC chip to the back of your device until it vibrates.
  6. 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');
}
);
});

FAQ

On a regular desktop-style web page, can we extract and display only the required fields in the TheFlex Browser?

Yes, it is possible to selectively extract specific fields from a web page using custom scripts. With JavaScript, you can target elements by their ID or class, retrieve their values, and display only the relevant fields in the TheFlex Browser’s interface.

Can custom scripts work effectively on dynamic pages, such as those built with AJAX?

Yes, custom scripts can also be utilized on dynamic pages. By using approaches like Mutation Observers, event listeners, or periodic checks (e.g., setInterval), scripts can respond to dynamically loaded or updated DOM elements, ensuring your logic runs at the appropriate time.

Can features like NFC or OCR be triggered automatically when a user clicks on specific input fields or buttons, without needing to modify the original web page?

Yes, using custom scripts, you can add event listeners (e.g., for clicks on elements with specific IDs) to trigger actions such as starting an NFC scan or OCR processing. This can be accomplished without changing the source code of the original page.

What security considerations should be taken into account when storing login data on NFC chips?

NFC chips generally store data unencrypted. It is recommended to encrypt sensitive information and, where possible, only store it temporarily on the chip. Appropriate permissions and secure handling should be ensured.

Are access logs or error reports available to trace issues with NFC transactions?

Depending on the implementation, logs and error reports can be enabled for troubleshooting. This helps to track processes and identify possible sources of errors during operation.

What happens if an NFC tag is damaged or incompatible?

The script can detect errors when reading or writing and provide respective messages. It is advisable to include proper error handling and compatibility checks in the implementation.