@volter-ai-dev/supercode-browser-playwright 0.2.0 → 0.2.1

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
@@ -130,34 +130,45 @@ Two entry points use no Node API:
130
130
  `@volter/almostcdp/playwright`, and answers the operations against an
131
131
  AlmostCDP surface with no Node process.
132
132
 
133
- A host's `actionGuard(action)` is asked before each element action and before
134
- each `browser.script` (`{action: "script", source, args}`); throwing a
135
- `BrowserActionRefusal` answers the call with its code, such as
136
- `APPROVAL_REQUIRED`. A script's own locator calls are the real `page`'s and are
137
- not asked again, so a host that guards element actions guards scripts as a
138
- whole.
139
-
140
- An element action (`click`, `fill`, `press`, `hover`, `focus`, `check`,
141
- `uncheck`, `select`, `drag`, and the coordinate actions `mousedown`, `mouseup`,
142
- `wheel`) carries a `target`, described from the browser side:
143
-
144
- - A locator is resolved once, waiting up to the action budget (5 s), so an
145
- element that renders late is guarded, not skipped. The guard sees that
146
- element and the action then runs on the same element handle.
147
- - A coordinate action (`browser.mouse` click/down/up/move, `browser.drag` from
148
- or to x/y, `browser.wheel` at the mouse's position) is guarded on the element
149
- at that point.
150
- - The elements are found in an isolated world the page's scripts cannot reach
151
- (the element's exact box, open shadow roots included; for a point,
152
- `elementFromPoint`), then described over CDP from each backend node:
153
- `DOM.describeNode` for tag and attributes, `Accessibility.getPartialAXTree`
154
- for role, name and accessibility ancestors. A page cannot change what the
155
- guard reads by overriding DOM functions. Over AlmostCDP the CDP endpoint
156
- itself runs in the page, so there the description is only as trustworthy as
157
- the page's world.
158
- - A target that cannot be resolved or described (inside an embedded frame or a
159
- closed shadow root, without a box, or a CDP failure) refuses the action with
160
- `UNSUPPORTED`; the guard is never skipped.
133
+ A host's `actionGuard(action)` is asked before every action that can change the
134
+ page or send it input, and before each `browser.script` (`{action: "script", source,
135
+ args}`); throwing a `BrowserActionRefusal` answers the call with its code, such as
136
+ `APPROVAL_REQUIRED`. Reading (status, snapshot, query, wait, box) is not asked;
137
+ `hover` is asked like any element action, and moving the mouse is not.
138
+
139
+ - Element actions (`click`, `fill`, `press`, `hover`, `focus`, `check`, `uncheck`,
140
+ `select`) carry a `target` described from the browser side. The locator is
141
+ resolved once (waiting up to 5 s) and the action runs on that same element
142
+ handle. The handle must be in the page's main frame and must be one of the
143
+ elements found at its box in an isolated world (a one-off marker attribute on
144
+ the handle confirms it); each is described over CDP (`DOM.describeNode` for tag
145
+ and attributes, `Accessibility.getPartialAXTree` for role, name and ancestors,
146
+ plus its form membership and, when unnamed, its own text). An element in a
147
+ `<label>` brings the control the label forwards to. A locator that resolves in
148
+ another frame, to a frame, or to a box more than eight elements share is refused.
149
+ A `select` carries the chosen options' labels and values.
150
+ - A locator `press` focuses its element and is refused unless focus is then on or
151
+ inside it; a press without a locator is described from the focused element and
152
+ refused inside a frame or a closed shadow root.
153
+ - Raw pointer input (`browser.mouse` click/down/up, `browser.wheel`,
154
+ `browser.drag`) carries `pointer: true` and the element at the point as best
155
+ known (`target.unidentified` says why when it cannot be told); a drag carries
156
+ both points and the element at the drop point. The mouse is moved to the point
157
+ before every down, up and wheel. After a locator action the position is that
158
+ element's box centre, or unknown, and a press then needs coordinates.
159
+ - `back`, `forward`, `reload` and `scroll` are page actions (`{action, url}`).
160
+ - Just before any input is dispatched, the executor confirms the page's main frame
161
+ still holds the document the action was checked on (its `loaderId` and URL) with
162
+ no navigation requested or loading (a navigation counts as settled once its
163
+ document commits, it moves within the document, loading stops, as for a 204
164
+ answer, or it becomes a download), then calls the host's `beforeInput({url})`;
165
+ a change refuses the action with `STALE_PAGE` and nothing is sent. A pointer
166
+ action on a locator first waits for its element in a trial run, so the
167
+ confirmation comes as late as it can.
168
+
169
+ A script gets the page through a membrane. When the script ends or its time runs
170
+ out, every later call through it throws, and the routes, exposed bindings and
171
+ functions, init scripts and listeners it installed are removed.
161
172
 
162
173
  A host's `snapshotExclude` is a CSS selector for its own elements in the page
163
174
  (an overlay, a launcher): `browser.snapshot` leaves out the nodes of every
@@ -41,9 +41,26 @@ export interface PlaywrightOperationExecutorOptions {
41
41
  * same.
42
42
  */
43
43
  snapshotExclude?: string;
44
+ /**
45
+ * The host's last check just before input is dispatched to the page, after
46
+ * the executor has confirmed the main frame still holds the checked
47
+ * document with no navigation in flight. `url` is the page URL the action
48
+ * was checked on. Throwing a `BrowserActionRefusal` refuses the action; no
49
+ * input has been sent.
50
+ */
51
+ beforeInput?: (checked: {
52
+ url: string;
53
+ }) => void | Promise<void>;
44
54
  }
45
55
  /** One action an operation is about to perform. */
46
- export type PlaywrightAction = PlaywrightElementAction | PlaywrightScriptAction;
56
+ export type PlaywrightAction = PlaywrightElementAction | PlaywrightPageAction | PlaywrightScriptAction;
57
+ /** An action on the page as a whole: history navigation, reload, scrolling. */
58
+ export interface PlaywrightPageAction {
59
+ action: "back" | "forward" | "reload" | "scroll";
60
+ /** The page's URL when the action was asked about. */
61
+ url: string;
62
+ value?: unknown;
63
+ }
47
64
  export type { GuardedNode, GuardedTarget } from "./guard.js";
48
65
  /** An action that lands on an element: by locator, or at a viewport point. */
49
66
  export interface PlaywrightElementAction {
@@ -51,6 +68,12 @@ export interface PlaywrightElementAction {
51
68
  /** What the action lands on, described from the browser side. */
52
69
  target: GuardedTarget;
53
70
  value?: unknown;
71
+ /**
72
+ * Raw pointer input (`browser.mouse` down/up/click, `browser.wheel`,
73
+ * `browser.drag`): the target is the element at `target.point` as best
74
+ * known, which a page can change between the look and the press.
75
+ */
76
+ pointer?: boolean;
54
77
  }
55
78
  export interface PlaywrightScriptAction {
56
79
  /** `browser.script`: the author's source, run with the real `page`. */
@@ -71,7 +94,12 @@ export declare class PlaywrightOperationExecutor {
71
94
  private readonly options;
72
95
  private readonly ready;
73
96
  private readonly targets;
74
- /** Where the mouse is: `page.mouse` keeps it, but does not report it. */
97
+ /**
98
+ * Where the mouse is: `page.mouse` keeps it, but does not report it. A
99
+ * locator action moves it to the element's clickable point; it is then the
100
+ * centre of that element's box as measured after the action, or unknown
101
+ * (null) when that cannot be measured, and a press needs coordinates.
102
+ */
75
103
  private mouse;
76
104
  constructor(page: Page, options: PlaywrightOperationExecutorOptions);
77
105
  execute(raw: unknown): Promise<BrowserOperationResult>;
@@ -95,7 +123,18 @@ export declare class PlaywrightOperationExecutor {
95
123
  * action runs on the locator. Resolution or description failing refuses.
96
124
  */
97
125
  private guarded;
98
- /** Asks the host's policy about the element at a viewport point. */
126
+ /** The document an action is checked on; input later goes only to it. */
127
+ private checkpoint;
128
+ /** Just before input: the same document, no navigation in flight, and the host's own last check. */
129
+ private dispatching;
130
+ /** The page-level action's guard. */
131
+ private guardPage;
132
+ /** The pointer's position for a press that names none; unknown after a locator action. */
133
+ private pointer;
134
+ /**
135
+ * Asks the host's policy about raw pointer input at a viewport point; the
136
+ * target is the element there as best known (`unidentified` when not).
137
+ */
99
138
  private guardPoint;
100
139
  /** A browser-side description, or the refusal that replaces the action. */
101
140
  private describe;