Orchestrating competing google and Office framework loads

If you are porting an Apps Script add-on to an Office add-in, you may find you'll be dealing with competing load methods if you are using google.load to bring in some google APIS. Office Add-ins like to have the Office framework loaded first, and google.load doesn't work inside that.

It's easy enough to tackle that using Promises. Here's my Office app, loading both the Office framework and google.load. The onloadcallback for google.load resolves a Promise, which is waited for inside the Office.initialize function. That way, I know both frameworks have loaded and initialized before continuing.

(function () {
    // each initialize fights with each other so do them separately and check theyve completed
    var goo = new Promise(function (resolve,reject){
        google.load('visualization', '1.1', { 'packages': ['sankey'] });
        google.setOnLoadCallback(function () {
    Office.initialize = function (reason) {
        // also need the google stuff to have loaded
        goo.then(function() {
            Process.initialize().then(function () {
                // set any listeners
                // chaneg the polling behavior for Office
                // watch for changes

        .catch(function(err) {
            throw err;


The code for this on github.