On some websites, honeypot traps are set up. These mechanisms are intended to lure bots into traps while being unnoticed by actual users.
Links that are included in the HTML code of a website but are invisible to people are some of the most elementary honeypot traps. To determine if a link is visible or not to genuine users, you might want to check its computed style.
Here is a code sample with two functions that will return a list with all the visible links that are on the webpage. The function checks for each link if the background color is the same as the text color. It also has a parameter named strict. That will instruct the function to check if the link is displayed or if it is visible because not all links that are not shown are honeypot traps.
function getComputedBackgroundColor(elem) {
let isTransparent
do {
const bgColor = window.getComputedStyle(elem).backgroundColor
isTransparent = !/rgb\(|[1-9]{1,3}\)'$/.test(bgColor) // you can test this regex on regex101.com
if (isTransparent) {
elem = elem.parentElement
}
} while (isTransparent)
return window.getComputedStyle(elem).backgroundColor
}
function filterLinks(strict) {
let allLinksArray = Array.from(document.querySelectorAll('a[href]'));
console.log('There are ' + allLinksArray.length + ' total links');
let filteredLinks = allLinksArray.filter(link => {
let linkCss = window.getComputedStyle(link);
let isDisplayed = linkCss.getPropertyValue('display') != 'none';
let isVisible = linkCss.getPropertyValue('visibility') != 'hidden';
let computedBgColor = window.getComputedBackgroundColor(link)
let textColor = linkCss.textColor
if (strict) {
if (isDisplayed && isVisible && computedBgColor !== textColor) return link;
} else {
if (computedBgColor !== textColor) return link;
}
});
console.log('There are ' + filteredLinks.length + ' visible links');
}
Typically, honeypot traps are used in combination with tracking systems that can identify automated requests. By doing this, even if future requests don't originate from the same IP, the website will be able to recognize them as being similar.