question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

window.chrome object not available in "headless" mode

See original GitHub issue

Perhaps this is not the correct place for this (I’ve also filed this bug: https://bugs.chromium.org/p/chromium/issues/detail?id=806333 but I wasn’t sure where to dig in.

I’m finding that when I run my Nightwatch tests with Chrome in “headless” mode, that certain odd tests are failing consistently that pass when run “not in headless” mode. Upon digging in, it appears that the window.chrome and/or chrome objects are not available/present to webpages loaded in “headless” mode.

This is a problem for us because some of the things we test for are dependent on whether or not a User’s browser as window.chrome && window.chrome.webstore, which should both be truthy in any version of Chrome, headless or not I would think.

Is this expected behavior? Anything that can be done?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
aslushnikovcommented, Jan 31, 2018

This is a problem for us because some of the things we test for are dependent on whether or not a User’s browser as window.chrome && window.chrome.webstore, which should both be truthy in any version of Chrome, headless or not I would think.

@newhouse the absence of window.chrome is an implication of headless architecture.

Chromium consists of layers:

image

A few things on this diagram are important:

  • content layer is the API to build “browsers”. So if you’re building a browser, you’re embedding content.
  • Chromium is a browser and a typical content embedder. A lot of Chromium functionality, e.g. extensions and window.chrome, lives in the chrome layer
  • headless is, in fact, another browser - a different content embedder. Since extensions are in the chrome layer, they’re naturally missing in the headless browser.

Hope this helps.

1reaction
JoelEinbindercommented, Jan 30, 2018

Look into how puppeteer does evaluateOnNewDocument: https://github.com/GoogleChrome/puppeteer/blob/master/lib/Page.js#L658

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not able to locate element when running chrome in headless ...
However when I run chrome in headless mode, it is not able to locate the checkbox which is to be clicked to download...
Read more >
window.chrome.runtime not available in chrome driver.
Open the console in this chrome session and enter window.chrome.runtime, this doesn't seem to be available. If you open a regular chrome window, ......
Read more >
It is *not* possible to detect and block Chrome headless - Intoli
In a non-headless browser, the window.chrome object looks something like this (keep in mind that the Web Extensions API is not available in...
Read more >
What is Google Chrome Headless Mode - Debug Bar
The Headless mode is a feature which allows the execution of a full version of the Chrome Browser. It provides the ability to...
Read more >
Getting Started with Headless Chrome - Chrome Developers
--headless \ # Runs Chrome in headless mode. --disable-gpu \ # Temporarily needed if running on Windows. ... https://www.chromestatus.com # URL to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found