I am writing a program in Java where I need to clear the cookies in the Safari browser. Is there a way to do this using Java? Or do I need to write a console script and run it from my program? I am using a MacBook Pro running Sierra (10).
Asked
Active
Viewed 127 times
1 Answers
0
First, "using Java" is a bit vague -- is it a JSP, an applet, or Java application? The type of context controls what can be done. A web app can delete it's own cookies, but there is no direct API to clear cookies using Java. There isn't, as far as I know, a macOS command line either. There may be a way in Objective C -- I'm not an Objective C expert -- you would have to figure out how to wrap the Objective C with Java. Deleting cookies with Objective C is discussed in this article:
How do I clear the browser cache programmatically on the iPhone?

CrankyElderGod
- 403
- 4
- 10
-
Sorry for not being clear. I'm writing a Java application. I'm using the Robot class to login to my accounts on a website and perform some tasks by moving the mouse and clicking/typing. I need to clear the cookies/cache so I can login to another account. The site doesn't like when you log into several accounts in a short period of time. And just an FYI... I'm NOT using this to try to hack accounts. These are all my own accounts. I'm just trying to automate something I do manually. I guess if there's no easy way to do this, I can always write code to click the menus to clear the cache/cookies. – M. Giuliano Aug 27 '17 at 11:45