Skip to content

Applies to Cowork 0.1.41 · For everyone who uses Cowork

Lifecycle ​

MAESTROSDK.beforeRefresh(handler) ​

Registers a function that runs before Cowork refreshes this Mini App's tab, for example when the person presses the refresh button. Use it to keep unsaved work: ask, save, or cancel the refresh.

Parameters ​

NameTypeRequiredDescription
handler() => boolean | void | Promise<boolean | void>YesRuns once per refresh. Return false (or a promise that resolves to false) to cancel the refresh. Anything else lets it go ahead

Returns ​

() => void: call it to remove this handler.

Behaviour ​

  • Handlers run one after another, in the order they were added, and each is awaited.
  • The first handler that returns false cancels the refresh. A handler that throws or rejects also cancels it.
  • With no handler, the tab refreshes at once.
  • Only one refresh is handled at a time; a second request while one is running is ignored.
  • A handler that is not a function is ignored, and the returned function does nothing.

Example ​

js
const off = MAESTROSDK.beforeRefresh(async () => {
  if (!form.dirty) return;
  return await MAESTROSDK.confirm({ title: 'Refresh?', message: 'Unsaved changes will be lost.' });
});
// later
off();

For Micromeet Cowork 0.1.41 · build 261111110020