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:
using selenium somehow ?
compiling new hasFocus() method in chrome JS engine or chromium ? that always return True.
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.
Use setFocus() method of textbox to know the textbox is focused or not.
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.
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.
Try this
document.__proto__.hasFocus = function() {return true}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With