Skip to content

Commit

Permalink
Set navigator.webdriver to true in page's context when playing a test…
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Shekyan committed Jul 23, 2018
1 parent 28c6189 commit 04b0148
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/content/selenium-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ function Selenium(browserbot) {
}
});
}
window.postMessage({
direction: "from-content-setnavigatorwebdriver"
}, "*");
}

Selenium.DEFAULT_TIMEOUT = 30 * 1000;
Expand Down
26 changes: 19 additions & 7 deletions src/page/runScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,24 @@ window.onerror = function(msg){
}
};
window.addEventListener("message", function(event) {
if (event.source == window && event.data && event.data.direction == "from-content-runscript") {
isWanted = true;
var doc = window.document;
var scriptTag = doc.createElement("script");
scriptTag.type = "text/javascript"
scriptTag.text = event.data.script;
doc.body.appendChild(scriptTag);
if (event.source == window && event.data) {
switch (event.data.direction) {
case "from-content-runscript":
isWanted = true;
var doc = window.document;
var scriptTag = doc.createElement("script");
scriptTag.type = "text/javascript";
scriptTag.text = event.data.script;
doc.body.appendChild(scriptTag);
break;
case "from-content-setnavigatorwebdriver":
Object.defineProperty(navigator, 'webdriver', {
get: function () { return true },
enumerable: true,
configurable: true
});
break;
default:
}
}
});

0 comments on commit 04b0148

Please sign in to comment.