Home

JavaScript API

The JavaScript API allows you to create an HTML/JavaScript application that has access to the native windowing environment, can communicate with other applications and has access to sandboxed system-level features.

API Ready

When using the OpenFin API, it is important to ensure that it has been fully loaded before making any API calls. To verify that the API is in fact ready, be sure to make any API calls either from within the fin.desktop.main() method or explicitly after it has returned. This avoids the situation of trying to access methods that are not yet fully injected.

Overview

When running within the OpenFin Runtime your web applications have access to the "fin" namespace and all the modules within the API without the need to include additional source files. You can treat the "fin" namespace as you would the "window", "navigator" or "document" objects.

Example

<!DOCTYPE html>
    <head>
        <style>
            #status-indicator {
              display: inline-block;
              height: 10px;
              width: 10px;
              background-color: red;
              border-radius: 20px;
            }
            #status-indicator.online {
              background-color: green;
            }
        </style>
        <script type="text/javascript">
        document.addEventListener('DOMContentLoaded', () => {
            //OpenFin is ready
            fin.desktop.main(() => {
                //Update the status Indicator.
                document.querySelector('#status-indicator').classList.toggle("online");

                //get the current version.
                fin.desktop.System.getVersion(version => {
                    document.querySelector('#of-version').innerText = version;
                });
            });
        });
        </script>
    </head>
    <body>
        <p>
            OpenFin adapter <span id="of-version"></span>
            Ready: <span id="status-indicator"></span>
        </p>
    </body>
</html>