omowright 0.0.0 → 0.1.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.
Files changed (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +282 -2
  3. package/TOOLS.md +366 -0
  4. package/bin/omowright-cloak.mjs +112 -0
  5. package/package.json +57 -4
  6. package/presets/agent-events/SKILL.md +75 -0
  7. package/presets/captcha/SKILL.md +129 -0
  8. package/presets/chrome/SKILL.md +84 -0
  9. package/presets/cloak-bridge/SKILL.md +43 -0
  10. package/presets/network/SKILL.md +126 -0
  11. package/presets/visual-browse/SKILL.md +103 -0
  12. package/skills/omowright/SKILL.md +193 -0
  13. package/skills/omowright/references/1password.md +118 -0
  14. package/skills/omowright/references/browserskill.md +186 -0
  15. package/skills/omowright/references/eval-kernel.md +100 -0
  16. package/skills/omowright/references/frames-layers-human.md +123 -0
  17. package/skills/omowright/references/quickstart.md +96 -0
  18. package/skills/omowright/references/stealth.md +174 -0
  19. package/src/agent-tabs.js +160 -0
  20. package/src/bridge-schemas.js +44 -0
  21. package/src/bridge-transport.js +57 -0
  22. package/src/browser-process.js +122 -0
  23. package/src/bsk/browser-signals.js +90 -0
  24. package/src/bsk/browsers.js +114 -0
  25. package/src/bsk/connect.js +45 -0
  26. package/src/bsk/daemon-info.js +100 -0
  27. package/src/bsk/external-extension.js +110 -0
  28. package/src/bsk/identify-browser.js +88 -0
  29. package/src/bsk/install-cli.js +81 -0
  30. package/src/bsk/ipc-client.js +236 -0
  31. package/src/bsk/onboard.js +133 -0
  32. package/src/bsk/screenshot.js +49 -0
  33. package/src/bsk/session.js +131 -0
  34. package/src/bsk/snapshot.js +56 -0
  35. package/src/bsk/targets.js +25 -0
  36. package/src/captcha-wait.js +74 -0
  37. package/src/captcha.js +142 -0
  38. package/src/cdp-errors.js +23 -0
  39. package/src/cdp-methods.js +61 -0
  40. package/src/chrome-profile.js +176 -0
  41. package/src/chrome.js +192 -0
  42. package/src/cloak-profile.js +266 -0
  43. package/src/connection.js +135 -0
  44. package/src/cookies.js +29 -0
  45. package/src/core.js +1710 -0
  46. package/src/cua.js +74 -0
  47. package/src/dialog-policy.js +80 -0
  48. package/src/emulate.js +127 -0
  49. package/src/events.js +111 -0
  50. package/src/frames-snapshot.js +138 -0
  51. package/src/har.js +103 -0
  52. package/src/human-handoff.js +122 -0
  53. package/src/index.js +86 -0
  54. package/src/injected.js +3 -0
  55. package/src/instance-lock.js +230 -0
  56. package/src/instances.js +493 -0
  57. package/src/internal-capability.js +1 -0
  58. package/src/launch-endpoint.js +185 -0
  59. package/src/layers.js +138 -0
  60. package/src/llm.js +201 -0
  61. package/src/lock-file.js +130 -0
  62. package/src/native-host-win32.js +201 -0
  63. package/src/network-events.js +201 -0
  64. package/src/network-snoop.js +229 -0
  65. package/src/open-shadow-query.js +22 -0
  66. package/src/owner-only.js +109 -0
  67. package/src/page-bundle.js +1397 -0
  68. package/src/page-routes.js +94 -0
  69. package/src/pipe.js +391 -0
  70. package/src/routes.js +256 -0
  71. package/src/running-browser.js +85 -0
  72. package/src/scroll-collect.js +73 -0
  73. package/src/serial-emitter.js +17 -0
  74. package/src/shared-connections.js +278 -0
  75. package/src/snapshot-diff.js +75 -0
  76. package/src/trace.js +183 -0
  77. package/src/url-match.js +148 -0
  78. package/src/viewport.js +12 -0
@@ -0,0 +1,135 @@
1
+ import path from "node:path";
2
+ import { mkdir } from "node:fs/promises";
3
+ import {
4
+ CdpClient,
5
+ FrameManager,
6
+ OmOPage,
7
+ SessionManager,
8
+ } from "./core.js";
9
+ import { acquireSharedConnection, canShareConnection } from "./shared-connections.js";
10
+
11
+ export class TabRepository {
12
+ #client;
13
+ constructor(client) { this.#client = client; }
14
+ async listTargets() { return this.#client.discoverTargets(); }
15
+ }
16
+
17
+ export class BrowserConnection {
18
+ #client;
19
+ #sessions;
20
+ #pages = new Map();
21
+ #storageRoot;
22
+
23
+ constructor(client, options = {}) {
24
+ this.#client = client;
25
+ this.#sessions = new SessionManager(client);
26
+ this.tabs = new TabRepository(client);
27
+ this.#storageRoot = path.resolve(options.storageRoot ?? process.cwd());
28
+ }
29
+
30
+ async initialize() {
31
+ await this.#client.ensureConnected();
32
+ return this;
33
+ }
34
+
35
+ get cdp() { return this.#client; }
36
+
37
+ setDialogPolicy(policy) {
38
+ if (typeof this.#client.setDialogPolicy !== "function") {
39
+ throw new Error("dialog policy is not supported by this transport");
40
+ }
41
+ this.#client.setDialogPolicy(policy);
42
+ }
43
+
44
+ async listTargets() { return this.tabs.listTargets(); }
45
+
46
+ async newTab(url = "about:blank") {
47
+ const { createAgentTabs } = await import("./agent-tabs.js");
48
+ return (await createAgentTabs(this).create(url)).page;
49
+ }
50
+
51
+ async attachPage(targetId) {
52
+ if (this.#pages.has(targetId)) return this.#pages.get(targetId).page;
53
+ const sessionId = await this.#sessions.resolvePageSession(targetId);
54
+ const frames = new FrameManager(this.#client, targetId, sessionId);
55
+ await frames.initialize();
56
+
57
+ const entry = { frames, page: null };
58
+ const host = this.#createPageHost(targetId, entry);
59
+ const page = new OmOPage(this.#client, frames, targetId, sessionId, host);
60
+ entry.page = page;
61
+ this.#pages.set(targetId, entry);
62
+ return page;
63
+ }
64
+
65
+ #createPageHost(targetId, entry) {
66
+ return {
67
+ daemonSession: { accountId: 0, id: "standalone" },
68
+ extensionBridgeRoute: {},
69
+ page: null,
70
+ resolvePageSession: (id, preferred) => this.#sessions.resolvePageSession(id, preferred),
71
+ resolvePath: value => path.resolve(this.#storageRoot, value),
72
+ ensurePath: async value => {
73
+ const resolved = path.resolve(this.#storageRoot, value);
74
+ await mkdir(path.dirname(resolved), { recursive: true });
75
+ return resolved;
76
+ },
77
+ registerReadableDownload: value => value,
78
+ isReadableDownload: () => false,
79
+ openPopupTab: async () => { throw Error("Popup tab control requires the extension bridge"); },
80
+ closeTab: async (_page, options = {}) => {
81
+ if (options.runBeforeUnload) {
82
+ await this.#client.send("Page.close", undefined, await this.#sessions.resolvePageSession(targetId));
83
+ } else {
84
+ await this.#client.send("Target.closeTarget", { targetId });
85
+ }
86
+ await entry.page?.dispose();
87
+ await entry.frames.dispose();
88
+ this.#pages.delete(targetId);
89
+ },
90
+ };
91
+ }
92
+
93
+ async close() {
94
+ for (const [targetId, entry] of [...this.#pages]) {
95
+ await entry.page.dispose().catch(() => {});
96
+ await entry.frames.dispose().catch(() => {});
97
+ this.#pages.delete(targetId);
98
+ }
99
+ await this.#sessions.dispose();
100
+ await this.#client.close();
101
+ }
102
+ }
103
+
104
+ // The browser's WebSocket URL carries its GUID: a ws:// URL is one already, an
105
+ // HTTP endpoint answers it on /json/version (no WebSocket, so no consent prompt).
106
+ async function browserKey(client, cdpUrl) {
107
+ if (/^wss?:\/\//.test(cdpUrl)) return cdpUrl;
108
+ return (await client.discoverVersion()).webSocketDebuggerUrl;
109
+ }
110
+
111
+ // Attaches in one process share one connection per browser (#76): each new
112
+ // connection to a user's Chrome is a new "Allow remote debugging?" prompt.
113
+ function createClient(cdpHttpUrl, options) {
114
+ if (typeof cdpHttpUrl !== "string" || cdpHttpUrl.length === 0) {
115
+ throw new TypeError("connect(cdpHttpUrl) requires a Chromium CDP HTTP URL");
116
+ }
117
+ return new CdpClient({ cdpUrl: cdpHttpUrl, ...options.client, dialogPolicy: options.dialogPolicy ?? options.client?.dialogPolicy });
118
+ }
119
+
120
+ // A connection of its own, never shared: for callers that lease or own the
121
+ // connection themselves (the named-instance registry).
122
+ export async function openConnection(cdpHttpUrl, options = {}) {
123
+ return new BrowserConnection(createClient(cdpHttpUrl, options), options).initialize();
124
+ }
125
+
126
+ export async function connect(cdpHttpUrl, options = {}) {
127
+ const client = createClient(cdpHttpUrl, options);
128
+ if (!canShareConnection(options)) return new BrowserConnection(client, options).initialize();
129
+ const key = await browserKey(client, cdpHttpUrl);
130
+ // Opened on the resolved GUID URL, never the port: a reconnect then reaches
131
+ // only this browser, and fails once it is gone (#79 review).
132
+ return acquireSharedConnection(key, options, {
133
+ open: (snapshot) => openConnection(key, snapshot),
134
+ });
135
+ }
package/src/cookies.js ADDED
@@ -0,0 +1,29 @@
1
+ export function sanitizeCookies(cookies) {
2
+ const byKey = new Map();
3
+ for (const cookie of cookies) {
4
+ const out = {
5
+ name: cookie.name,
6
+ value: cookie.value,
7
+ path: cookie.path || "/",
8
+ secure: Boolean(cookie.secure),
9
+ httpOnly: Boolean(cookie.httpOnly),
10
+ };
11
+ if (cookie.name.startsWith("__Host-")) {
12
+ out.secure = true;
13
+ out.path = "/";
14
+ out.url = `https://${cookie.domain.replace(/^\./, "")}`;
15
+ } else {
16
+ out.domain = cookie.domain;
17
+ }
18
+ if (cookie.expires && cookie.expires > 0) out.expires = cookie.expires;
19
+ if (cookie.sameSite && (cookie.sameSite !== "None" || out.secure)) out.sameSite = cookie.sameSite;
20
+ const key = `${out.name}|${out.domain ?? out.url}`;
21
+ const prev = byKey.get(key);
22
+ if (!prev || (out.expires ?? 0) > (prev.expires ?? 0)) byKey.set(key, out);
23
+ }
24
+ return [...byKey.values()];
25
+ }
26
+
27
+ export async function injectCookies(page, cookies) {
28
+ await page._sendToTarget("Network.setCookies", { cookies: sanitizeCookies(cookies) });
29
+ }