omowright 0.2.0 → 0.3.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/README.md +24 -22
- package/TOOLS.md +6 -6
- package/dist/agent-tabs.d.ts +56 -0
- package/dist/aria-hidden.d.ts +1 -0
- package/dist/aside/cli-binary.d.ts +7 -0
- package/dist/aside/cli-contract.d.ts +9 -0
- package/dist/aside/errors.d.ts +8 -0
- package/dist/aside/line-transport.d.ts +11 -0
- package/dist/aside/mcp-transport.d.ts +11 -0
- package/dist/aside/onboard.d.ts +76 -0
- package/dist/aside/session-types.d.ts +68 -0
- package/dist/aside/session.d.ts +20 -0
- package/{bin/omowright-cloak.mjs → dist/bin/omowright-cloak.js} +28 -31
- package/dist/bridge-schemas.d.ts +326 -0
- package/dist/bridge-transport.d.ts +144 -0
- package/dist/browser-context.d.ts +4024 -0
- package/dist/browser-process.d.ts +10 -0
- package/dist/bsk/browser-signals.d.ts +23 -0
- package/dist/bsk/browsers.d.ts +46 -0
- package/dist/bsk/connect.d.ts +23 -0
- package/dist/bsk/daemon-info.d.ts +16 -0
- package/dist/bsk/external-extension.d.ts +74 -0
- package/dist/bsk/identify-browser.d.ts +48 -0
- package/dist/bsk/install-cli.d.ts +37 -0
- package/dist/bsk/ipc-client.d.ts +45 -0
- package/dist/bsk/onboard.d.ts +96 -0
- package/dist/bsk/reply-fields.d.ts +3 -0
- package/dist/bsk/screenshot.d.ts +24 -0
- package/dist/bsk/session.d.ts +142 -0
- package/dist/bsk/snapshot.d.ts +16 -0
- package/dist/bsk/targets.d.ts +20 -0
- package/dist/captcha-wait.d.ts +17 -0
- package/dist/captcha.d.ts +46 -0
- package/dist/cdp-errors.d.ts +38 -0
- package/dist/cdp-methods.d.ts +10 -0
- package/dist/cdp-protocol.d.ts +459 -0
- package/dist/chrome-profile.d.ts +77 -0
- package/dist/chrome.d.ts +130 -0
- package/dist/cloak-profile.d.ts +43 -0
- package/dist/connection.d.ts +4024 -0
- package/dist/console-events.d.ts +22 -0
- package/dist/cookies.d.ts +42 -0
- package/dist/core.d.ts +10810 -0
- package/dist/cua.d.ts +56 -0
- package/dist/dialog-policy.d.ts +43 -0
- package/dist/ego/bindings.d.ts +68 -0
- package/dist/ego/cdp-client.d.ts +28 -0
- package/dist/ego/client.d.ts +8 -0
- package/dist/ego/errors.d.ts +7 -0
- package/dist/emulate.d.ts +62 -0
- package/dist/engines.d.ts +59 -0
- package/dist/events.d.ts +93 -0
- package/dist/frames-snapshot.d.ts +58 -0
- package/dist/har.d.ts +88 -0
- package/dist/human-handoff.d.ts +30 -0
- package/{src/index.js → dist/index.d.ts} +11 -55
- package/dist/index.js +39262 -0
- package/dist/injected.d.ts +1 -0
- package/dist/instance-lock.d.ts +5 -0
- package/dist/instances.d.ts +45 -0
- package/dist/internal-capability.d.ts +1 -0
- package/dist/launch-endpoint.d.ts +34 -0
- package/dist/layers.d.ts +31 -0
- package/dist/llm.d.ts +1349 -0
- package/dist/lock-backend-win32-xbcm60vz.js +57 -0
- package/dist/lock-backend-win32.d.ts +3 -0
- package/dist/lock-backend.d.ts +6 -0
- package/dist/native-host-win32.d.ts +38 -0
- package/dist/network-events.d.ts +66 -0
- package/dist/network-snoop.d.ts +56 -0
- package/dist/nul-frames.d.ts +4 -0
- package/dist/open-shadow-query.d.ts +1 -0
- package/dist/owner-only.d.ts +15 -0
- package/dist/page-bundle.js +1587 -0
- package/dist/page-events.d.ts +25 -0
- package/dist/page-routes.d.ts +30 -0
- package/dist/page-setup.d.ts +55 -0
- package/dist/pipe.d.ts +71 -0
- package/dist/process-start-time.d.ts +2 -0
- package/dist/read-property.d.ts +2 -0
- package/dist/routes.d.ts +60 -0
- package/dist/running-browser.d.ts +39 -0
- package/dist/scroll-collect.d.ts +36 -0
- package/dist/serial-emitter.d.ts +5 -0
- package/dist/shared-connections.d.ts +11 -0
- package/dist/snapshot-diff.d.ts +57 -0
- package/dist/text-matching.d.ts +21 -0
- package/dist/trace.d.ts +59 -0
- package/dist/url-match.d.ts +7 -0
- package/dist/viewport.d.ts +26 -0
- package/dist/ws.d.ts +62 -0
- package/package.json +47 -26
- package/presets/agent-events/SKILL.md +1 -1
- package/presets/captcha/SKILL.md +1 -3
- package/presets/chrome/SKILL.md +2 -2
- package/presets/cloak-bridge/SKILL.md +11 -11
- package/presets/network/SKILL.md +15 -13
- package/presets/visual-browse/SKILL.md +14 -10
- package/skills/omowright/SKILL.md +77 -47
- package/skills/omowright/references/aside.md +50 -0
- package/skills/omowright/references/browserskill.md +29 -32
- package/skills/omowright/references/ego.md +24 -0
- package/skills/omowright/references/eval-kernel.md +44 -23
- package/skills/omowright/references/frames-layers-human.md +16 -7
- package/skills/omowright/references/quickstart.md +3 -3
- package/skills/omowright/references/stealth.md +7 -7
- package/src/agent-tabs.js +0 -179
- package/src/aria-hidden.js +0 -47
- package/src/bridge-schemas.js +0 -44
- package/src/bridge-transport.js +0 -83
- package/src/browser-context.js +0 -105
- package/src/browser-process.js +0 -127
- package/src/bsk/browser-signals.js +0 -90
- package/src/bsk/browsers.js +0 -114
- package/src/bsk/connect.js +0 -75
- package/src/bsk/daemon-info.js +0 -100
- package/src/bsk/external-extension.js +0 -110
- package/src/bsk/identify-browser.js +0 -88
- package/src/bsk/install-cli.js +0 -81
- package/src/bsk/ipc-client.js +0 -236
- package/src/bsk/onboard.js +0 -140
- package/src/bsk/screenshot.js +0 -49
- package/src/bsk/session.js +0 -131
- package/src/bsk/snapshot.js +0 -56
- package/src/bsk/targets.js +0 -25
- package/src/captcha-wait.js +0 -79
- package/src/captcha.js +0 -142
- package/src/cdp-errors.js +0 -23
- package/src/cdp-methods.js +0 -69
- package/src/chrome-profile.js +0 -176
- package/src/chrome.js +0 -194
- package/src/cloak-profile.js +0 -266
- package/src/connection.js +0 -234
- package/src/console-events.js +0 -12
- package/src/cookies.js +0 -39
- package/src/core.js +0 -1702
- package/src/cua.js +0 -74
- package/src/dialog-policy.js +0 -80
- package/src/emulate.js +0 -127
- package/src/events.js +0 -111
- package/src/frames-snapshot.js +0 -138
- package/src/har.js +0 -103
- package/src/human-handoff.js +0 -124
- package/src/injected.js +0 -3
- package/src/instance-lock.js +0 -74
- package/src/instances.js +0 -490
- package/src/internal-capability.js +0 -1
- package/src/launch-endpoint.js +0 -185
- package/src/layers.js +0 -138
- package/src/llm.js +0 -201
- package/src/lock-backend-win32.js +0 -54
- package/src/lock-backend.js +0 -81
- package/src/native-host-win32.js +0 -201
- package/src/network-events.js +0 -223
- package/src/network-snoop.js +0 -229
- package/src/nul-frames.js +0 -28
- package/src/open-shadow-query.js +0 -101
- package/src/owner-only.js +0 -196
- package/src/page-bundle.js +0 -1478
- package/src/page-events.js +0 -45
- package/src/page-routes.js +0 -94
- package/src/page-setup.js +0 -239
- package/src/pipe.js +0 -418
- package/src/process-start-time.js +0 -64
- package/src/routes.js +0 -256
- package/src/running-browser.js +0 -85
- package/src/scroll-collect.js +0 -73
- package/src/serial-emitter.js +0 -17
- package/src/shared-connections.js +0 -285
- package/src/snapshot-diff.js +0 -75
- package/src/text-matching.js +0 -101
- package/src/trace.js +0 -183
- package/src/url-match.js +0 -148
- package/src/viewport.js +0 -12
package/src/connection.js
DELETED
|
@@ -1,234 +0,0 @@
|
|
|
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
|
-
import { createAgentTabs, getAgentTabs } from "./agent-tabs.js";
|
|
11
|
-
import { repinViewport } from "./viewport.js";
|
|
12
|
-
import { BrowserContext } from "./browser-context.js";
|
|
13
|
-
|
|
14
|
-
export class TabRepository {
|
|
15
|
-
#client;
|
|
16
|
-
constructor(client) { this.#client = client; }
|
|
17
|
-
async listTargets() { return this.#client.discoverTargets(); }
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class BrowserConnection {
|
|
21
|
-
#client;
|
|
22
|
-
#sessions;
|
|
23
|
-
#pages = new Map();
|
|
24
|
-
#contexts = new Map();
|
|
25
|
-
#storageRoot;
|
|
26
|
-
#popups = new Map();
|
|
27
|
-
#popupTargets = new Map();
|
|
28
|
-
#attachingPopups = new Map();
|
|
29
|
-
#ownedPopups = new Set();
|
|
30
|
-
#popupOff = [];
|
|
31
|
-
|
|
32
|
-
constructor(client, options = {}) {
|
|
33
|
-
this.#client = client;
|
|
34
|
-
this.#sessions = new SessionManager(client);
|
|
35
|
-
this.tabs = new TabRepository(client);
|
|
36
|
-
this.#storageRoot = path.resolve(options.storageRoot ?? process.cwd());
|
|
37
|
-
this.#popupOff.push(client.on("Target.targetCreated", ({ targetInfo }) => {
|
|
38
|
-
if (targetInfo?.type !== "page" || !this.#acceptsPopup(targetInfo.openerId)) return;
|
|
39
|
-
// Target discovery and Page.windowOpen are independently dispatched. Keep
|
|
40
|
-
// the target's opener identity even when discovery wins that race.
|
|
41
|
-
const targets = this.#popupTargets.get(targetInfo.openerId) ?? [];
|
|
42
|
-
targets.push({ targetId: targetInfo.targetId });
|
|
43
|
-
this.#popupTargets.set(targetInfo.openerId, targets);
|
|
44
|
-
this.#matchPopups(targetInfo.openerId);
|
|
45
|
-
}));
|
|
46
|
-
this.#popupOff.push(client.on("Target.targetDestroyed", ({ targetId }) => {
|
|
47
|
-
this.#ownedPopups.delete(targetId);
|
|
48
|
-
const error = Error("Popup closed before attachment completed");
|
|
49
|
-
this.#attachingPopups.get(targetId)?.reject(error);
|
|
50
|
-
for (const targets of this.#popupTargets.values()) {
|
|
51
|
-
const target = targets.find(target => target.targetId === targetId);
|
|
52
|
-
if (target) target.error = error;
|
|
53
|
-
}
|
|
54
|
-
}));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async initialize() {
|
|
58
|
-
await this.#client.ensureConnected();
|
|
59
|
-
return this;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
get cdp() { return this.#client; }
|
|
63
|
-
|
|
64
|
-
setDialogPolicy(policy) {
|
|
65
|
-
if (typeof this.#client.setDialogPolicy !== "function") {
|
|
66
|
-
throw new Error("dialog policy is not supported by this transport");
|
|
67
|
-
}
|
|
68
|
-
this.#client.setDialogPolicy(policy);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async listTargets() { return this.tabs.listTargets(); }
|
|
72
|
-
|
|
73
|
-
async newTab(url = "about:blank") {
|
|
74
|
-
return (await (getAgentTabs(this) ?? createAgentTabs(this)).create(url)).page;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
#acceptsPopup(openerId) {
|
|
78
|
-
return !!getAgentTabs(this)?.get(openerId) &&
|
|
79
|
-
this.#pages.get(openerId)?.page.events.listenerCount("popup") > 0;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
#matchPopups(openerId) {
|
|
83
|
-
const targets = this.#popupTargets.get(openerId);
|
|
84
|
-
const queue = this.#popups.get(openerId);
|
|
85
|
-
while (targets?.length && queue?.length) {
|
|
86
|
-
const target = targets.shift();
|
|
87
|
-
const pending = queue.shift();
|
|
88
|
-
if (target.error) pending.reject(target.error);
|
|
89
|
-
else {
|
|
90
|
-
this.#attachingPopups.set(target.targetId, pending);
|
|
91
|
-
this.#ownedPopups.add(target.targetId);
|
|
92
|
-
pending.operation = this.#attachPopup(target.targetId, pending).catch(pending.reject).finally(() => {
|
|
93
|
-
this.#attachingPopups.delete(target.targetId);
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (!targets?.length) this.#popupTargets.delete(openerId);
|
|
98
|
-
if (!queue?.length) this.#popups.delete(openerId);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async #attachPopup(targetId, pending) {
|
|
102
|
-
const tabs = getAgentTabs(this) ?? createAgentTabs(this);
|
|
103
|
-
const { page } = await tabs.adopt(targetId);
|
|
104
|
-
page.popupMetadata = Object.freeze(pending.metadata);
|
|
105
|
-
await page.waitForLoadState("interactive");
|
|
106
|
-
pending.resolve(page);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
async attachPage(targetId) {
|
|
110
|
-
if (this.#pages.has(targetId)) return this.#pages.get(targetId).page;
|
|
111
|
-
const sessionId = await this.#sessions.resolvePageSession(targetId);
|
|
112
|
-
const frames = new FrameManager(this.#client, targetId, sessionId);
|
|
113
|
-
await frames.initialize();
|
|
114
|
-
|
|
115
|
-
const entry = { frames, page: null };
|
|
116
|
-
const host = this.#createPageHost(targetId, entry);
|
|
117
|
-
const page = new OmOPage(this.#client, frames, targetId, sessionId, host);
|
|
118
|
-
const { targetInfo } = await this.#client.send("Target.getTargetInfo", { targetId });
|
|
119
|
-
const contextId = targetInfo.browserContextId;
|
|
120
|
-
if (!this.#contexts.has(contextId)) this.#contexts.set(contextId, new BrowserContext(this, contextId));
|
|
121
|
-
const context = this.#contexts.get(contextId);
|
|
122
|
-
page.context = () => context;
|
|
123
|
-
for (const frame of frames.frames.values()) context.trackOrigin(frame.url);
|
|
124
|
-
page.on("framenavigated", frame => context.trackOrigin(frame.url));
|
|
125
|
-
entry.page = page;
|
|
126
|
-
this.#pages.set(targetId, entry);
|
|
127
|
-
return page;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
#createPageHost(targetId, entry) {
|
|
131
|
-
return {
|
|
132
|
-
daemonSession: { accountId: 0, id: "standalone" },
|
|
133
|
-
extensionBridgeRoute: {},
|
|
134
|
-
page: null,
|
|
135
|
-
resolvePageSession: (id, preferred) => this.#sessions.resolvePageSession(id, preferred),
|
|
136
|
-
setViewportSize: async size => {
|
|
137
|
-
const tabs = getAgentTabs(this);
|
|
138
|
-
if (tabs?.get(targetId)) await tabs.repin(targetId, size);
|
|
139
|
-
else await repinViewport(entry.page, size);
|
|
140
|
-
},
|
|
141
|
-
resolvePath: value => path.resolve(this.#storageRoot, value),
|
|
142
|
-
ensurePath: async value => {
|
|
143
|
-
const resolved = path.resolve(this.#storageRoot, value);
|
|
144
|
-
await mkdir(path.dirname(resolved), { recursive: true });
|
|
145
|
-
return resolved;
|
|
146
|
-
},
|
|
147
|
-
registerReadableDownload: value => value,
|
|
148
|
-
isReadableDownload: () => false,
|
|
149
|
-
resolvePopup: async metadata => {
|
|
150
|
-
if (!this.#acceptsPopup(targetId)) return;
|
|
151
|
-
const queue = this.#popups.get(targetId) ?? [];
|
|
152
|
-
const promise = new Promise((resolve, reject) => queue.push({
|
|
153
|
-
resolve, reject, metadata: { url: metadata.url, windowName: metadata.windowName },
|
|
154
|
-
}));
|
|
155
|
-
this.#popups.set(targetId, queue);
|
|
156
|
-
this.#matchPopups(targetId);
|
|
157
|
-
return promise;
|
|
158
|
-
},
|
|
159
|
-
openPopupTab: async () => { throw Error("Popup tab control requires the extension bridge"); },
|
|
160
|
-
closeTab: async (_page, options = {}) => {
|
|
161
|
-
if (options.runBeforeUnload) {
|
|
162
|
-
await this.#client.send("Page.close", undefined, await this.#sessions.resolvePageSession(targetId));
|
|
163
|
-
} else {
|
|
164
|
-
await this.#client.send("Target.closeTarget", { targetId });
|
|
165
|
-
}
|
|
166
|
-
await entry.page?.dispose();
|
|
167
|
-
await entry.frames.dispose();
|
|
168
|
-
this.#pages.delete(targetId);
|
|
169
|
-
},
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
async close() {
|
|
174
|
-
for (const off of this.#popupOff) off();
|
|
175
|
-
for (const queue of this.#popups.values()) {
|
|
176
|
-
for (const pending of queue) pending.reject(Error("Browser connection closed"));
|
|
177
|
-
}
|
|
178
|
-
this.#popups.clear();
|
|
179
|
-
this.#popupTargets.clear();
|
|
180
|
-
for (const pending of this.#attachingPopups.values()) pending.reject(Error("Browser connection closed"));
|
|
181
|
-
await Promise.all([...this.#attachingPopups.values()].map(pending => pending.operation));
|
|
182
|
-
const tabs = getAgentTabs(this);
|
|
183
|
-
if (tabs) {
|
|
184
|
-
await Promise.all([...this.#ownedPopups].filter(id => tabs.get(id)).map(id => tabs.close(id)));
|
|
185
|
-
await tabs.dispose({ closeOwned: false });
|
|
186
|
-
}
|
|
187
|
-
for (const [targetId, entry] of [...this.#pages]) {
|
|
188
|
-
await entry.page.dispose().catch(() => {});
|
|
189
|
-
await entry.frames.dispose().catch(() => {});
|
|
190
|
-
this.#pages.delete(targetId);
|
|
191
|
-
}
|
|
192
|
-
await this.#sessions.dispose();
|
|
193
|
-
await this.#client.close();
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// `await using browser = await connect(...)` closes the connection when the
|
|
197
|
-
// scope ends, also on a throw, so an agent script exits on its own (#244).
|
|
198
|
-
async [Symbol.asyncDispose]() {
|
|
199
|
-
await this.close();
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// The browser's WebSocket URL carries its GUID: a ws:// URL is one already, an
|
|
204
|
-
// HTTP endpoint answers it on /json/version (no WebSocket, so no consent prompt).
|
|
205
|
-
async function browserKey(client, cdpUrl) {
|
|
206
|
-
if (/^wss?:\/\//.test(cdpUrl)) return cdpUrl;
|
|
207
|
-
return (await client.discoverVersion()).webSocketDebuggerUrl;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Attaches in one process share one connection per browser (#76): each new
|
|
211
|
-
// connection to a user's Chrome is a new "Allow remote debugging?" prompt.
|
|
212
|
-
function createClient(cdpHttpUrl, options) {
|
|
213
|
-
if (typeof cdpHttpUrl !== "string" || cdpHttpUrl.length === 0) {
|
|
214
|
-
throw new TypeError("connect(cdpHttpUrl) requires a Chromium CDP HTTP URL");
|
|
215
|
-
}
|
|
216
|
-
return new CdpClient({ cdpUrl: cdpHttpUrl, ...options.client, dialogPolicy: options.dialogPolicy ?? options.client?.dialogPolicy });
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// A connection of its own, never shared: for callers that lease or own the
|
|
220
|
-
// connection themselves (the named-instance registry).
|
|
221
|
-
export async function openConnection(cdpHttpUrl, options = {}) {
|
|
222
|
-
return new BrowserConnection(createClient(cdpHttpUrl, options), options).initialize();
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export async function connect(cdpHttpUrl, options = {}) {
|
|
226
|
-
const client = createClient(cdpHttpUrl, options);
|
|
227
|
-
if (!canShareConnection(options)) return new BrowserConnection(client, options).initialize();
|
|
228
|
-
const key = await browserKey(client, cdpHttpUrl);
|
|
229
|
-
// Opened on the resolved GUID URL, never the port: a reconnect then reaches
|
|
230
|
-
// only this browser, and fails once it is gone (#79 review).
|
|
231
|
-
return acquireSharedConnection(key, options, {
|
|
232
|
-
open: (snapshot) => openConnection(key, snapshot),
|
|
233
|
-
});
|
|
234
|
-
}
|
package/src/console-events.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export function subscribeConsoleEvents(page) {
|
|
2
|
-
return page.cdp.on("Runtime.consoleAPICalled", (event, metadata) => {
|
|
3
|
-
if (!metadata.sessionId || !page.frameManager.hasSession(metadata.sessionId)) return;
|
|
4
|
-
const text = (event.args ?? []).map(arg => {
|
|
5
|
-
if (arg.unserializableValue !== undefined) return arg.unserializableValue;
|
|
6
|
-
if (arg.value !== undefined) return typeof arg.value === "string" ? arg.value : String(arg.value);
|
|
7
|
-
return arg.description ?? arg.type;
|
|
8
|
-
}).join(" ");
|
|
9
|
-
page.events.emit("console", { type: () => event.type, text: () => text })
|
|
10
|
-
.catch(error => console.warn("[console] page event listener failed", error));
|
|
11
|
-
});
|
|
12
|
-
}
|
package/src/cookies.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export function cookieToCdp(cookie) {
|
|
2
|
-
const { name, value, url, domain, path, httpOnly, secure, sameSite } = cookie;
|
|
3
|
-
const out = { name, value, url, domain, path, httpOnly, secure, sameSite };
|
|
4
|
-
if (cookie.expires !== undefined && cookie.expires !== -1) out.expires = cookie.expires;
|
|
5
|
-
if (cookie.partitionKey !== undefined) {
|
|
6
|
-
out.partitionKey = { topLevelSite: cookie.partitionKey, hasCrossSiteAncestor: true };
|
|
7
|
-
}
|
|
8
|
-
return out;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function sanitizeCookies(cookies) {
|
|
12
|
-
const byKey = new Map();
|
|
13
|
-
for (const cookie of cookies) {
|
|
14
|
-
const out = {
|
|
15
|
-
name: cookie.name,
|
|
16
|
-
value: cookie.value,
|
|
17
|
-
path: cookie.path || "/",
|
|
18
|
-
secure: Boolean(cookie.secure),
|
|
19
|
-
httpOnly: Boolean(cookie.httpOnly),
|
|
20
|
-
};
|
|
21
|
-
if (cookie.name.startsWith("__Host-")) {
|
|
22
|
-
out.secure = true;
|
|
23
|
-
out.path = "/";
|
|
24
|
-
out.url = `https://${cookie.domain.replace(/^\./, "")}`;
|
|
25
|
-
} else {
|
|
26
|
-
out.domain = cookie.domain;
|
|
27
|
-
}
|
|
28
|
-
if (cookie.expires && cookie.expires > 0) out.expires = cookie.expires;
|
|
29
|
-
if (cookie.sameSite && (cookie.sameSite !== "None" || out.secure)) out.sameSite = cookie.sameSite;
|
|
30
|
-
const key = `${out.name}|${out.domain ?? out.url}`;
|
|
31
|
-
const prev = byKey.get(key);
|
|
32
|
-
if (!prev || (out.expires ?? 0) > (prev.expires ?? 0)) byKey.set(key, out);
|
|
33
|
-
}
|
|
34
|
-
return [...byKey.values()];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export async function injectCookies(page, cookies) {
|
|
38
|
-
await page._sendToTarget("Network.setCookies", { cookies: sanitizeCookies(cookies).map(cookieToCdp) });
|
|
39
|
-
}
|