The user agent string includes HeadlessChrome instead of Chrome. This is probably the signal that you’re intended to look for, so you could use:
/\bHeadlessChrome\//.test(navigator.userAgent)
Other interesting signals include:
- It looks like
window.chromeis undefined when headless. [innerWidth, innerHeight]is[800, 600](hardcoded inheadless_browser.cc), while[outerWidth, outerHeight]is[0, 0](which shouldn’t usually happen).