@hmharness/browser 0.23.33 → 0.23.34
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/dist/page.js +45 -45
- package/package.json +31 -31
package/dist/page.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
/** Stamp [data-hmh-ref] onto visible interactive elements and return the
|
|
2
2
|
* serialized snapshot. Cap 80 elements — a longer list stops paying for
|
|
3
3
|
* its own tokens. Password VALUES are never read back. */
|
|
4
|
-
export const SNAPSHOT_EXPR = `(() => {
|
|
5
|
-
for (const el of document.querySelectorAll('[data-hmh-ref]')) el.removeAttribute('data-hmh-ref');
|
|
6
|
-
const sels = 'a[href], button, input, select, textarea, summary, [role], [contenteditable="true"], [onclick], [tabindex]';
|
|
7
|
-
const nodes = Array.from(document.querySelectorAll(sels));
|
|
8
|
-
const out = [];
|
|
9
|
-
let ref = 0;
|
|
10
|
-
for (const el of nodes) {
|
|
11
|
-
if (out.length >= 80) break;
|
|
12
|
-
const r = el.getBoundingClientRect();
|
|
13
|
-
const st = getComputedStyle(el);
|
|
14
|
-
if (r.width < 1 || r.height < 1 || st.visibility === 'hidden' || st.display === 'none') continue;
|
|
15
|
-
if (el.closest('[aria-hidden="true"]')) continue;
|
|
16
|
-
ref += 1;
|
|
17
|
-
el.setAttribute('data-hmh-ref', String(ref));
|
|
18
|
-
const e = { ref: ref, tag: el.tagName.toLowerCase() };
|
|
19
|
-
const role = el.getAttribute('role');
|
|
20
|
-
if (role) e.role = role;
|
|
21
|
-
const t = (el.innerText || el.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 80);
|
|
22
|
-
if (t) e.text = t;
|
|
23
|
-
const ph = el.getAttribute('placeholder');
|
|
24
|
-
if (ph) e.placeholder = ph.slice(0, 60);
|
|
25
|
-
const kind = el.getAttribute('type');
|
|
26
|
-
if ((el.tagName === 'INPUT' && kind !== 'password' || el.tagName === 'TEXTAREA') && el.value) e.value = String(el.value).slice(0, 60);
|
|
27
|
-
const href = el.getAttribute('href');
|
|
28
|
-
if (href) e.href = href.slice(0, 120);
|
|
29
|
-
out.push(e);
|
|
30
|
-
}
|
|
31
|
-
return JSON.stringify({ title: document.title, url: location.href, elements: out });
|
|
4
|
+
export const SNAPSHOT_EXPR = `(() => {
|
|
5
|
+
for (const el of document.querySelectorAll('[data-hmh-ref]')) el.removeAttribute('data-hmh-ref');
|
|
6
|
+
const sels = 'a[href], button, input, select, textarea, summary, [role], [contenteditable="true"], [onclick], [tabindex]';
|
|
7
|
+
const nodes = Array.from(document.querySelectorAll(sels));
|
|
8
|
+
const out = [];
|
|
9
|
+
let ref = 0;
|
|
10
|
+
for (const el of nodes) {
|
|
11
|
+
if (out.length >= 80) break;
|
|
12
|
+
const r = el.getBoundingClientRect();
|
|
13
|
+
const st = getComputedStyle(el);
|
|
14
|
+
if (r.width < 1 || r.height < 1 || st.visibility === 'hidden' || st.display === 'none') continue;
|
|
15
|
+
if (el.closest('[aria-hidden="true"]')) continue;
|
|
16
|
+
ref += 1;
|
|
17
|
+
el.setAttribute('data-hmh-ref', String(ref));
|
|
18
|
+
const e = { ref: ref, tag: el.tagName.toLowerCase() };
|
|
19
|
+
const role = el.getAttribute('role');
|
|
20
|
+
if (role) e.role = role;
|
|
21
|
+
const t = (el.innerText || el.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 80);
|
|
22
|
+
if (t) e.text = t;
|
|
23
|
+
const ph = el.getAttribute('placeholder');
|
|
24
|
+
if (ph) e.placeholder = ph.slice(0, 60);
|
|
25
|
+
const kind = el.getAttribute('type');
|
|
26
|
+
if ((el.tagName === 'INPUT' && kind !== 'password' || el.tagName === 'TEXTAREA') && el.value) e.value = String(el.value).slice(0, 60);
|
|
27
|
+
const href = el.getAttribute('href');
|
|
28
|
+
if (href) e.href = href.slice(0, 120);
|
|
29
|
+
out.push(e);
|
|
30
|
+
}
|
|
31
|
+
return JSON.stringify({ title: document.title, url: location.href, elements: out });
|
|
32
32
|
})()`;
|
|
33
33
|
/** Page text for reading (innerText keeps visual order; capped for context). */
|
|
34
|
-
export const READ_EXPR = `(() => {
|
|
35
|
-
const text = (document.body ? document.body.innerText : '').replace(/\\n{3,}/g, '\\n\\n');
|
|
36
|
-
return JSON.stringify({ title: document.title, url: location.href, text: text.slice(0, 12000), truncated: text.length > 12000 });
|
|
34
|
+
export const READ_EXPR = `(() => {
|
|
35
|
+
const text = (document.body ? document.body.innerText : '').replace(/\\n{3,}/g, '\\n\\n');
|
|
36
|
+
return JSON.stringify({ title: document.title, url: location.href, text: text.slice(0, 12000), truncated: text.length > 12000 });
|
|
37
37
|
})()`;
|
|
38
38
|
/** the querySelector string for a snapshot ref (ref is a validated
|
|
39
39
|
* integer, so single-quote wrapping needs no escaping) */
|
|
@@ -47,20 +47,20 @@ export function clickExpr(ref) {
|
|
|
47
47
|
/** Type into a snapshot ref — native value setter + input/change events
|
|
48
48
|
* (React/Vue-compatible), optional submit via form.requestSubmit(). */
|
|
49
49
|
export function typeExpr(ref, text, submit = false) {
|
|
50
|
-
return `(() => { const el = document.querySelector(${refQuery(ref)}); if (!el) return 'E_NO_REF'; el.focus(); el.scrollIntoView({ block: 'center' });
|
|
51
|
-
const value = ${JSON.stringify(text)};
|
|
52
|
-
if (el.isContentEditable) { el.textContent = value; }
|
|
53
|
-
else {
|
|
54
|
-
const proto = el.tagName === 'TEXTAREA' ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
|
|
55
|
-
const setter = Object.getOwnPropertyDescriptor(proto, 'value') && Object.getOwnPropertyDescriptor(proto, 'value').set;
|
|
56
|
-
if (setter) setter.call(el, value); else el.setAttribute('value', value);
|
|
57
|
-
}
|
|
58
|
-
el.dispatchEvent(new Event('input', { bubbles: true }));
|
|
59
|
-
el.dispatchEvent(new Event('change', { bubbles: true }));
|
|
60
|
-
if (${submit ? 'true' : 'false'}) {
|
|
61
|
-
const form = el.closest('form');
|
|
62
|
-
if (form) form.requestSubmit(); else el.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
|
|
63
|
-
}
|
|
50
|
+
return `(() => { const el = document.querySelector(${refQuery(ref)}); if (!el) return 'E_NO_REF'; el.focus(); el.scrollIntoView({ block: 'center' });
|
|
51
|
+
const value = ${JSON.stringify(text)};
|
|
52
|
+
if (el.isContentEditable) { el.textContent = value; }
|
|
53
|
+
else {
|
|
54
|
+
const proto = el.tagName === 'TEXTAREA' ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
|
|
55
|
+
const setter = Object.getOwnPropertyDescriptor(proto, 'value') && Object.getOwnPropertyDescriptor(proto, 'value').set;
|
|
56
|
+
if (setter) setter.call(el, value); else el.setAttribute('value', value);
|
|
57
|
+
}
|
|
58
|
+
el.dispatchEvent(new Event('input', { bubbles: true }));
|
|
59
|
+
el.dispatchEvent(new Event('change', { bubbles: true }));
|
|
60
|
+
if (${submit ? 'true' : 'false'}) {
|
|
61
|
+
const form = el.closest('form');
|
|
62
|
+
if (form) form.requestSubmit(); else el.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
|
|
63
|
+
}
|
|
64
64
|
return 'ok'; })()`;
|
|
65
65
|
}
|
|
66
66
|
/** Scroll: down|up|top|bottom (default 600px steps). */
|
package/package.json
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@hmharness/browser",
|
|
3
|
-
"version": "0.23.
|
|
4
|
-
"description": "hmharness BrowserOS driver — discovers, trust-pins and launches the BrowserOS AI browser (Chromium fork), then drives it over the Chrome DevTools Protocol. Client only, zero dependencies, dedicated profile: the user's daily browser is never touched.",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"types": "./dist/index.d.ts",
|
|
11
|
-
"default": "./dist/index.js"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"scripts": {
|
|
15
|
-
"build": "tsc -p tsconfig.build.json"
|
|
16
|
-
},
|
|
17
|
-
"dependencies": {
|
|
18
|
-
"@hmharness/kernel": "0.23.
|
|
19
|
-
},
|
|
20
|
-
"files": [
|
|
21
|
-
"dist"
|
|
22
|
-
],
|
|
23
|
-
"license": "MIT",
|
|
24
|
-
"repository": {
|
|
25
|
-
"type": "git",
|
|
26
|
-
"url": "git+https://github.com/swsgbl/hmharness.git"
|
|
27
|
-
},
|
|
28
|
-
"engines": {
|
|
29
|
-
"node": ">=22"
|
|
30
|
-
}
|
|
31
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@hmharness/browser",
|
|
3
|
+
"version": "0.23.34",
|
|
4
|
+
"description": "hmharness BrowserOS driver — discovers, trust-pins and launches the BrowserOS AI browser (Chromium fork), then drives it over the Chrome DevTools Protocol. Client only, zero dependencies, dedicated profile: the user's daily browser is never touched.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc -p tsconfig.build.json"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@hmharness/kernel": "0.23.34"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/swsgbl/hmharness.git"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=22"
|
|
30
|
+
}
|
|
31
|
+
}
|