pageBeforeRemove is the last moment the page element exists. Undo there whatever pageInit set up that outlives it: window and document listeners, timers, observers, and widgets from app.*.create(), such as the Actions sheet, whose element lives in the app root:
$on('pageBeforeRemove', () => {
sheet.destroy();
window.removeEventListener('online', onNetwork);
window.removeEventListener('offline', onNetwork);
});With the handler deleted, books 1, 2 and 3 were opened with Back in between, then Playwright 26,280 went offline with context.set_offline(True):
--- go offline
5 ms book 1 handles "offline"
5 ms book 2 handles "offline"
5 ms book 3 handles "offline"Two removed pages still ran handlers and stayed in memory; with the cleanup, only book 3 printed. Components can also use $onBeforeUnmount.