webhands 0.3.0 → 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/errors.ts CHANGED
@@ -8,6 +8,9 @@ import {
8
8
  AttachNoContextError,
9
9
  NoLiveServerError,
10
10
  SessionAlreadyActiveError,
11
+ CrossOriginFrameError,
12
+ ScreenshotPathError,
13
+ StaleRefError,
11
14
  type ControllerError,
12
15
  type ControllerErrorCode,
13
16
  } from '@webhands/core';
@@ -78,6 +81,25 @@ export function fixCommandFor(error: ControllerError, binary: string): string {
78
81
  // A session is already live; v1 holds exactly one. The fix is to tear it
79
82
  // down before starting another.
80
83
  return `${binary} stop`;
84
+ case 'cross-origin-frame':
85
+ // `eval --frame` reaches the top document and SAME-ORIGIN child frames
86
+ // only (page-world JS cannot cross a security boundary). There is no
87
+ // flag that makes a cross-origin frame reachable here; the fix is to
88
+ // target a same-origin frame, or omit --frame for the top document. (The
89
+ // cross-origin reach is the separate Tier-4 surface.)
90
+ return `${binary} eval '<expression>' (drop --frame for the top document, or pass a SAME-ORIGIN frame selector)`;
91
+ case 'screenshot-path-outside-managed-dir':
92
+ // A --out override escaped the managed screenshots dir. webhands writes
93
+ // only WITHIN that dir; the fix is to drop --out (let webhands mint a
94
+ // path) or pass one under the managed dir.
95
+ return `${binary} screenshot (drop --out to let webhands mint a path under ${(error as ScreenshotPathError).managedDir}, or pass an --out inside it)`;
96
+ case 'stale-ref':
97
+ // A durable `query` ref went stale (resolve-to-zero) or ambiguous
98
+ // (resolve-to-many) before the action ran: the page changed between the
99
+ // query and the act. There is no flag that revives a stale handle; the
100
+ // fix is to re-run `query --with-refs` against the fresh DOM and act on
101
+ // the NEW ref (the agent's natural read-then-act loop).
102
+ return `${binary} query '<locator>' --with-refs (re-read the page to get a fresh ref, then click/type --by-ref with it)`;
81
103
  default: {
82
104
  // Exhaustiveness guard: a new ControllerErrorCode must add a fix command
83
105
  // here rather than silently fall through to a generic message.
@@ -123,5 +145,8 @@ export {
123
145
  AttachNoContextError,
124
146
  NoLiveServerError,
125
147
  SessionAlreadyActiveError,
148
+ CrossOriginFrameError,
149
+ ScreenshotPathError,
150
+ StaleRefError,
126
151
  };
127
152
  export type {ControllerError, ControllerErrorCode};