Skip to content

Plugin Lifecycle

Every Zotero plugin follows a lifecycle, from installation to uninstallation. During this cycle, the plugin triggers a series of "hooks"—points in the plugin's execution where certain actions can be taken.

HookTriggered when...Description
installThe plugin is installed or updatedSet up initial configurations. This hook is only for setup tasks and the plugin isn't running yet.
startupThe plugin is being loadedInitialize everything needed for the plugin to function.
shutdownThe plugin is being unloadedClean up resources before the plugin stops running.
uninstallThe plugin is being uninstalled or replaced by a newer installationPerform cleanup for uninstallation.
onMainWindowLoadThe main Zotero window opens. Can happen multiple times during a session.Initialize UI changes for the main window.
onMainWindowUnloadThe main Zotero window closes. Can happen multiple times during a session.Remove any window-specific changes.

The figure below illustrates the plugin lifecycle and the order in which the hooks are called. The figure below shows the lifecycle of a plugin and how the hooks are called.

lifecycle

💡 Try this out!

Add the following line to the bootstrap.js file's startup() function of the example plugin, then apply the changes and restart Zotero with debug output enabled.

javascript
Zotero.debug("Hello, World! The plugin is loaded.");

Check the debug output to see if the message is printed when the plugin is loaded.

Disable and then enable the plugin in the Plugins Manager to see if the message is printed again.