I wish to use a class that provides the option to get all open tabs. Unfortunately, I can only find code in js and other.. and I don't really know how to use it in my Java code..
Asked
Active
Viewed 1,375 times
2
-
What do you mean *to get all open tabs* ? – ortis Oct 29 '14 at 12:39
-
For example: You open the chrome browser and enter google.com & youtube.com in 2 different tabs, I wish to make a list: – Eureka Oct 29 '14 at 12:50
-
The only way seems to implement a Chrome extension and use "native messaging". See https://github.com/vakho10/Native-Messaging for an example project. – koppor Mar 20 '18 at 19:57
-
It is also possible using Selenium: https://stackoverflow.com/a/43787744/873282 – koppor Mar 20 '18 at 19:59
2 Answers
1
A dirty solution:
From Java, you can send keyboard event (see Robot
class). So you could emulate Ctrl+1 to switch to the first tab (Ctrl+2 to second tab and so on), then Ctrl+L to highlight the URL and Ctrl+C to copy it in the clipboard. Then acess the clipboard content from java :
Toolkit toolkit = Toolkit.getDefaultToolkit();
Clipboard clipboard = toolkit.getSystemClipboard();
String url= (String) clipboard.getData(DataFlavor.stringFlavor);

ortis
- 2,203
- 2
- 15
- 18
0
There is no way to find browser physical details with Java other than the request headers. You Cannot.
On the other hand you can send the info you found with Javascript to server(Java) through a request.

Suresh Atta
- 120,458
- 37
- 198
- 307