use of net.sourceforge.htmlunit.corejs.javascript.tools.debugger.ScopeProvider in project htmlunit by HtmlUnit.
the class WebClientUtils method attachVisualDebugger.
/**
* Attaches a visual (GUI) debugger to the specified client.
* @param client the client to which the visual debugger is to be attached
* @see <a href="http://www.mozilla.org/rhino/debugger.html">Mozilla Rhino Debugger Documentation</a>
*/
public static void attachVisualDebugger(final WebClient client) {
final HtmlUnitContextFactory cf = ((JavaScriptEngine) client.getJavaScriptEngine()).getContextFactory();
final Main main = Main.mainEmbedded(cf, (ScopeProvider) null, "HtmlUnit JavaScript Debugger");
main.getDebugFrame().setExtendedState(Frame.MAXIMIZED_BOTH);
final SourceProvider sourceProvider = script -> {
String sourceName = script.getSourceName();
if (sourceName.endsWith("(eval)") || sourceName.endsWith("(Function)")) {
// script is result of eval call. Rhino already knows the source and we don't
return null;
}
if (sourceName.startsWith("script in ")) {
sourceName = StringUtils.substringBetween(sourceName, "script in ", " from");
for (final WebWindow ww : client.getWebWindows()) {
final WebResponse wr = ww.getEnclosedPage().getWebResponse();
if (sourceName.equals(wr.getWebRequest().getUrl().toString())) {
return wr.getContentAsString();
}
}
}
return null;
};
main.setSourceProvider(sourceProvider);
}
Aggregations