@patch-adams/core 1.5.20 → 1.5.21

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/index.js CHANGED
@@ -1640,22 +1640,28 @@ function generateLrsBridgeCode(options) {
1640
1640
 
1641
1641
  /**
1642
1642
  * Get the best available actor for statement building.
1643
- * Priority: LRS.actor (if non-anonymous) > localStorage shared actor > LRS.actor > extractActor()
1643
+ * ALWAYS checks localStorage because the skin overlay in another frame
1644
+ * may have updated the actor AFTER this bridge instance initialized.
1645
+ * (e.g., user enters email in skin overlay \u2192 actor persisted to localStorage,
1646
+ * but the bridge in scormcontent/index.html already loaded a stale actor at init)
1644
1647
  */
1645
1648
  function getActor() {
1646
- // If current actor is non-anonymous, use it
1647
- if (LRS.actor && !isAnonymousActor(LRS.actor)) {
1648
- return LRS.actor;
1649
- }
1650
- // Check localStorage for actor set by another frame (e.g., skin overlay)
1649
+ // Always check localStorage for the freshest actor \u2014 it may have been
1650
+ // updated by the skin overlay in another frame since our init
1651
1651
  var shared = loadSharedActor();
1652
1652
  if (shared) {
1653
- // Update local actor so future calls are fast
1653
+ // Only update if different from current (avoid unnecessary log spam)
1654
+ if (!LRS.actor || LRS.actor.name !== shared.name ||
1655
+ (LRS.actor.account && shared.account && LRS.actor.account.name !== shared.account.name)) {
1656
+ log('Actor updated from cross-frame storage:', shared.name);
1657
+ }
1654
1658
  LRS.actor = shared;
1655
- log('Actor loaded from cross-frame storage:', shared.name);
1656
1659
  return shared;
1657
1660
  }
1658
1661
  // Fallback to current actor or re-extract
1662
+ if (LRS.actor && !isAnonymousActor(LRS.actor)) {
1663
+ return LRS.actor;
1664
+ }
1659
1665
  return LRS.actor || extractActor();
1660
1666
  }
1661
1667
 
@@ -1666,7 +1672,9 @@ function generateLrsBridgeCode(options) {
1666
1672
  LRS.setActor = function(actor) {
1667
1673
  LRS.actor = actor;
1668
1674
  persistActor(actor);
1669
- // Also try to propagate to other frames in the hierarchy
1675
+
1676
+ // Propagate to ALL frames: walk UP parent chain AND DOWN into child iframes
1677
+ // UP: parent frames (e.g., if skin is in a child iframe)
1670
1678
  try {
1671
1679
  var w = window;
1672
1680
  for (var i = 0; i < 10; i++) {
@@ -1679,9 +1687,29 @@ function generateLrsBridgeCode(options) {
1679
1687
  w = w.parent;
1680
1688
  }
1681
1689
  } catch (e) {}
1690
+
1691
+ // DOWN: child iframes (e.g., scormcontent/index.html has its own bridge)
1692
+ function setActorInChildren(win) {
1693
+ try {
1694
+ var frames = win.frames;
1695
+ for (var j = 0; j < frames.length; j++) {
1696
+ try {
1697
+ if (frames[j].pa_patcher && frames[j].pa_patcher.lrs) {
1698
+ frames[j].pa_patcher.lrs.actor = actor;
1699
+ log('Actor propagated to child frame', j);
1700
+ }
1701
+ // Recurse into nested iframes
1702
+ setActorInChildren(frames[j]);
1703
+ } catch (e) { /* cross-origin child */ }
1704
+ }
1705
+ } catch (e) {}
1706
+ }
1707
+ setActorInChildren(window);
1708
+
1682
1709
  if (window.console && window.console.info) {
1683
1710
  console.info('[PA-LRS] Actor set:', actor.name,
1684
1711
  actor.mbox ? '(' + actor.mbox + ')' : '',
1712
+ actor.account ? '(account: ' + actor.account.name + ')' : '',
1685
1713
  '\u2014 shared across frames');
1686
1714
  }
1687
1715
  };