The paradox of debugging the Office.initialize and Office.onReady functions is that a debugger can only attach to a process that's running, but these functions run immediately as the add-in's runtime process starts up, before a debugger can attach. In most situations, restarting the add-in after a debugger is attached doesn't help because restarting the add-in closes the original runtime process and the attached debugger and starts a new process that has no debugger attached.
Fortunately, there's an exception. You can debug these functions using Office on the web, with the following steps.
Sideload and run the add-in in Office on the web. This is usually done by opening an add-in's task pane or running a function command. The add-in runs in the overall browser process, not a separate process as it would in desktop Office.
Open the browser's developer tools. This is usually done by pressing F12. The debugger in the tools attaches to the browser process.
Apply breakpoints as needed to the code in the Office.initialize or Office.onReady function.
Relaunch the add-in's task pane or the function command just as you did in step 1. This action does not close the browser process or the debugger. The Office.initialize or Office.onReady function runs again and processing stops on your breakpoints.
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Office Add-ins feedback
Office Add-ins is an open source project. Select a link to provide feedback: