用一个奇葩方法检测并“崩溃”Chromium爬虫(爬虫哭了)

76 阅读1分钟

前阵子在Chromium的bug列表里刷到一个神奇操作:只用几行JavaScript,就能让Puppeteer、Playwright这些基于Chromium的爬虫直接崩溃。听起来是不是有点狠?方法也超简单,核心代码如下:const iframe = document.createElement("iframe");

iframe.src = "data:text/html,";

document.body.appendChild(iframe);

iframe.contentWindow.open("", "", "top=9999");

在正常浏览器里,没什么事。但在爬虫环境下,直接挂掉。

这招靠谱吗?****

其实不太靠谱。首先,这种方法会弹窗,影响正常用户体验。其次,一旦崩溃,啥数据都收不到,也无法灵活处理。更重要的是,爬虫很快就能修复绕过,反检测永无止境。

function botCheckMate() {
	const iframe = document.createElement("iframe");
	iframe.src = "data:text/html,<body></body>";
	document.body.appendChild(iframe);
	iframe.contentWindow.open("", "", "top=9999");
	
	// After this point, if the code didn't crash, then you're human
	return false;
}

let isBot = botCheckMate();

总结****

这方法确实有趣,适合测试、玩梗。但真要上线,还是建议用更温和、隐蔽的检测方式。毕竟,安静地识别爬虫,比大张旗鼓“开炮”更有效。

最后一句:别让Googlebot碰到这玩意儿,否则SEO直接GG。