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