omowright 0.0.0 → 0.2.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/LICENSE +21 -0
- package/README.md +290 -2
- package/TOOLS.md +487 -0
- package/bin/omowright-cloak.mjs +112 -0
- package/package.json +57 -4
- package/presets/agent-events/SKILL.md +75 -0
- package/presets/captcha/SKILL.md +129 -0
- package/presets/chrome/SKILL.md +88 -0
- package/presets/cloak-bridge/SKILL.md +43 -0
- package/presets/network/SKILL.md +126 -0
- package/presets/visual-browse/SKILL.md +103 -0
- package/skills/omowright/SKILL.md +193 -0
- package/skills/omowright/references/1password.md +118 -0
- package/skills/omowright/references/browserskill.md +195 -0
- package/skills/omowright/references/eval-kernel.md +100 -0
- package/skills/omowright/references/frames-layers-human.md +123 -0
- package/skills/omowright/references/quickstart.md +109 -0
- package/skills/omowright/references/stealth.md +174 -0
- package/src/agent-tabs.js +179 -0
- package/src/aria-hidden.js +47 -0
- package/src/bridge-schemas.js +44 -0
- package/src/bridge-transport.js +83 -0
- package/src/browser-context.js +105 -0
- package/src/browser-process.js +127 -0
- package/src/bsk/browser-signals.js +90 -0
- package/src/bsk/browsers.js +114 -0
- package/src/bsk/connect.js +75 -0
- package/src/bsk/daemon-info.js +100 -0
- package/src/bsk/external-extension.js +110 -0
- package/src/bsk/identify-browser.js +88 -0
- package/src/bsk/install-cli.js +81 -0
- package/src/bsk/ipc-client.js +236 -0
- package/src/bsk/onboard.js +140 -0
- package/src/bsk/screenshot.js +49 -0
- package/src/bsk/session.js +131 -0
- package/src/bsk/snapshot.js +56 -0
- package/src/bsk/targets.js +25 -0
- package/src/captcha-wait.js +79 -0
- package/src/captcha.js +142 -0
- package/src/cdp-errors.js +23 -0
- package/src/cdp-methods.js +69 -0
- package/src/chrome-profile.js +176 -0
- package/src/chrome.js +194 -0
- package/src/cloak-profile.js +266 -0
- package/src/connection.js +234 -0
- package/src/console-events.js +12 -0
- package/src/cookies.js +39 -0
- package/src/core.js +1702 -0
- package/src/cua.js +74 -0
- package/src/dialog-policy.js +80 -0
- package/src/emulate.js +127 -0
- package/src/events.js +111 -0
- package/src/frames-snapshot.js +138 -0
- package/src/har.js +103 -0
- package/src/human-handoff.js +124 -0
- package/src/index.js +89 -0
- package/src/injected.js +3 -0
- package/src/instance-lock.js +74 -0
- package/src/instances.js +490 -0
- package/src/internal-capability.js +1 -0
- package/src/launch-endpoint.js +185 -0
- package/src/layers.js +138 -0
- package/src/llm.js +201 -0
- package/src/lock-backend-win32.js +54 -0
- package/src/lock-backend.js +81 -0
- package/src/native-host-win32.js +201 -0
- package/src/network-events.js +223 -0
- package/src/network-snoop.js +229 -0
- package/src/nul-frames.js +28 -0
- package/src/open-shadow-query.js +101 -0
- package/src/owner-only.js +196 -0
- package/src/page-bundle.js +1478 -0
- package/src/page-events.js +45 -0
- package/src/page-routes.js +94 -0
- package/src/page-setup.js +239 -0
- package/src/pipe.js +418 -0
- package/src/process-start-time.js +64 -0
- package/src/routes.js +256 -0
- package/src/running-browser.js +85 -0
- package/src/scroll-collect.js +73 -0
- package/src/serial-emitter.js +17 -0
- package/src/shared-connections.js +285 -0
- package/src/snapshot-diff.js +75 -0
- package/src/text-matching.js +101 -0
- package/src/trace.js +183 -0
- package/src/url-match.js +148 -0
- package/src/viewport.js +12 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
function injectHumanBanner(prompt) {
|
|
2
|
+
if (document.querySelector('[data-omowright-human="1"]')) return true;
|
|
3
|
+
const host = document.createElement("div");
|
|
4
|
+
host.setAttribute("data-omowright-human", "1");
|
|
5
|
+
host.style.cssText = "position:fixed;top:0;left:0;right:0;z-index:2147483647;display:block;visibility:visible;opacity:1;pointer-events:auto;";
|
|
6
|
+
const root = host.attachShadow({ mode: "open" });
|
|
7
|
+
const bar = document.createElement("div");
|
|
8
|
+
bar.setAttribute("style", "display:flex;align-items:center;gap:12px;padding:10px 16px;background:#111;color:#fff;font:14px/1.4 system-ui,sans-serif;");
|
|
9
|
+
const message = document.createElement("span");
|
|
10
|
+
message.textContent = prompt == null ? "" : String(prompt);
|
|
11
|
+
const button = document.createElement("button");
|
|
12
|
+
button.textContent = "Done";
|
|
13
|
+
button.addEventListener("click", () => {
|
|
14
|
+
window.__omowrightHumanDone = true;
|
|
15
|
+
});
|
|
16
|
+
bar.append(message, button);
|
|
17
|
+
root.append(bar);
|
|
18
|
+
(document.documentElement ?? document.body).appendChild(host);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function humanBannerPresent() {
|
|
23
|
+
return document.querySelector('[data-omowright-human="1"]') !== null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function humanDoneFlag() {
|
|
27
|
+
return window.__omowrightHumanDone === true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function querySelectorExists(selector) {
|
|
31
|
+
return document.querySelector(selector) !== null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function removeHumanBanner() {
|
|
35
|
+
document.querySelectorAll('[data-omowright-human="1"]').forEach(node => node.remove());
|
|
36
|
+
try {
|
|
37
|
+
delete window.__omowrightHumanDone;
|
|
38
|
+
} catch {
|
|
39
|
+
window.__omowrightHumanDone = undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function sleep(ms, signal) {
|
|
44
|
+
return new Promise(resolve => {
|
|
45
|
+
if (signal?.aborted) {
|
|
46
|
+
resolve();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const timer = setTimeout(() => {
|
|
50
|
+
signal?.removeEventListener("abort", onAbort);
|
|
51
|
+
resolve();
|
|
52
|
+
}, ms);
|
|
53
|
+
function onAbort() {
|
|
54
|
+
clearTimeout(timer);
|
|
55
|
+
resolve();
|
|
56
|
+
}
|
|
57
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function ensureBanner(page, prompt) {
|
|
62
|
+
try {
|
|
63
|
+
if (await page.evaluate(humanBannerPresent)) return;
|
|
64
|
+
await page.evaluate(injectHumanBanner, prompt ?? "");
|
|
65
|
+
} catch {
|
|
66
|
+
// Page may be mid-navigation; the next poll retries.
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function matchesUntil(page, until) {
|
|
71
|
+
if (until == null) return false;
|
|
72
|
+
if (typeof until === "function") return Boolean(await until(page));
|
|
73
|
+
if (typeof until === "object") {
|
|
74
|
+
if (Object.prototype.hasOwnProperty.call(until, "url")) {
|
|
75
|
+
const current = page.url();
|
|
76
|
+
const expected = until.url;
|
|
77
|
+
if (expected instanceof RegExp) return expected.test(current);
|
|
78
|
+
return String(current).includes(String(expected));
|
|
79
|
+
}
|
|
80
|
+
if (typeof until.selector === "string") {
|
|
81
|
+
try {
|
|
82
|
+
return Boolean(await page.evaluate(querySelectorExists, until.selector));
|
|
83
|
+
} catch {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function isDone(page) {
|
|
92
|
+
try {
|
|
93
|
+
return await page.evaluate(humanDoneFlag) === true;
|
|
94
|
+
} catch {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function requestHuman(page, { prompt, until, timeoutMs = 300000, pollMs = 500, signal } = {}) {
|
|
100
|
+
const started = Date.now();
|
|
101
|
+
const finish = (outcome, reason) => ({ outcome, elapsedMs: Date.now() - started, reason });
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
await page.bringToFront().catch(() => {});
|
|
105
|
+
await ensureBanner(page, prompt);
|
|
106
|
+
|
|
107
|
+
for (;;) {
|
|
108
|
+
if (signal?.aborted) return finish("cancelled", "signal");
|
|
109
|
+
// Check the conditions before the deadline: a slow bringToFront or banner
|
|
110
|
+
// injection must not time the wait out before its first check.
|
|
111
|
+
if (await matchesUntil(page, until)) return finish("continued", "until");
|
|
112
|
+
if (await isDone(page)) return finish("continued", "done-button");
|
|
113
|
+
if (Date.now() - started >= timeoutMs) return finish("timed_out", "timed_out");
|
|
114
|
+
// Human waits are idle time, not a race against a specific event; a timer
|
|
115
|
+
// poll loop is the correct tool here.
|
|
116
|
+
await ensureBanner(page, prompt);
|
|
117
|
+
const remaining = timeoutMs - (Date.now() - started);
|
|
118
|
+
if (remaining <= 0) return finish("timed_out", "timed_out");
|
|
119
|
+
await sleep(Math.min(pollMs, remaining), signal);
|
|
120
|
+
}
|
|
121
|
+
} finally {
|
|
122
|
+
await page.evaluate(removeHumanBanner).catch(() => {});
|
|
123
|
+
}
|
|
124
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export { connect, BrowserConnection, TabRepository } from "./connection.js";
|
|
2
|
+
export { OMOWRIGHT_PAGE_CDP_METHODS } from "./cdp-methods.js";
|
|
3
|
+
export {
|
|
4
|
+
CdpCommandTimeoutError,
|
|
5
|
+
CdpPipeClosedError,
|
|
6
|
+
CdpSessionCrashedError,
|
|
7
|
+
CdpSessionDetachedError,
|
|
8
|
+
connectPipe,
|
|
9
|
+
PipeCdpClient,
|
|
10
|
+
} from "./pipe.js";
|
|
11
|
+
export { connectNamed, listInstances } from "./instances.js";
|
|
12
|
+
export { RunningBrowserError, connectRunningBrowser, findRunningBrowser, readDevToolsActivePort } from "./running-browser.js";
|
|
13
|
+
export { SharedConnectionError } from "./shared-connections.js";
|
|
14
|
+
export {
|
|
15
|
+
buildCloakBrowserArgs,
|
|
16
|
+
connectCloakProfile,
|
|
17
|
+
findCloakBrowserPath,
|
|
18
|
+
resolveCloakProfile,
|
|
19
|
+
} from "./cloak-profile.js";
|
|
20
|
+
export { compactSnapshot, snapshotTokens, toolSchemas } from "./llm.js";
|
|
21
|
+
export { createCua } from "./cua.js";
|
|
22
|
+
export { createCaptcha, macOSVisionOcr } from "./captcha.js";
|
|
23
|
+
export { BROWSER_EVENT_NAMES, createEvents } from "./events.js";
|
|
24
|
+
export { PAGE_EVENT_NAMES } from "./page-events.js";
|
|
25
|
+
export { AgentTabManager, createAgentTabs } from "./agent-tabs.js";
|
|
26
|
+
export { DEFAULT_AGENT_VIEWPORT, repinViewport } from "./viewport.js";
|
|
27
|
+
export { createChromeApi } from "./bridge-transport.js";
|
|
28
|
+
export {
|
|
29
|
+
BridgeUnavailableError,
|
|
30
|
+
BridgeProtocolError,
|
|
31
|
+
createNativeMessagingHost,
|
|
32
|
+
createBridgeClient,
|
|
33
|
+
installNativeMessagingHost,
|
|
34
|
+
encodeFrame,
|
|
35
|
+
decodeFrames,
|
|
36
|
+
ExtensionHelloSchema,
|
|
37
|
+
HostHelloSchema,
|
|
38
|
+
EventSchema,
|
|
39
|
+
CommandSchema,
|
|
40
|
+
ResponseSchema,
|
|
41
|
+
} from "./bridge-transport.js";
|
|
42
|
+
export { injectCookies, sanitizeCookies } from "./cookies.js";
|
|
43
|
+
export { pageBundle } from "./injected.js";
|
|
44
|
+
export {
|
|
45
|
+
BrowserCdpCommandError,
|
|
46
|
+
CdpClient,
|
|
47
|
+
ElementHandle,
|
|
48
|
+
FrameLocator,
|
|
49
|
+
FrameManager,
|
|
50
|
+
Locator,
|
|
51
|
+
ModifierState,
|
|
52
|
+
OmOKeyboard,
|
|
53
|
+
OmOMouse,
|
|
54
|
+
OmOPage,
|
|
55
|
+
SessionManager,
|
|
56
|
+
UnsupportedOperationError,
|
|
57
|
+
VideoRecordingError,
|
|
58
|
+
WaitForFunctionTimeoutError,
|
|
59
|
+
takeSnapshot,
|
|
60
|
+
selectors,
|
|
61
|
+
} from "./core.js";
|
|
62
|
+
export { normalizeDialogPolicy, resolveDialogAction } from "./dialog-policy.js";
|
|
63
|
+
export { DEVICE_PRESETS, emulate } from "./emulate.js";
|
|
64
|
+
export { reconcileFrames, snapshotWithFrames } from "./frames-snapshot.js";
|
|
65
|
+
export { toHar } from "./har.js";
|
|
66
|
+
export { requestHuman } from "./human-handoff.js";
|
|
67
|
+
export { describeLayers, layersHeader, snapshotWithLayers } from "./layers.js";
|
|
68
|
+
export { createNetworkSnoop } from "./network-snoop.js";
|
|
69
|
+
export { NetworkBodyUnavailableError } from "./network-events.js";
|
|
70
|
+
export { createRoutes } from "./routes.js";
|
|
71
|
+
export { collectWhileScrolling } from "./scroll-collect.js";
|
|
72
|
+
export { createTrace } from "./trace.js";
|
|
73
|
+
export { BskIpcClient, BskRpcError, readDaemonInfo, resolveBskHome } from "./bsk/ipc-client.js";
|
|
74
|
+
export { BskSession } from "./bsk/session.js";
|
|
75
|
+
export { connectBrowserSkill, listBrowsers } from "./bsk/connect.js";
|
|
76
|
+
export { bskSnapshot, buildSnapshotExpression } from "./bsk/snapshot.js";
|
|
77
|
+
export {
|
|
78
|
+
BROWSERSKILL_EXTENSION_IDS,
|
|
79
|
+
STORE_PAGE_URLS,
|
|
80
|
+
detectBrowsers,
|
|
81
|
+
externalExtensionEntry,
|
|
82
|
+
registerExternalExtension,
|
|
83
|
+
unregisterExternalExtension,
|
|
84
|
+
} from "./bsk/external-extension.js";
|
|
85
|
+
export { catalogBrowsers } from "./bsk/browsers.js";
|
|
86
|
+
export { probeBrowserSignals } from "./bsk/browser-signals.js";
|
|
87
|
+
export { identifyBrowser } from "./bsk/identify-browser.js";
|
|
88
|
+
export { installBskCli } from "./bsk/install-cli.js";
|
|
89
|
+
export { bskDoctor, bskOnboard } from "./bsk/onboard.js";
|
package/src/injected.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { unlink } from "node:fs/promises";
|
|
2
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
3
|
+
import { probeOnce, tryAcquire } from "./lock-backend.js";
|
|
4
|
+
|
|
5
|
+
const localLocks = new Map();
|
|
6
|
+
|
|
7
|
+
export function isPidAlive(pid) {
|
|
8
|
+
try {
|
|
9
|
+
process.kill(pid, 0);
|
|
10
|
+
return true;
|
|
11
|
+
} catch (error) {
|
|
12
|
+
if (error?.code === "EPERM") return true;
|
|
13
|
+
if (error?.code === "ESRCH") return false;
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function unlinkIfPresent(target) {
|
|
19
|
+
await unlink(target).catch((error) => {
|
|
20
|
+
if (error?.code !== "ENOENT") throw error;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function acquireLock(lockPath, timeoutMs) {
|
|
25
|
+
const deadline = performance.now() + timeoutMs;
|
|
26
|
+
let delay = 10;
|
|
27
|
+
for (;;) {
|
|
28
|
+
const held = await tryAcquire(lockPath);
|
|
29
|
+
if (held) {
|
|
30
|
+
try {
|
|
31
|
+
await probeOnce(lockPath);
|
|
32
|
+
return held;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
await held.release();
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const remaining = deadline - performance.now();
|
|
39
|
+
if (remaining <= 0) throw new Error(`timed out waiting for instance lock ${lockPath}`);
|
|
40
|
+
await sleep(Math.min(remaining, delay * (0.75 + Math.random() * 0.5)));
|
|
41
|
+
delay = Math.min(delay * 2, 250);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function acquireLocalLock(key) {
|
|
46
|
+
const previous = localLocks.get(key) ?? Promise.resolve();
|
|
47
|
+
let releaseCurrent;
|
|
48
|
+
const current = new Promise((resolve) => {
|
|
49
|
+
releaseCurrent = resolve;
|
|
50
|
+
});
|
|
51
|
+
const tail = previous.then(() => current);
|
|
52
|
+
localLocks.set(key, tail);
|
|
53
|
+
await previous;
|
|
54
|
+
return () => {
|
|
55
|
+
releaseCurrent();
|
|
56
|
+
if (localLocks.get(key) === tail) localLocks.delete(key);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// The kernel owns exclusion and crash release; the local FIFO avoids polling
|
|
61
|
+
// between callers in this process. Neither acquisition nor release removes files.
|
|
62
|
+
export async function withLock(lockPath, { timeoutMs }, run) {
|
|
63
|
+
const releaseLocal = await acquireLocalLock(lockPath);
|
|
64
|
+
try {
|
|
65
|
+
const held = await acquireLock(lockPath, timeoutMs);
|
|
66
|
+
try {
|
|
67
|
+
return await run();
|
|
68
|
+
} finally {
|
|
69
|
+
await held.release();
|
|
70
|
+
}
|
|
71
|
+
} finally {
|
|
72
|
+
releaseLocal();
|
|
73
|
+
}
|
|
74
|
+
}
|