@elliemae/ssf-host 2.25.3 → 2.25.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/host.js CHANGED
@@ -1249,30 +1249,574 @@ class SSFHost {
1249
1249
  this.#logger.debug("Dispatched config events to all guests");
1250
1250
  };
1251
1251
  /**
1252
- * unloads guest application from host
1253
- * @param guestIdOrWindowOrEle unique id of the guest application or window object or dom element of the guest application
1254
- * @throws Error if guestId or Window reference is invalid
1252
+ * Call cleanup function on guest window.emui
1253
+ * @param {object} options - Cleanup options
1254
+ * @param {any} options.guestEmui - The window.emui object
1255
+ * @param {string} options.cleanupFunctionName - Function name to call
1256
+ * @param {string} options.context - Context for logging
1255
1257
  */
1256
- unloadGuest = (guestIdOrWindowOrEle) => {
1258
+ #callGuestCleanupFunction = (options) => {
1259
+ const { guestEmui, cleanupFunctionName, context } = options;
1260
+ const emuiObj = guestEmui;
1261
+ const cleanupFn = emuiObj[cleanupFunctionName];
1262
+ if (typeof cleanupFn !== "function") {
1263
+ return;
1264
+ }
1265
+ try {
1266
+ cleanupFn();
1267
+ this.#logger.debug(
1268
+ `[SSF] Called window.emui.${String(cleanupFunctionName)}() for ${String(
1269
+ context
1270
+ )}`
1271
+ );
1272
+ } catch (e) {
1273
+ this.#logger.warn(
1274
+ `[SSF] emui.${String(cleanupFunctionName)}() threw error for ${String(
1275
+ context
1276
+ )}: ${e.message}`
1277
+ );
1278
+ } finally {
1279
+ guestEmui[cleanupFunctionName] = null;
1280
+ }
1281
+ };
1282
+ /**
1283
+ * Null window.emui.app properties
1284
+ * @param {Record<string, unknown> | unknown} app - The window.emui.app object
1285
+ */
1286
+ #nullAppProperties = (app) => {
1287
+ if (typeof app !== "object" || app === null) {
1288
+ return;
1289
+ }
1290
+ const appObj = app;
1291
+ appObj.init = null;
1292
+ appObj.mount = null;
1293
+ appObj.unmount = null;
1294
+ appObj.getRef = null;
1295
+ appObj.navigate = null;
1296
+ };
1297
+ /**
1298
+ * Null all window.emui properties
1299
+ * @param {Record<string, unknown> | unknown} guestEmui - The window.emui object
1300
+ */
1301
+ #nullEmuiProperties = (guestEmui) => {
1302
+ if (typeof guestEmui !== "object" || guestEmui === null) {
1303
+ return;
1304
+ }
1305
+ const emuiObj = guestEmui;
1306
+ if (emuiObj.app) {
1307
+ this.#nullAppProperties(emuiObj.app);
1308
+ emuiObj.app = null;
1309
+ }
1310
+ emuiObj.registerApp = null;
1311
+ emuiObj.logRocket = null;
1312
+ emuiObj.getEnvironment = null;
1313
+ emuiObj.loadScript = null;
1314
+ emuiObj.loadStylesheet = null;
1315
+ emuiObj.unmount = null;
1316
+ };
1317
+ /**
1318
+ * Disconnect FieldMutation observer for iframe
1319
+ * @param {Window | null} contentWindow - The iframe contentWindow
1320
+ * @param {string} guestId - Guest ID for logging
1321
+ */
1322
+ #disconnectFieldMutationObserver = (contentWindow, guestId) => {
1323
+ try {
1324
+ const bodyElement = contentWindow?.document?.body;
1325
+ if (!bodyElement) return;
1326
+ const { observerReferences } = window;
1327
+ if (!observerReferences || !(observerReferences instanceof Map)) {
1328
+ return;
1329
+ }
1330
+ if (!observerReferences.has(bodyElement)) return;
1331
+ const observer = observerReferences.get(bodyElement);
1332
+ if (observer && typeof observer.disconnect === "function") {
1333
+ observer.disconnect();
1334
+ observerReferences.delete(bodyElement);
1335
+ this.#logger.debug(
1336
+ `[SSF] Disconnected FieldMutation observer for guest ${guestId}`
1337
+ );
1338
+ }
1339
+ } catch (e) {
1340
+ this.#logger.debug(
1341
+ `[SSF] Failed to disconnect FieldMutation observer for guest ${guestId}: ${e.message}`
1342
+ );
1343
+ }
1344
+ };
1345
+ /**
1346
+ * Close contentWindow explicitly
1347
+ * @param {Window | null} contentWindow - The iframe contentWindow
1348
+ * @param {string} guestId - Guest ID for logging
1349
+ */
1350
+ #closeContentWindow = (contentWindow, guestId) => {
1351
+ try {
1352
+ if (!contentWindow || contentWindow.closed) return;
1353
+ contentWindow.close();
1354
+ this.#logger.debug(
1355
+ `[SSF] Called contentWindow.close() for guest ${guestId}`
1356
+ );
1357
+ } catch (e) {
1358
+ this.#logger.debug(
1359
+ `[SSF] contentWindow.close() failed for guest ${guestId}: ${e.message}`
1360
+ );
1361
+ }
1362
+ };
1363
+ /**
1364
+ * Navigate iframe to about:blank
1365
+ * @param {HTMLIFrameElement} iframe - The iframe element
1366
+ * @param {string} guestId - Guest ID for logging
1367
+ */
1368
+ #navigateToBlank = (iframe, guestId) => {
1369
+ try {
1370
+ if (!iframe.parentNode) return;
1371
+ iframe.src = "about:blank";
1372
+ this.#logger.debug(`[SSF] Navigated to about:blank for guest ${guestId}`);
1373
+ } catch (e) {
1374
+ this.#logger.debug(
1375
+ `[SSF] Navigation to about:blank failed for guest ${guestId}: ${e.message}`
1376
+ );
1377
+ }
1378
+ };
1379
+ /**
1380
+ * Cleanup window.elli.script properties
1381
+ * @param {Window} guestWindow - Guest window
1382
+ * @param {string} context - Context string for logging
1383
+ */
1384
+ #cleanupElliScript = (guestWindow, context) => {
1385
+ try {
1386
+ const windowWithElli = guestWindow;
1387
+ const { elli } = windowWithElli;
1388
+ if (elli?.script && typeof elli.script === "object") {
1389
+ const { script } = elli;
1390
+ if (script && script.guest && typeof script.guest === "object") {
1391
+ const { guest } = script;
1392
+ const guestObj = guest;
1393
+ guestObj.create = null;
1394
+ }
1395
+ if (script) {
1396
+ script.guest = null;
1397
+ script.connect = null;
1398
+ script.getObject = null;
1399
+ script.setLogLevel = null;
1400
+ script.subscribe = null;
1401
+ script.unsubscribe = null;
1402
+ elli.script = null;
1403
+ }
1404
+ this.#logger.debug(
1405
+ `[SSF] Nulled all window.elli.script properties for ${context}`
1406
+ );
1407
+ }
1408
+ } catch (e) {
1409
+ this.#logger.debug(
1410
+ `[SSF] Failed to cleanup window.elli: ${e.message}`
1411
+ );
1412
+ }
1413
+ };
1414
+ /**
1415
+ * Clear Google Tag Manager data layer
1416
+ * @param {Window} guestWindow - Guest window
1417
+ * @param {string} context - Context string for logging
1418
+ */
1419
+ #clearGtmDataLayer = (guestWindow, context) => {
1420
+ try {
1421
+ const windowWithGtm = guestWindow;
1422
+ if (windowWithGtm.gtmDataLayer) {
1423
+ windowWithGtm.gtmDataLayer = null;
1424
+ this.#logger.debug(`[SSF] Cleared gtmDataLayer for ${context}`);
1425
+ }
1426
+ } catch (e) {
1427
+ this.#logger.debug(
1428
+ `[SSF] Failed to cleanup GTM data layer: ${e.message}`
1429
+ );
1430
+ }
1431
+ };
1432
+ /**
1433
+ * Cleanup window.emui properties
1434
+ * @param {unknown} guestEmui - Guest window.emui object
1435
+ * @param {string} context - Context string for logging
1436
+ */
1437
+ #cleanupEmuiProperties = (guestEmui, context) => {
1438
+ try {
1439
+ if (typeof guestEmui === "object" && guestEmui !== null) {
1440
+ this.#nullEmuiProperties(guestEmui);
1441
+ }
1442
+ this.#logger.debug(
1443
+ `[SSF] Nulled all window.emui properties for ${context}`
1444
+ );
1445
+ } catch (e) {
1446
+ this.#logger.debug(
1447
+ `[SSF] Failed to cleanup window.emui: ${e.message}`
1448
+ );
1449
+ }
1450
+ };
1451
+ /**
1452
+ * Cleanup guest window context - nulls all window.emui and window.elli.script properties
1453
+ * This breaks closure retention chains and allows GC of webpack bundles, SDKs, and singletons
1454
+ * @param {object} options - Cleanup options
1455
+ * @param {Window | null} options.guestWindow - The guest window
1456
+ * @param {string} options.guestId - Guest ID for logging
1457
+ * @param {string} options.cleanupFunctionName - Cleanup function name
1458
+ * @param {string} options.windowType - Window type for logging
1459
+ */
1460
+ #cleanupGuestWindow = (options) => {
1461
+ const {
1462
+ guestWindow,
1463
+ guestId,
1464
+ cleanupFunctionName,
1465
+ windowType = "iframe"
1466
+ } = options;
1467
+ if (!guestWindow) {
1468
+ this.#logger.debug(
1469
+ `No ${windowType} window available for cleanup of guest ${guestId}`
1470
+ );
1471
+ return;
1472
+ }
1473
+ const context = `${windowType} ${guestId}`;
1474
+ try {
1475
+ const windowWithEmui = guestWindow;
1476
+ const guestEmui = windowWithEmui.emui;
1477
+ if (!guestEmui) {
1478
+ this.#logger.debug(`No window.emui found for ${context}`);
1479
+ return;
1480
+ }
1481
+ this.#callGuestCleanupFunction({
1482
+ guestEmui,
1483
+ cleanupFunctionName,
1484
+ context
1485
+ });
1486
+ this.#cleanupEmuiProperties(guestEmui, context);
1487
+ this.#cleanupElliScript(guestWindow, context);
1488
+ this.#clearGtmDataLayer(guestWindow, context);
1489
+ } catch (e) {
1490
+ this.#logger.debug(
1491
+ `[SSF] Could not access ${windowType} window for cleanup (guest ${guestId}): ${e.message}`
1492
+ );
1493
+ }
1494
+ };
1495
+ /**
1496
+ * Navigate to parent of target property
1497
+ * @param {string[]} parts - Path parts
1498
+ * @param {string} path - Full path for logging
1499
+ * @param {string} guestId - Guest ID for logging
1500
+ * @returns {object | null} Navigation result with current object and parent chain
1501
+ */
1502
+ #navigateToParent = (parts, path, guestId) => {
1503
+ const parentChain = [];
1504
+ let current = window;
1505
+ for (let i = 0; i < parts.length - 1; i += 1) {
1506
+ const part = parts[i];
1507
+ if (current[part] === void 0 || current[part] === null) {
1508
+ this.#logger.debug(
1509
+ `Path "${path}" does not exist (stopped at ${part}) for guest ${guestId}`
1510
+ );
1511
+ return null;
1512
+ }
1513
+ parentChain.push({ obj: current, key: part });
1514
+ current = current[part];
1515
+ }
1516
+ return { current, parentChain };
1517
+ };
1518
+ /**
1519
+ * Clean up empty parent objects in chain
1520
+ * @param {Array<{obj: Record<string, unknown>, key: string}>} parentChain - Chain of parent objects
1521
+ * @param {string[]} parts - Path parts for logging
1522
+ * @param {string} guestId - Guest ID for logging
1523
+ */
1524
+ #cleanupParentChain = (parentChain, parts, guestId) => {
1525
+ for (let i = parentChain.length - 1; i >= 0; i -= 1) {
1526
+ const { obj, key } = parentChain[i];
1527
+ const parent = obj[key];
1528
+ if (!parent || typeof parent !== "object" || !this.#isEmptyOrNullObject(parent)) {
1529
+ break;
1530
+ }
1531
+ obj[key] = null;
1532
+ this.#logger.debug(
1533
+ `Cleaned up empty parent object at ${parts.slice(0, i + 1).join(".")} for guest ${guestId}`
1534
+ );
1535
+ }
1536
+ };
1537
+ /**
1538
+ * Recursively clear window references by path string
1539
+ * Handles nested paths like "window.IMT.focusFormTitle" or "window.emui.app"
1540
+ * Sets each reference to null and cleans up empty parent objects
1541
+ * @param {string[]} paths - Array of dot-separated paths to window properties
1542
+ * @param {string} guestId - Guest ID for logging purposes
1543
+ * @example
1544
+ * // Clear window.IMT.focusFormTitle and cleanup window.IMT if empty
1545
+ * clearWindowRefs(["window.IMT.focusFormTitle"], "my-guest-id");
1546
+ * @example
1547
+ * // Clear multiple refs
1548
+ * clearWindowRefs(["window.IMT.focusFormTitle", "window.emui.app"], "my-guest-id");
1549
+ */
1550
+ #clearWindowRefs = (paths, guestId) => {
1551
+ if (!paths || paths.length === 0) return;
1552
+ paths.forEach((path) => {
1553
+ try {
1554
+ const parts = path.split(".").filter((p) => p !== "window" && p.trim() !== "");
1555
+ if (parts.length === 0) {
1556
+ this.#logger.debug(
1557
+ `Invalid path "${path}" - skipping for guest ${guestId}`
1558
+ );
1559
+ return;
1560
+ }
1561
+ const result = this.#navigateToParent(parts, path, guestId);
1562
+ if (!result) return;
1563
+ const { current, parentChain } = result;
1564
+ const targetProp = parts[parts.length - 1];
1565
+ if (current[targetProp] === void 0) {
1566
+ return;
1567
+ }
1568
+ current[targetProp] = null;
1569
+ this.#logger.debug(
1570
+ `Cleared window reference: ${path} for guest ${guestId}`
1571
+ );
1572
+ this.#cleanupParentChain(parentChain, parts, guestId);
1573
+ } catch (e) {
1574
+ this.#logger.debug(
1575
+ `Failed to clear window reference "${path}" for guest ${guestId}: ${e.message}`
1576
+ );
1577
+ }
1578
+ });
1579
+ };
1580
+ /**
1581
+ * Check if an object is empty or only contains null/undefined values
1582
+ * Used to determine if parent objects should be cleaned up after nulling child properties
1583
+ * @param {unknown} obj - Object to check
1584
+ * @returns {boolean} true if object has no properties or all properties are null/undefined
1585
+ */
1586
+ #isEmptyOrNullObject = (obj) => {
1587
+ if (obj === null || obj === void 0 || typeof obj !== "object")
1588
+ return true;
1589
+ const keys = Object.keys(obj);
1590
+ if (keys.length === 0) return true;
1591
+ const record = obj;
1592
+ return keys.every(
1593
+ (key) => record[key] === null || record[key] === void 0
1594
+ );
1595
+ };
1596
+ /**
1597
+ * Unloads guest application from host with optional enhanced cleanup.
1598
+ *
1599
+ * **Basic Mode (no options):**
1600
+ * - Standard guest disposal
1601
+ * - Removes from tracking maps
1602
+ *
1603
+ * **Enhanced Mode (with options):**
1604
+ * - `purgeOnDestroy: true` - Uses comprehensive cleanup via `unloadGuestWithFullCleanup`
1605
+ * - Calls guest cleanup function (React unmount, Redux teardown)
1606
+ * - Closes contentWindow context
1607
+ * - Navigates iframe to about:blank
1608
+ * - Removes iframe from DOM (deferred)
1609
+ * - Clears all window.emui and window.elli.script references
1610
+ * - Disconnects FieldMutation observers
1611
+ * - Removes from SSF tracking
1612
+ *
1613
+ * - `windowRefsToClear` - Array of paths to window refs to clear recursively
1614
+ * - Example: ["window.IMT.focusFormTitle", "window.emui.customApp"]
1615
+ * - Each path is parsed and set to null
1616
+ *
1617
+ * - `appId` - Optional appId for targeted window.emui[appId] cleanup
1618
+ *
1619
+ * - `cleanupFunctionName` - Name of cleanup function on window.emui (default: 'unmount')
1620
+ * @param {string | Window | HTMLIFrameElement} guestIdOrWindowOrEle - Unique id, window object, or iframe element
1621
+ * @param {object} options - Optional cleanup configuration
1622
+ * @param {boolean} options.purgeOnDestroy - When true, use comprehensive cleanup sequence
1623
+ * @param {string[]} options.windowRefsToClear - Array of window ref paths to clear
1624
+ * @param {string} options.appId - Optional appId for targeted cleanup
1625
+ * @param {string} options.cleanupFunctionName - Guest cleanup function name (default: 'unmount')
1626
+ * @example
1627
+ * // Basic cleanup
1628
+ * host.unloadGuest('my-guest-id');
1629
+ * @example
1630
+ * // Enhanced cleanup with purge
1631
+ * host.unloadGuest('my-guest-id', {
1632
+ * purgeOnDestroy: true,
1633
+ * windowRefsToClear: ["window.IMT.focusFormTitle"],
1634
+ * cleanupFunctionName: 'appCleanup'
1635
+ * });
1636
+ * @example
1637
+ * // Enhanced cleanup with appId
1638
+ * host.unloadGuest('my-guest-id', {
1639
+ * purgeOnDestroy: true,
1640
+ * appId: 'workflowtasks',
1641
+ * cleanupFunctionName: 'cleanup'
1642
+ * });
1643
+ */
1644
+ unloadGuest = (guestIdOrWindowOrEle, options) => {
1257
1645
  const guest = this.#findGuest(guestIdOrWindowOrEle);
1258
- if (guest) {
1259
- guest.dispose();
1260
- this.#guestsByWindow.delete(guest.window);
1261
- this.#guestsByUrl.delete(guest.url);
1262
- this.#guestMetadata.delete(guest.id);
1263
- this.#guests.delete(guest.id);
1646
+ if (!guest) {
1647
+ this.#logger.warn("Attempted to unload unknown guest");
1648
+ return;
1649
+ }
1650
+ const guestId = guest.id;
1651
+ if (options?.purgeOnDestroy) {
1652
+ const cleanupFunctionName = options.cleanupFunctionName || "unmount";
1653
+ if (options.windowRefsToClear && options.windowRefsToClear.length > 0) {
1654
+ this.#clearWindowRefs(options.windowRefsToClear, guestId);
1655
+ }
1656
+ this.unloadGuestWithFullCleanup(guestId, cleanupFunctionName);
1264
1657
  this.#logger.audit({
1265
- message: `Guest is removed from host`,
1658
+ message: `Guest unloaded with purge mode (windowRefs: ${options.windowRefsToClear?.length || 0})`,
1266
1659
  ...guest.getInfo()
1267
1660
  });
1268
- this.#stopMonitoringPopupGuests();
1661
+ return;
1662
+ }
1663
+ guest.dispose();
1664
+ this.#guestsByWindow.delete(guest.window);
1665
+ this.#guestsByUrl.delete(guest.url);
1666
+ this.#guestMetadata.delete(guest.id);
1667
+ this.#guests.delete(guest.id);
1668
+ this.#logger.audit({
1669
+ message: `Guest is removed from host`,
1670
+ ...guest.getInfo()
1671
+ });
1672
+ this.#stopMonitoringPopupGuests();
1673
+ };
1674
+ /**
1675
+ * Process iframe cleanup sequence
1676
+ * @param {Guest} guest - Guest object
1677
+ * @param {string} cleanupFunctionName - Cleanup function name
1678
+ */
1679
+ #processIframeCleanup = (guest, cleanupFunctionName) => {
1680
+ if (!guest.domElement) return;
1681
+ const iframe = guest.domElement;
1682
+ const contentWindow = guest.window;
1683
+ const { id: guestId } = guest;
1684
+ this.#cleanupGuestWindow({
1685
+ guestWindow: contentWindow,
1686
+ guestId,
1687
+ cleanupFunctionName,
1688
+ windowType: "iframe"
1689
+ });
1690
+ this.#disconnectFieldMutationObserver(contentWindow, guestId);
1691
+ this.#closeContentWindow(contentWindow, guestId);
1692
+ this.#navigateToBlank(iframe, guestId);
1693
+ setTimeout(() => {
1694
+ try {
1695
+ if (iframe.parentNode) {
1696
+ iframe.remove();
1697
+ this.#logger.debug(
1698
+ `[SSF] Removed iframe from DOM for guest ${guestId}`
1699
+ );
1700
+ }
1701
+ } catch (e) {
1702
+ this.#logger.warn(
1703
+ `[SSF] Failed to remove iframe for guest ${guestId}: ${e.message}`
1704
+ );
1705
+ }
1706
+ }, 10);
1707
+ };
1708
+ /**
1709
+ * Process popup cleanup sequence
1710
+ * @param {Guest} guest - Guest object
1711
+ * @param {string} cleanupFunctionName - Cleanup function name
1712
+ */
1713
+ #processPopupCleanup = (guest, cleanupFunctionName) => {
1714
+ const popupWindow = guest.window;
1715
+ const { id: guestId } = guest;
1716
+ this.#cleanupGuestWindow({
1717
+ guestWindow: popupWindow,
1718
+ guestId,
1719
+ cleanupFunctionName,
1720
+ windowType: "popup"
1721
+ });
1722
+ try {
1723
+ if (popupWindow && !popupWindow.closed) {
1724
+ popupWindow.close();
1725
+ this.#logger.debug(`[SSF] Closed popup window for guest ${guestId}`);
1726
+ }
1727
+ } catch (e) {
1728
+ this.#logger.debug(
1729
+ `[SSF] Failed to close popup window for guest ${guestId}: ${e.message}`
1730
+ );
1731
+ }
1732
+ guest.dispose();
1733
+ };
1734
+ /**
1735
+ * Unloads guest application with comprehensive memory leak prevention.
1736
+ *
1737
+ * This method implements industry best practices for iframe and popup cleanup to prevent
1738
+ * memory leaks, particularly detached window retention and webpack bundle accumulation.
1739
+ *
1740
+ * **Enhanced Cleanup Sequence for Embedded Iframes:**
1741
+ * 1. Call guest cleanup function (React unmount, Redux teardown, etc.)
1742
+ * 2. Close contentWindow context explicitly
1743
+ * 3. Navigate iframe to about:blank (Chrome GC recommendation)
1744
+ * 4. Small delay, then remove iframe from DOM
1745
+ * 5. Remove from SSF tracking maps
1746
+ * 6. Null all internal references
1747
+ *
1748
+ * **Enhanced Cleanup Sequence for Popup Windows:**
1749
+ * 1. Call guest cleanup function (React unmount, Redux teardown, etc.)
1750
+ * 2. Null all window.emui and window.elli.script references
1751
+ * 3. Clear Google Tag Manager data layer
1752
+ * 4. Close popup window explicitly
1753
+ * 5. Dispose guest (cleanup event listeners)
1754
+ * 6. Remove from SSF tracking maps
1755
+ *
1756
+ * **Memory Leak Prevention:**
1757
+ * - Breaks all closures from contentWindow/popup to parent
1758
+ * - Signals V8 to GC webpack bundle backing store strings
1759
+ * - Removes iframe from browser back/forward cache
1760
+ * - Clears all SSF remoting message handlers
1761
+ * - Nulls all window.emui and window.elli.script properties
1762
+ *
1763
+ * **Important:** This method does NOT clean up window.emui[appId] registry.
1764
+ * When using selfInitialize=true pattern, the guest application handles
1765
+ * its own emui registry cleanup internally.
1766
+ *
1767
+ * **Synchronous Design:** This method is intentionally synchronous to work
1768
+ * with React useEffect cleanup functions. Cleanup steps use setTimeout
1769
+ * for deferred operations rather than async/await.
1770
+ * @param {string | Window | HTMLIFrameElement} guestIdOrWindowOrEle - unique id of the guest application or window object or dom element
1771
+ * @param {string} cleanupFunctionName - name of cleanup function on window.emui (default: 'unmount')
1772
+ * @example
1773
+ * // Standard usage with app cleanup
1774
+ * host.unloadGuestWithFullCleanup('my-guest-id', 'appCleanup');
1775
+ * @example
1776
+ * // Usage with custom cleanup function
1777
+ * host.unloadGuestWithFullCleanup('my-guest-id', 'customUnmount');
1778
+ * @example
1779
+ * // Usage when guest uses default unmount
1780
+ * host.unloadGuestWithFullCleanup('my-guest-id');
1781
+ */
1782
+ unloadGuestWithFullCleanup = (guestIdOrWindowOrEle, cleanupFunctionName = "unmount") => {
1783
+ const guest = this.#findGuest(guestIdOrWindowOrEle);
1784
+ if (!guest) {
1785
+ this.#logger.warn("Attempted to unload unknown guest");
1786
+ return;
1787
+ }
1788
+ const { id: guestId } = guest;
1789
+ if (guest.openMode === import_types.OpenMode.Embed && guest.domElement) {
1790
+ this.#processIframeCleanup(guest, cleanupFunctionName);
1791
+ } else if (guest.openMode === import_types.OpenMode.Popup) {
1792
+ this.#processPopupCleanup(guest, cleanupFunctionName);
1793
+ } else {
1794
+ guest.dispose();
1795
+ }
1796
+ try {
1797
+ this.#remoting.removeSender({
1798
+ origin: guest.origin,
1799
+ window: guest.window
1800
+ });
1801
+ this.#logger.debug(`[SSF] Removed remoting sender for guest ${guestId}`);
1802
+ } catch (e) {
1803
+ this.#logger.debug(
1804
+ `[SSF] Failed to remove remoting sender for guest ${guestId}: ${e.message}`
1805
+ );
1269
1806
  }
1807
+ this.#guestsByWindow.delete(guest.window);
1808
+ this.#guestsByUrl.delete(guest.url);
1809
+ this.#guestMetadata.delete(guestId);
1810
+ this.#guests.delete(guestId);
1811
+ this.#stopMonitoringPopupGuests();
1812
+ this.#logger.audit({
1813
+ message: `Guest unloaded with full cleanup`,
1814
+ ...guest.getInfo()
1815
+ });
1270
1816
  };
1271
1817
  /**
1272
1818
  * monitors guest window close action and executes the callback from host.
1273
- * @param callback host callback method
1274
- * @param id unique id of the guest application
1275
- * @param param
1819
+ * @param param - Guest close parameters including id and callback
1276
1820
  */
1277
1821
  onGuestClose = (param) => {
1278
1822
  const { id, guestCloseCallback } = param;