Reputation: 17
I would like to know any java method can be used to check if the browser is closed.
I used the following code to open a default browser:
if(Desktop.isDesktopSupported()){
Desktop desktop = Desktop.getDesktop();
desktop.browse(new URI(url));
}
Then I want to perform some user actions on the opened website to capture the web traffic. After the browser is closed the web traffic will be saved.
So how can I determine if the browser is closed by using java code?
Upvotes: 1
Views: 1603
Reputation: 776
The best you can do is use Process builder:
public class Main {
public static void main(String[] args) {
try {
ProcessBuilder pb = new ProcessBuilder("C:\\Windows\\System32\\calc.exe");
Process p1 = pb.start();
p1.waitFor();
System.out.println(p1.exitValue());
} catch (Exception e) {
System.out.print(e);
}
}
}
You can launch a browser with the webpage as an argument and keep track of it like that.
Upvotes: 1