to the portalactivate event window.addEventListener('portalactivate', evt => { // Retrieve the previous page as a <portal> // - The JavaScript state // - UI state // are all saved const portal = evt.adoptPredecessor(); // Append the <portal> to the document }); document.body.append(portal);