pi-chrome 0.15.34 → 0.15.35

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Pi Chrome Connector",
4
- "version": "0.15.34",
4
+ "version": "0.15.35",
5
5
  "description": "Lets Pi control tabs in Chrome via a local connector at 127.0.0.1.",
6
6
  "permissions": [
7
7
  "tabs",
@@ -55,6 +55,10 @@ function readPiChromeVersion(): string {
55
55
  }
56
56
  const PI_CHROME_VERSION = readPiChromeVersion();
57
57
  const PI_CHROME_GLOBAL_KEY = "__piChromeProfileBridgeLoaded__";
58
+ // Authorization is kept on globalThis (separate from the singleton flag, which is cleared on
59
+ // reload) so a /reload — which tears down and re-evaluates the module — does not silently drop
60
+ // an active /chrome authorize grant.
61
+ const PI_CHROME_AUTH_KEY = "__piChromeProfileBridgeAuth__";
58
62
  const DEFAULT_HOST = process.env.PI_CHROME_BRIDGE_HOST ?? "127.0.0.1";
59
63
  const DEFAULT_PORT = Number(process.env.PI_CHROME_BRIDGE_PORT ?? "17318");
60
64
  const DEFAULT_TIMEOUT_MS = 30_000;
@@ -535,6 +539,7 @@ export default function (pi: ExtensionAPI): void {
535
539
  const currentRoot = extensionRoot();
536
540
  const globalState = globalThis as typeof globalThis & {
537
541
  [PI_CHROME_GLOBAL_KEY]?: { version: string; root: string; token?: symbol };
542
+ [PI_CHROME_AUTH_KEY]?: { until: number | "indefinite" };
538
543
  };
539
544
  const alreadyLoaded = globalState[PI_CHROME_GLOBAL_KEY];
540
545
  if (alreadyLoaded?.token || (alreadyLoaded && alreadyLoaded.root !== currentRoot)) {
@@ -551,6 +556,19 @@ export default function (pi: ExtensionAPI): void {
551
556
  const bridge = new ChromeProfileBridge(DEFAULT_HOST, DEFAULT_PORT);
552
557
  let backgroundDefault = true;
553
558
  let chromeAuthorizedUntil: number | "indefinite" | undefined;
559
+ // Restore an authorization that survived a /reload. Drop it if it already expired.
560
+ const persistedAuth = globalState[PI_CHROME_AUTH_KEY];
561
+ if (persistedAuth) {
562
+ if (persistedAuth.until === "indefinite" || persistedAuth.until > Date.now()) {
563
+ chromeAuthorizedUntil = persistedAuth.until;
564
+ } else {
565
+ delete globalState[PI_CHROME_AUTH_KEY];
566
+ }
567
+ }
568
+ const persistAuth = (): void => {
569
+ if (chromeAuthorizedUntil === undefined) delete globalState[PI_CHROME_AUTH_KEY];
570
+ else globalState[PI_CHROME_AUTH_KEY] = { until: chromeAuthorizedUntil };
571
+ };
554
572
  let chromeToolsRegistered = false;
555
573
  let authExpiryTimer: NodeJS.Timeout | undefined;
556
574
  // Remembered so bridge sends can tag tabs with this session's group even when ctx isn't handy.
@@ -576,6 +594,7 @@ export default function (pi: ExtensionAPI): void {
576
594
  const lockChromeControl = (): void => {
577
595
  clearAuthExpiryTimer();
578
596
  chromeAuthorizedUntil = undefined;
597
+ persistAuth();
579
598
  deactivateChromeTools();
580
599
  };
581
600
 
@@ -662,6 +681,11 @@ export default function (pi: ExtensionAPI): void {
662
681
  pi.on("session_start", async (_event, ctx) => {
663
682
  sessionCtx = ctx;
664
683
  await bridge.start();
684
+ // Reestablish in-memory state after a /reload restored chromeAuthorizedUntil from globalThis.
685
+ if (chromeControlAuthorized()) {
686
+ activateChromeTools();
687
+ if (typeof chromeAuthorizedUntil === "number") scheduleAuthExpiry(ctx, chromeAuthorizedUntil);
688
+ }
665
689
  updateChromeStatus(ctx);
666
690
  });
667
691
 
@@ -801,6 +825,7 @@ Usage rules:
801
825
  return;
802
826
  }
803
827
  chromeAuthorizedUntil = until;
828
+ persistAuth();
804
829
  activateChromeTools();
805
830
  scheduleAuthExpiry(ctx, until);
806
831
  ctx.ui.notify(`Chrome control authorized for ${label}.`, "info");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-chrome",
3
- "version": "0.15.34",
3
+ "version": "0.15.35",
4
4
  "scripts": {
5
5
  "test": "node test-suite/unit/csp-eval.test.mjs",
6
6
  "version": "node scripts/sync-manifest-version.js",