pi-chrome 0.15.42 → 0.15.44
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/README.md
CHANGED
|
@@ -66,16 +66,11 @@ Second doctor run should show all checks passing.
|
|
|
66
66
|
|
|
67
67
|
## What it can do
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
-
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
- **Interact** — click, type, fill, key, hover, drag, scroll, tap.
|
|
75
|
-
- **Files** — upload files through `<input type=file>` without native picker.
|
|
76
|
-
- **Observe** — console logs, network requests, response bodies.
|
|
77
|
-
|
|
78
|
-
Input tools return structured verification data. Pass `includeSnapshot: true` on click/type/fill/key calls to get fresh page state in same result.
|
|
69
|
+
- Read and summarize pages you're already signed into.
|
|
70
|
+
- Click, type, fill forms, scroll, drag, tap, and upload files.
|
|
71
|
+
- Capture screenshots for bugs, PRs, and demos.
|
|
72
|
+
- Inspect console logs and captured `fetch`/`XMLHttpRequest` responses.
|
|
73
|
+
- Manage tabs without taking over your active window.
|
|
79
74
|
|
|
80
75
|
Tool parameters and gotchas are documented inline in Pi.
|
|
81
76
|
|
|
@@ -718,15 +718,40 @@ export default function (pi: ExtensionAPI): void {
|
|
|
718
718
|
countdownInterval = undefined;
|
|
719
719
|
};
|
|
720
720
|
|
|
721
|
-
const
|
|
721
|
+
const chromeToolsActive = (tools = pi.getActiveTools()): boolean => tools.some((name) => CHROME_TOOL_NAME_SET.has(name));
|
|
722
722
|
|
|
723
|
-
const activateChromeTools = ():
|
|
723
|
+
const activateChromeTools = (): boolean => {
|
|
724
724
|
registerChromeTools(pi);
|
|
725
|
-
|
|
725
|
+
const before = pi.getActiveTools();
|
|
726
|
+
const next = [...new Set([...before, ...CHROME_TOOL_NAMES])];
|
|
727
|
+
pi.setActiveTools(next);
|
|
728
|
+
return !chromeToolsActive(before) && chromeToolsActive(next);
|
|
726
729
|
};
|
|
727
730
|
|
|
728
|
-
const deactivateChromeTools = ():
|
|
729
|
-
pi.
|
|
731
|
+
const deactivateChromeTools = (): boolean => {
|
|
732
|
+
const before = pi.getActiveTools();
|
|
733
|
+
pi.setActiveTools(before.filter((name) => !CHROME_TOOL_NAME_SET.has(name)));
|
|
734
|
+
return chromeToolsActive(before);
|
|
735
|
+
};
|
|
736
|
+
|
|
737
|
+
const logChromeToolChange = (action: "authorized" | "revoked" | "expired", label?: string): void => {
|
|
738
|
+
const enabled = action === "authorized";
|
|
739
|
+
const content = enabled
|
|
740
|
+
? `Chrome tools enabled by /chrome authorize${label ? ` (${label})` : ""}.`
|
|
741
|
+
: action === "expired"
|
|
742
|
+
? "Chrome tools disabled because /chrome authorize grant expired."
|
|
743
|
+
: "Chrome tools disabled by /chrome revoke.";
|
|
744
|
+
pi.sendMessage({
|
|
745
|
+
customType: "pi-chrome-tool-change",
|
|
746
|
+
content,
|
|
747
|
+
display: true,
|
|
748
|
+
details: {
|
|
749
|
+
action,
|
|
750
|
+
tools: [...CHROME_TOOL_NAMES],
|
|
751
|
+
authorizedUntil: chromeAuthorizedUntil,
|
|
752
|
+
at: Date.now(),
|
|
753
|
+
},
|
|
754
|
+
}, { triggerTurn: false });
|
|
730
755
|
};
|
|
731
756
|
|
|
732
757
|
// Close THIS session's dedicated automation window/tab. Fire-and-forget and best-effort: it
|
|
@@ -738,12 +763,13 @@ export default function (pi: ExtensionAPI): void {
|
|
|
738
763
|
void bridge.send("automation.cleanup", sessionKey !== undefined ? { sessionKey } : {}, 3_000).catch(() => undefined);
|
|
739
764
|
};
|
|
740
765
|
|
|
741
|
-
const lockChromeControl = (): void => {
|
|
766
|
+
const lockChromeControl = (logAction?: "revoked" | "expired"): void => {
|
|
742
767
|
clearAuthExpiryTimer();
|
|
743
768
|
clearCountdownInterval();
|
|
769
|
+
const hadChromeTools = deactivateChromeTools();
|
|
770
|
+
if (logAction && hadChromeTools) logChromeToolChange(logAction);
|
|
744
771
|
chromeAuthorizedUntil = undefined;
|
|
745
772
|
persistAuth();
|
|
746
|
-
deactivateChromeTools();
|
|
747
773
|
// Revoking control ends pi-chrome's automation for this session; tidy up the target we own.
|
|
748
774
|
cleanupAutomationTargetBestEffort();
|
|
749
775
|
};
|
|
@@ -760,7 +786,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
760
786
|
const chromeControlAuthorized = (): boolean => {
|
|
761
787
|
if (chromeAuthorizedUntil === "indefinite") return true;
|
|
762
788
|
if (typeof chromeAuthorizedUntil === "number" && chromeAuthorizedUntil > Date.now()) return true;
|
|
763
|
-
if (chromeAuthorizedUntil !== undefined) lockChromeControl();
|
|
789
|
+
if (chromeAuthorizedUntil !== undefined) lockChromeControl("expired");
|
|
764
790
|
return false;
|
|
765
791
|
};
|
|
766
792
|
|
|
@@ -827,7 +853,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
827
853
|
authExpiryTimer = setTimeout(() => {
|
|
828
854
|
if (chromeAuthorizedUntil !== until) return;
|
|
829
855
|
try {
|
|
830
|
-
lockChromeControl();
|
|
856
|
+
lockChromeControl("expired");
|
|
831
857
|
ctx.ui.notify("Chrome control authorization expired. Run /chrome authorize to allow chrome_* tools again.", "info");
|
|
832
858
|
updateChromeStatus(ctx);
|
|
833
859
|
} catch (error) {
|
|
@@ -1040,6 +1066,7 @@ Usage rules:
|
|
|
1040
1066
|
chromeAuthorizedUntil = until;
|
|
1041
1067
|
persistAuth();
|
|
1042
1068
|
activateChromeTools();
|
|
1069
|
+
logChromeToolChange("authorized", label);
|
|
1043
1070
|
scheduleAuthExpiry(ctx, until);
|
|
1044
1071
|
ctx.ui.notify(`Chrome control authorized for ${label}.`, "info");
|
|
1045
1072
|
updateChromeStatus(ctx);
|
|
@@ -1063,7 +1090,7 @@ Usage rules:
|
|
|
1063
1090
|
};
|
|
1064
1091
|
|
|
1065
1092
|
const revokeHandler = (ctx: ExtensionContext) => {
|
|
1066
|
-
lockChromeControl();
|
|
1093
|
+
lockChromeControl("revoked");
|
|
1067
1094
|
ctx.ui.notify("Chrome control locked. Run /chrome authorize to allow chrome_* tools again.", "info");
|
|
1068
1095
|
updateChromeStatus(ctx);
|
|
1069
1096
|
};
|
package/package.json
CHANGED