| 80 | |
| 81 | So, what script can you run in the UI process? This UI-side script runs in a separate JS context that has no access to the DOM, no timers, no requestAnimationFrame, no XHR etc. What it can do is run vanilla JavaScript, and access properties and functions on [https://trac.webkit.org/browser/trunk/Tools/WebKitTestRunner/UIScriptContext/Bindings/UIScriptController.idl UIScriptController], which is exposed as uiController. Here's a simple example, using function-like syntax for the inline script, that returns zoom scale: |
| 82 | |
| 83 | {{{ |
| 84 | <script> |
| 85 | testRunner.runUIScript("(function() { return uiController.zoomScale; })()", function(result) { |
| 86 | console.log("Got zoom scale " + result); |
| 87 | }); |
| 88 | </script> |
| 89 | }}} |
| 90 | |
| 91 | Because testRunner.runUIScript() is asynchronous, the caller has to supply a callback function. The string result returned by the UI process script is passed to this callback function as an argument. You can use this to return simple bits of data as strings, or use JSON.stringify() in the UI script, and JSON.parse() in the test script to get more complex objects across the process boundary. |