Skip to content
Advertisement

document.querySelectorAll(“body”) returning undefined

I am using the following codes in the console of the firefox DevTools to extract book names from https://bookauthority.org/books/best-problem-solving-books

Code 1

JavaScript

Code 2

JavaScript

Even the following code is not working

JavaScript

It only says undefined. What can I do?

Advertisement

Answer

querySelectorAll works just fine. The problem resides in that the specific webpage on which you’re executing the code, has overriden the window.console.log method and the new implementation apparently does not print arguments to the console, as its native implementation does.

You can see this by issuing window.console.log (without parentheses), which usualy prints something like ƒ log() { [native code] } (at least in Chrome).

There are hacks how to acquire the native implementation. See, for example, this post: https://stackoverflow.com/a/11129588/4005175


Example:

JavaScript
Advertisement