GWT JSNI Variables – An Exhaustive List
- Reference to the root browser window GWT widgets are being rendered to. Note that when called from the iframe linker, GWT code runs in an iframe, not the root browser window, so calling window will reference the wrong window.
- Same as above, but referencing the document, not window. Same as $wnd.document
- The X.Y.Z version of GWT this code was compiled with. Because Google uses the GWT trunk in their apps, they will return 0.0.999.
- The name of the compiled GWT module. Note, you may have assumed this was obfuscated. It’s not.
- The root URL for this module’s entrypoint.
- The MD5 hash for this module.
- Url and port of code server in hosted mode. i.e.
- $hostedHtml Version
- Version of hosted HTML page (hosted.html) in use.This is the page that shows error traces in browser in hosted mode.
- Used when collecting stats in hosted mode. Same value as
- Undocumented. Used to collect stats in hosted mode.
- $stack, $stackDepth, $location
- Undocumented. Trace information used by JsStackEmulator.
Example of accessing GWT Version
To determine the running version of a GWT application, you can use JSNI to return that version.
From outside the application you can walk the DOM of the page to find the iframe containing the running GWT code and access the version like below.
This is the mechanism I used to detect GWT apps in the Library Detector Chrome Extension (Github). Note the wrapping in a try/catch. This is because some iframes are cross domain and will throw a security exception if you try to access them.
Some other explanations:
Window is a class plenty of static methods, which you can use for getting or setting certain properties of the browser window, but actually it is not the native browser window object. These method implementations are eventually
JSNI blocks which use the
$wnd variable to set/get those properties. Like
Window.alert() whose implementation would be
$wnd.alert(). Note that
Window.java doesn’t have access for everything in the browser’s window object like
$wnd instead of
window because compiled code is executed normally in an iframe, and in this context,
window will reference the iframe window while
$wnd will reference the parent window. The same occurs with
$doc which is a reference in the iframe to the parent document.
In the other side
Document is a java class which extends
In summary, although
$doc are not the same in java world, when it is compiled they will be the same, otherwise
Window it’s not an overlay of
$wnd, it is just a way to access certain methods of the browser window.