aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTianren Dong <tianrendong.dtr@gmail.com>2026-07-07 01:30:54 -0400
committerTianren Dong <tianrendong.dtr@gmail.com>2026-07-07 01:30:54 -0400
commit017ff4b9a639f0b8b213e58a3f30613fc38edcc8 (patch)
tree94e8671a2c6c7d2c430fc8c43db44d3ad1fe1a04
parent7fcc851d89bf1db4e188d81ca84362a3f4a8cbed (diff)
Fix Chrome authorization update logging
-rw-r--r--extensions/chrome-profile-bridge/browser-extension/manifest.json2
-rw-r--r--extensions/chrome-profile-bridge/index.ts28
-rw-r--r--package-lock.json4
-rw-r--r--package.json2
4 files changed, 23 insertions, 13 deletions
diff --git a/extensions/chrome-profile-bridge/browser-extension/manifest.json b/extensions/chrome-profile-bridge/browser-extension/manifest.json
index c3753e7..e5fbe61 100644
--- a/extensions/chrome-profile-bridge/browser-extension/manifest.json
+++ b/extensions/chrome-profile-bridge/browser-extension/manifest.json
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Pi Chrome Connector",
- "version": "0.15.45",
+ "version": "0.15.46",
"description": "Lets Pi control tabs in Chrome via a local connector at 127.0.0.1.",
"permissions": [
"tabs",
diff --git a/extensions/chrome-profile-bridge/index.ts b/extensions/chrome-profile-bridge/index.ts
index a57d1a9..e3e5a04 100644
--- a/extensions/chrome-profile-bridge/index.ts
+++ b/extensions/chrome-profile-bridge/index.ts
@@ -701,6 +701,7 @@ export default function (pi: ExtensionAPI): void {
else globalState[PI_CHROME_AUTH_KEY] = { until: chromeAuthorizedUntil };
};
let chromeToolsRegistered = false;
+ let chromeToolsUsable = false;
let authExpiryTimer: NodeJS.Timeout | undefined;
let countdownInterval: NodeJS.Timeout | undefined;
// Remembered so bridge sends can tag tabs with this session's group even when ctx isn't handy.
@@ -735,15 +736,16 @@ export default function (pi: ExtensionAPI): void {
};
const logChromeToolChange = (
- action: "authorized" | "revoked" | "expired",
+ action: "authorized" | "reauthorized" | "revoked" | "expired",
options: { label?: string; authorizedUntil?: number | "indefinite" } = {},
): void => {
- const enabled = action === "authorized";
- const content = enabled
+ const content = action === "authorized"
? `Chrome tools enabled by /chrome authorize${options.label ? ` (${options.label})` : ""}.`
- : action === "expired"
- ? "Chrome tools disabled because /chrome authorize grant expired."
- : "Chrome tools disabled by /chrome revoke.";
+ : action === "reauthorized"
+ ? `Chrome tool authorization updated by /chrome authorize${options.label ? ` (${options.label})` : ""}.`
+ : action === "expired"
+ ? "Chrome tools disabled because /chrome authorize grant expired."
+ : "Chrome tools disabled by /chrome revoke.";
pi.sendMessage({
customType: "pi-chrome-tool-change",
content,
@@ -769,8 +771,10 @@ export default function (pi: ExtensionAPI): void {
const lockChromeControl = (logAction?: "revoked" | "expired"): void => {
clearAuthExpiryTimer();
clearCountdownInterval();
- const hadChromeTools = deactivateChromeTools();
- if (logAction && hadChromeTools) logChromeToolChange(logAction, { authorizedUntil: undefined });
+ const wasUsable = chromeToolsUsable;
+ deactivateChromeTools();
+ chromeToolsUsable = false;
+ if (logAction && wasUsable) logChromeToolChange(logAction, { authorizedUntil: undefined });
chromeAuthorizedUntil = undefined;
persistAuth();
// Revoking control ends pi-chrome's automation for this session; tidy up the target we own.
@@ -911,8 +915,12 @@ export default function (pi: ExtensionAPI): void {
// Reestablish in-memory state after a /reload restored chromeAuthorizedUntil from globalThis.
if (chromeControlAuthorized()) {
activateChromeTools();
+ chromeToolsUsable = true;
if (typeof chromeAuthorizedUntil === "number") scheduleAuthExpiry(ctx, chromeAuthorizedUntil);
else if (chromeAuthorizedUntil === "indefinite") startCountdownTicker(ctx);
+ } else {
+ deactivateChromeTools();
+ chromeToolsUsable = false;
}
updateChromeStatus(ctx);
});
@@ -1066,10 +1074,12 @@ Usage rules:
ctx.ui.notify("Chrome control remains locked.", "info");
return;
}
+ const wasUsable = chromeToolsUsable;
chromeAuthorizedUntil = until;
persistAuth();
activateChromeTools();
- logChromeToolChange("authorized", { label, authorizedUntil: until });
+ chromeToolsUsable = true;
+ logChromeToolChange(wasUsable ? "reauthorized" : "authorized", { label, authorizedUntil: until });
scheduleAuthExpiry(ctx, until);
ctx.ui.notify(`Chrome control authorized for ${label}.`, "info");
updateChromeStatus(ctx);
diff --git a/package-lock.json b/package-lock.json
index f17ac39..9823197 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "pi-chrome",
- "version": "0.15.45",
+ "version": "0.15.46",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "pi-chrome",
- "version": "0.15.45",
+ "version": "0.15.46",
"license": "MIT",
"peerDependencies": {
"@earendil-works/pi-coding-agent": "*",
diff --git a/package.json b/package.json
index e6e4354..9da6d94 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "pi-chrome",
- "version": "0.15.45",
+ "version": "0.15.46",
"scripts": {
"test": "node test-suite/unit/csp-eval.test.mjs && node test-suite/unit/automation-target.test.mjs",
"version": "node scripts/sync-manifest-version.js",