Debug the initialize and onReady functions
Note
This article assumes that you are familiar with Initialize your Office Add-in.
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
orOffice.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
orOffice.onReady
function runs again and processing stops on your breakpoints.
Tip
For more detailed information, see Debug add-ins in Office on the web.
See also
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應