pi-browser-harness 0.3.2 → 0.4.0

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/src/index.ts CHANGED
@@ -98,7 +98,23 @@ export default function browserHarnessExtension(pi: ExtensionAPI): void {
98
98
 
99
99
  pi.on("session_start", async (_event, ctx) => {
100
100
  state = restoreState(ctx, state.namespace);
101
- client = createBrowserClient({ namespace: state.namespace });
101
+ const initialOwnership: { ownedTargetIds?: ReadonlyArray<string>; harnessWindowTargetId?: string } = {};
102
+ if (state.ownedTargetIds !== undefined) initialOwnership.ownedTargetIds = state.ownedTargetIds;
103
+ if (state.harnessWindowTargetId !== undefined) initialOwnership.harnessWindowTargetId = state.harnessWindowTargetId;
104
+ client = createBrowserClient({
105
+ namespace: state.namespace,
106
+ ...(Object.keys(initialOwnership).length > 0 ? { initialOwnership } : {}),
107
+ onOwnershipChange: (snap) => {
108
+ state = {
109
+ ...state,
110
+ ownedTargetIds: snap.ownedTargetIds,
111
+ ...(snap.harnessWindowTargetId !== undefined
112
+ ? { harnessWindowTargetId: snap.harnessWindowTargetId }
113
+ : {}),
114
+ };
115
+ persistState(pi, state);
116
+ },
117
+ });
102
118
  // failure is fine — surfaced via tool errors when the agent first tries to use the browser
103
119
  await client.start();
104
120
  if (!toolsRegistered) {
package/src/registry.ts CHANGED
@@ -9,11 +9,12 @@ import { handleDialogTool } from "./domains/dialog";
9
9
  import { screenshotTool } from "./domains/screenshot";
10
10
  import { navigateTool, openUrlsTool } from "./domains/navigate";
11
11
  import { goBackTool, goForwardTool, reloadTool } from "./domains/history";
12
- import { listTabsTool, currentTabTool, switchTabTool, newTabTool } from "./domains/tabs";
12
+ import { listTabsTool, currentTabTool, switchTabTool, newTabTool, closeTabTool } from "./domains/tabs";
13
13
  import { uploadFileTool, downloadTool, printToPdfTool } from "./domains/files";
14
14
  import { viewportResizeTool } from "./domains/viewport";
15
15
  import { dragAndDropTool } from "./domains/drag";
16
- import { httpGetTool, getNetworkLogTool } from "./domains/network";
16
+ import { httpGetTool, networkRequestsTool } from "./domains/network";
17
+ import { snapshotTool } from "./domains/snapshot";
17
18
  import { executeJsTool, runScriptTool } from "./domains/js";
18
19
 
19
20
  // Mutation tools that modify page / browser state are marked `serialized: true`
@@ -39,13 +40,15 @@ const TOOLS: ReadonlyArray<AnyBrowserToolDefinition> = [
39
40
  currentTabTool,
40
41
  { ...switchTabTool, serialized: true },
41
42
  { ...newTabTool, serialized: true },
43
+ { ...closeTabTool, serialized: true },
42
44
  { ...uploadFileTool, serialized: true },
43
45
  { ...downloadTool, serialized: true },
44
46
  { ...printToPdfTool, serialized: true },
45
47
  { ...viewportResizeTool, serialized: true },
46
48
  { ...dragAndDropTool, serialized: true },
47
49
  httpGetTool,
48
- getNetworkLogTool,
50
+ networkRequestsTool,
51
+ snapshotTool,
49
52
  executeJsTool,
50
53
  runScriptTool,
51
54
  ];
package/src/state.ts CHANGED
@@ -10,9 +10,14 @@ import type { ExtensionAPI, ExtensionContext } from "@mariozechner/pi-coding-age
10
10
  export type BrowserState = {
11
11
  readonly namespace: string;
12
12
  readonly remoteBrowserId?: string;
13
+ readonly ownedTargetIds?: ReadonlyArray<string>;
14
+ readonly harnessWindowTargetId?: string;
13
15
  };
14
16
 
15
- export const defaultState = (namespace = "default"): BrowserState => ({ namespace });
17
+ export const defaultState = (namespace = "default"): BrowserState => ({
18
+ namespace,
19
+ ownedTargetIds: [],
20
+ });
16
21
 
17
22
  export const persistState = (pi: ExtensionAPI, state: BrowserState): void => {
18
23
  pi.appendEntry<BrowserState>("browser-harness-state", state);