/** Executes a code inside of provided {@link WebView}. This method * associates the {@link BrwsrCtx execution context} with provided browser, * so the {@link JavaScriptBody} annotations know where to execute * their JavaScript bodies. * The code is going to be executed synchronously * in case {@link Platform#isFxApplicationThread()} returns <code>true</code>. * Otherwise this method returns immediately and the code is executed * later via {@link Platform#runLater(java.lang.Runnable)}. * <p> * This method relies on {@link WebView#getUserData()} being properly * provided by the <code>load</code> methods in this class. * * @param webView the web view previously prepared by one of the <code>load</code> * methods in this class * @param code the code to execute * @throws IllegalArgumentException if the web view was not properly * initialized * @see BrwsrCtx#execute(java.lang.Runnable) * @since 0.8.1 */ public static void runInBrowser(WebView webView, Runnable code) { Object ud = webView.getUserData(); if (!(ud instanceof InitializeWebView)) { throw new IllegalArgumentException(); } ((InitializeWebView)ud).runInContext(code); } }