首页 > 解决方案 > How to catch google chrome audit lighthouse

问题描述

How can I catch in Javascript a user running an Audit from Lighthouse in my website?

I'd like to see if there is a possibility, out of curiosity.

Edit:

Based on @DBS answer, I'd like to see that If I can catch it during the process

    <script>
        if (navigator.userAgent.indexOf("Chrome-Lighthouse") > -1) {
            document.body.innerHTML = "Lighthouse!";
        } else {
            document.body.innerHTML = "No lighthouse :("
        }
    </script>

enter image description here

标签: javascriptgoogle-chrome

解决方案


如果通过“捕获”,您只是意味着检测它。Lighthouse 进程包括一个自定义用户代理。

在用户代理中搜索字符串Chrome-Lighthouse

例如

if (navigator.userAgent.indexOf("Chrome-Lighthouse") > -1) {
  console.log("Lighthouse!");
} else {
  console.log("No lighthouse :(")
}

我不相信在与进程交互的调试意义上“捕捉”是可能的。


推荐阅读