-1

When I execute Javascript in Selenium with a python am I then interacting with the website? E.g. if I execute Javascript to go one page back can the website then see this? E.g.

driver.execute_script("window.history.go(-1)")
J. Doe
  • 183
  • 2
  • 9
  • 5
    Why asking instead of trying? – Andrei Suvorkov Jul 15 '18 at 16:08
  • In that regard, Selenium is just like any other browser. If you tell it to go back a page it may just fetch the page from its cache. But a page's meta data may indicate that it must not be pulled from a cache and all accesses must request the latest version from the site. – PM 2Ring Jul 15 '18 at 16:12
  • Possible duplicate of [Running javascript in Selenium using Python](https://stackoverflow.com/questions/7794087/running-javascript-in-selenium-using-python) – Pedro Lobito Jul 15 '18 at 16:14
  • I am asking because I don't know what the website can pick up? – J. Doe Jul 15 '18 at 16:51
  • You can pick up any website, since the point of the question is not depending on the website. Take any website, click on any link on it, then execute script. Profit. It will take max 5 minutes to test. – Andrei Suvorkov Jul 15 '18 at 17:03
  • The script works, my question is whether the website can track that I used javascript to "back one page" and not just a regular back button – J. Doe Jul 15 '18 at 17:10

1 Answers1

0

execute_script executes the code in the browser:

execute_script(script, *args)

Synchronously Executes JavaScript in the current window/frame.

Whether the website sees it depends on what code you provide in script. Some JavaScript will cause a request to be sent to the remote server and some won't.

Community
  • 1
  • 1
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • Will driver.execute_script("window.history.go(-1)")? – J. Doe Jul 15 '18 at 16:40
  • That depends on the browser you're controlling (they may behave differently) and what the previous page in the history is (if it asked not to be cached the browser should re-fetch it from the server, for example). This is really starting to sound like an [XY problem](https://meta.stackexchange.com/q/66377/248627). What are you actually trying to achieve? – ChrisGPT was on strike Jul 15 '18 at 17:11
  • I prefer the website not knowing how I navigate it, thus I want to try and stay as anonymous as possible, therefore I want to make it look as normal as possible – J. Doe Jul 15 '18 at 17:13
  • Wait, what? What does "make it look as normal as possible" mean? How does this have anything to do with anonymity? – ChrisGPT was on strike Jul 15 '18 at 17:14
  • That when you browse you have a fingerprint, I'd prefer to have as normal a fingerprint as possible when i browse google, facebook etc. – J. Doe Jul 15 '18 at 17:22
  • Okay, but what does that have to do with Selenium? – ChrisGPT was on strike Jul 15 '18 at 17:25
  • I usually browse in Selenium, because it is simple to add proxies and I can automate some random stuff I do online, among which is going back one page using the aforementioned script. – J. Doe Jul 15 '18 at 17:26
  • You "browse in Selenium"? Selenium is a tool to automate tasks in existing third-party browsers (it isn't a browser itself). It has _nothing whatsoever_ to do with privacy; it's for automation (usually automated testing). And even if Selenium was about privacy how does your `window.history.go(-1)` come into it? – ChrisGPT was on strike Jul 15 '18 at 17:28
  • Okay, I like using it as a browser, as I have made small scripts that I can use when I browse to download images etc., which makes it easier for me. What comes in is if I use the window.history.go(-1) and the website knows that javascript is being executed then that would very much make my browsing fingerprint unique. As I assume there are not a lot of people browsing with selenium? Sorry for the confusion – J. Doe Jul 15 '18 at 17:35
  • So your question _isn't_ whether running that code will send an HTTP request to the website you're browsing, it's whether the website knows that you did `window.history.go(-1)` instead of clicking on "back"? – ChrisGPT was on strike Jul 15 '18 at 17:36
  • The server will not be able to distinguish between `window.history.go(-1)` and clicking the back button. In both cases you are taking an action _in the browser_ that might generate an HTTP request. The HTTP request will not contain any context about how it was generated in the browser. Note that this has nothing to do with Selenium. – ChrisGPT was on strike Jul 15 '18 at 17:42
  • Awesome, thanks a lot for your help, do you have any recommended reading on this subject? I am obviously not well enough informed on it – J. Doe Jul 15 '18 at 17:47
  • To be honest, it sounds like you want to become a computer power user (understand at a high level how browsers and web servers work) but you're on a computer _programming_ site. In other words, not here. You're probably better served using a browser that's _designed around_ privacy instead of trying to shoe-horn another tool into that role, and spending time on [su] or something. Also, read about the XY problem I linked to before and make sure to ask about what you really want to know (privacy, in this case). [ask] is helpful too. – ChrisGPT was on strike Jul 15 '18 at 18:29