Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Browsing context #57

Open
togadiyaj opened this issue Feb 4, 2021 · 0 comments
Open

Support for Browsing context #57

togadiyaj opened this issue Feb 4, 2021 · 0 comments

Comments

@togadiyaj
Copy link

togadiyaj commented Feb 4, 2021

Would be great if it supports creating browsing context and tab from it as https://devdocs.io/puppeteer/ does.

try (ChromeDevToolsService parentDevToolService = ChromeServiceExt
.createDevToolsService(chromeService.getVersion().getWebSocketDebuggerUrl())){}

public static ChromeDevToolsService createDevToolsService(String webSocketURL) {
try {
WebSocketService webSocketService = WebSocketServiceImpl.create(new URI(webSocketURL));
CommandInvocationHandler commandInvocationHandler = new CommandInvocationHandler();
Map<Method, Object> commandsCache = new ConcurrentHashMap<>();
ChromeDevToolsService devtools =
(ChromeDevToolsService) ProxyUtils.createProxyFromAbstract(
ChromeDevToolsServiceImpl.class,
new Class[] {WebSocketService.class, ChromeDevToolsServiceConfiguration.class},
new Object[] {webSocketService, new ChromeDevToolsServiceConfiguration()},
(unused, method, args) ->
commandsCache.computeIfAbsent(
method,
key -> {
Class<?> returnType = method.getReturnType();
return ProxyUtils.createProxy(returnType, commandInvocationHandler);
}));
commandInvocationHandler.setChromeDevToolsService(devtools);
return devtools;
}catch(Exception e) {
throw new SnapshotGenerationException("Couldn't create ChromeDevToolsService for chrome webSocketDebuggerUrl ",e);
}
}

 static ChromeTab createTab(ChromeService chromeService, ChromeDevToolsService parentDevToolService,
		String browserContext) {
	ChromeTab tab;
	String targetId = parentDevToolService.getTarget().createTarget(SnapshotGenConstants.ABOUT_BLANK, null, null,browserContext, null, null, null);
	tab = chromeService.getTabs().stream().filter(chromeTab -> chromeTab.getId().equals(targetId))
			.findFirst().get();
	return tab;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant