Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I change the document method of javascript: hasFocus() to return 'true' all the time?

I am trying to fool this specific code:

<!DOCTYPE html>
<html>
<body>

<p>Click anywhere in the document (the right frame) to get focus. If you click outside the document, it will lose focus.</p>

<p id="demo"></p>

<script>
setInterval("myFunction()", 1);

function myFunction() {
    var x = document.getElementById("demo");
    if (document.hasFocus()) {
        x.innerHTML = "The document has focus.";
    } else {
        x.innerHTML = "The document DOES NOT have focus.";
    }
}
</script>

</body>
</html>

So even when I am not foreground application in Chrome it will return True. Solutions I thought of:

  1. using selenium somehow ?

  2. compiling new hasFocus() method in chrome JS engine or chromium ? that always return True.

like image 446
Sion C Avatar asked Apr 25 '18 15:04

Sion C


People also ask

How do I use hasFocus?

hasFocus() The hasFocus() method of the Document interface returns a boolean value indicating whether the document or any element inside the document has focus. This method can be used to determine whether the active element in a document has focus.

How do you know if a textbox has focused?

Use setFocus() method of textbox to know the textbox is focused or not.

How do you know if an element is focused?

Compare document. activeElement with the element you want to check for focus. If they are the same, the element is focused; otherwise, it isn't.

How do I know if my window is in focus?

Use the document. hasFocus() method to check if a window has focus, e.g. if (document. hasFocus()) {} . The method returns a boolean value indicating whether the document or any element in the document has focus.


1 Answers

Try this

document.__proto__.hasFocus = function() {return true}
like image 121
M1X Avatar answered Sep 17 '22 22:09

M1X