nothing-browser 0.0.21 → 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.
- package/LICENSE +1 -1
- package/dist/human/index.js +25 -1
- package/dist/piggy/captcha/index.d.ts +39 -0
- package/dist/piggy/captcha/index.d.ts.map +1 -0
- package/dist/piggy/capture/index.d.ts +48 -0
- package/dist/piggy/capture/index.d.ts.map +1 -0
- package/dist/piggy/dialog/index.d.ts +28 -0
- package/dist/piggy/dialog/index.d.ts.map +1 -0
- package/dist/piggy/export/index.d.ts +62 -0
- package/dist/piggy/export/index.d.ts.map +1 -0
- package/dist/piggy/find/index.d.ts +90 -0
- package/dist/piggy/find/index.d.ts.map +1 -0
- package/dist/piggy/http/index.d.ts +14 -0
- package/dist/piggy/http/index.d.ts.map +1 -0
- package/dist/piggy/human/index.d.ts +36 -4
- package/dist/piggy/human/index.d.ts.map +1 -1
- package/dist/piggy/iframe/index.d.ts +53 -0
- package/dist/piggy/iframe/index.d.ts.map +1 -0
- package/dist/piggy/interactions/index.d.ts +24 -0
- package/dist/piggy/interactions/index.d.ts.map +1 -0
- package/dist/piggy/media/index.d.ts +11 -0
- package/dist/piggy/media/index.d.ts.map +1 -0
- package/dist/piggy/navigation/index.d.ts +16 -0
- package/dist/piggy/navigation/index.d.ts.map +1 -0
- package/dist/piggy/provide/index.d.ts +81 -0
- package/dist/piggy/provide/index.d.ts.map +1 -0
- package/dist/piggy/proxy/index.d.ts +94 -0
- package/dist/piggy/proxy/index.d.ts.map +1 -0
- package/dist/piggy/register/index.d.ts.map +1 -1
- package/dist/piggy/router/index.d.ts +38 -0
- package/dist/piggy/router/index.d.ts.map +1 -0
- package/dist/piggy/session/index.d.ts +27 -0
- package/dist/piggy/session/index.d.ts.map +1 -0
- package/dist/piggy/tabs/index.d.ts +10 -0
- package/dist/piggy/tabs/index.d.ts.map +1 -0
- package/dist/piggy/wait/index.d.ts +28 -0
- package/dist/piggy/wait/index.d.ts.map +1 -0
- package/dist/piggy.d.ts.map +1 -1
- package/dist/piggy.js +901 -181
- package/dist/register/index.js +39 -86
- package/package.json +1 -1
- package/piggy/captcha/index.d.ts +35 -0
- package/piggy/captcha/index.ts +93 -0
- package/piggy/capture/index.ts +76 -0
- package/piggy/dialog/index.d.ts +29 -0
- package/piggy/dialog/index.ts +85 -0
- package/piggy/export/index.d.ts +117 -0
- package/piggy/export/index.ts +147 -0
- package/piggy/find/index.d.ts +79 -0
- package/piggy/find/index.ts +165 -0
- package/piggy/http/index.ts +65 -0
- package/piggy/human/index.ts +115 -53
- package/piggy/iframe/index.ts +79 -0
- package/piggy/interactions/index.ts +79 -0
- package/piggy/media/index.ts +46 -0
- package/piggy/navigation/index.ts +52 -0
- package/piggy/provide/index.ts +144 -0
- package/piggy/proxy/index.ts +154 -0
- package/piggy/register/index.ts +41 -59
- package/piggy/router/index.ts +69 -0
- package/piggy/session/index.ts +76 -0
- package/piggy/tabs/index.ts +22 -0
- package/piggy/wait/index.ts +90 -0
- package/piggy.ts +94 -39
- package/dist/piggy/open/index.d.ts +0 -4
- package/dist/piggy/open/index.d.ts.map +0 -1
- package/piggy/open/index.d.ts +0 -4
- package/piggy/open/index.d.ts.map +0 -1
- package/piggy/open/index.ts +0 -5
package/dist/piggy.js
CHANGED
|
@@ -7568,6 +7568,29 @@ class PiggyClient {
|
|
|
7568
7568
|
}
|
|
7569
7569
|
}
|
|
7570
7570
|
|
|
7571
|
+
// piggy/human/index.ts
|
|
7572
|
+
class HumanClient {
|
|
7573
|
+
client;
|
|
7574
|
+
constructor(client) {
|
|
7575
|
+
this.client = client;
|
|
7576
|
+
}
|
|
7577
|
+
set(opts, tabId = "default") {
|
|
7578
|
+
return this.client.send("human.set", { ...opts, tabId });
|
|
7579
|
+
}
|
|
7580
|
+
get(tabId = "default") {
|
|
7581
|
+
return this.client.send("human.get", { tabId });
|
|
7582
|
+
}
|
|
7583
|
+
type(opts, tabId = "default") {
|
|
7584
|
+
return this.client.send("human.type", { ...opts, tabId });
|
|
7585
|
+
}
|
|
7586
|
+
click(opts, tabId = "default") {
|
|
7587
|
+
return this.client.send("human.click", { ...opts, tabId });
|
|
7588
|
+
}
|
|
7589
|
+
}
|
|
7590
|
+
function createHumanAPI(client) {
|
|
7591
|
+
return new HumanClient(client);
|
|
7592
|
+
}
|
|
7593
|
+
|
|
7571
7594
|
// node_modules/memoirist/dist/index.mjs
|
|
7572
7595
|
var createNode = (part, inert) => {
|
|
7573
7596
|
const inertMap = inert?.length ? {} : null;
|
|
@@ -28297,61 +28320,6 @@ function stopServer() {
|
|
|
28297
28320
|
_app = null;
|
|
28298
28321
|
}
|
|
28299
28322
|
|
|
28300
|
-
// piggy/human/index.ts
|
|
28301
|
-
function randomDelay(min, max) {
|
|
28302
|
-
return new Promise((r) => setTimeout(r, Math.floor(Math.random() * (max - min + 1)) + min));
|
|
28303
|
-
}
|
|
28304
|
-
function humanTypeSequence(text) {
|
|
28305
|
-
const adjacent = {
|
|
28306
|
-
a: ["q", "w", "s", "z"],
|
|
28307
|
-
b: ["v", "g", "h", "n"],
|
|
28308
|
-
c: ["x", "d", "f", "v"],
|
|
28309
|
-
d: ["s", "e", "r", "f", "c", "x"],
|
|
28310
|
-
e: ["w", "r", "d", "s"],
|
|
28311
|
-
f: ["d", "r", "t", "g", "v", "c"],
|
|
28312
|
-
g: ["f", "t", "y", "h", "b", "v"],
|
|
28313
|
-
h: ["g", "y", "u", "j", "n", "b"],
|
|
28314
|
-
i: ["u", "o", "k", "j"],
|
|
28315
|
-
j: ["h", "u", "i", "k", "m", "n"],
|
|
28316
|
-
k: ["j", "i", "o", "l", "m"],
|
|
28317
|
-
l: ["k", "o", "p"],
|
|
28318
|
-
m: ["n", "j", "k"],
|
|
28319
|
-
n: ["b", "h", "j", "m"],
|
|
28320
|
-
o: ["i", "p", "l", "k"],
|
|
28321
|
-
p: ["o", "l"],
|
|
28322
|
-
q: ["w", "a"],
|
|
28323
|
-
r: ["e", "t", "f", "d"],
|
|
28324
|
-
s: ["a", "w", "e", "d", "x", "z"],
|
|
28325
|
-
t: ["r", "y", "g", "f"],
|
|
28326
|
-
u: ["y", "i", "h", "j"],
|
|
28327
|
-
v: ["c", "f", "g", "b"],
|
|
28328
|
-
w: ["q", "e", "a", "s"],
|
|
28329
|
-
x: ["z", "s", "d", "c"],
|
|
28330
|
-
y: ["t", "u", "g", "h"],
|
|
28331
|
-
z: ["a", "s", "x"]
|
|
28332
|
-
};
|
|
28333
|
-
const actions = [];
|
|
28334
|
-
const typoIndices = new Set;
|
|
28335
|
-
if (text.length > 4) {
|
|
28336
|
-
let tries = 0;
|
|
28337
|
-
while (typoIndices.size < 2 && tries < 20) {
|
|
28338
|
-
typoIndices.add(Math.floor(Math.random() * text.length));
|
|
28339
|
-
tries++;
|
|
28340
|
-
}
|
|
28341
|
-
}
|
|
28342
|
-
for (let i = 0;i < text.length; i++) {
|
|
28343
|
-
if (typoIndices.has(i)) {
|
|
28344
|
-
const ch = text[i].toLowerCase();
|
|
28345
|
-
const neighbors = adjacent[ch];
|
|
28346
|
-
const typo = neighbors ? neighbors[Math.floor(Math.random() * neighbors.length)] ?? ch : ch;
|
|
28347
|
-
actions.push(typo);
|
|
28348
|
-
actions.push("BACKSPACE");
|
|
28349
|
-
}
|
|
28350
|
-
actions.push(text[i]);
|
|
28351
|
-
}
|
|
28352
|
-
return actions;
|
|
28353
|
-
}
|
|
28354
|
-
|
|
28355
28323
|
// piggy/intercept/scripts.ts
|
|
28356
28324
|
function buildRespondScript(pattern, status2, contentType, body) {
|
|
28357
28325
|
const safePattern = pattern.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
@@ -28762,7 +28730,7 @@ function createSiteObject(name, registeredUrl, client, tabId, pool) {
|
|
|
28762
28730
|
},
|
|
28763
28731
|
click: (selector, opts) => withErrScreen(() => withTab((t2) => retry(name, async () => {
|
|
28764
28732
|
if (humanMode)
|
|
28765
|
-
await
|
|
28733
|
+
await new Promise((r) => setTimeout(r, 80 + Math.random() * 140));
|
|
28766
28734
|
await client.waitForSelector(selector, opts?.timeout ?? 15000, t2);
|
|
28767
28735
|
const ok = await client.click(selector, t2);
|
|
28768
28736
|
if (!ok)
|
|
@@ -28772,48 +28740,36 @@ function createSiteObject(name, registeredUrl, client, tabId, pool) {
|
|
|
28772
28740
|
}, opts?.retries ?? 2)), `click(${selector})`),
|
|
28773
28741
|
doubleClick: (selector) => withErrScreen(() => withTab(async (t2) => {
|
|
28774
28742
|
if (humanMode)
|
|
28775
|
-
await
|
|
28743
|
+
await new Promise((r) => setTimeout(r, 80 + Math.random() * 120));
|
|
28776
28744
|
return client.doubleClick(selector, t2);
|
|
28777
28745
|
}), `dblclick(${selector})`),
|
|
28778
28746
|
hover: (selector) => withErrScreen(() => withTab(async (t2) => {
|
|
28779
28747
|
if (humanMode)
|
|
28780
|
-
await
|
|
28748
|
+
await new Promise((r) => setTimeout(r, 50 + Math.random() * 100));
|
|
28781
28749
|
return client.hover(selector, t2);
|
|
28782
28750
|
}), `hover(${selector})`),
|
|
28783
28751
|
type: (selector, text, opts) => withErrScreen(() => withTab(async (t2) => {
|
|
28784
28752
|
await client.waitForSelector(selector, 30000, t2);
|
|
28785
|
-
if (humanMode
|
|
28786
|
-
const
|
|
28787
|
-
|
|
28788
|
-
|
|
28789
|
-
|
|
28790
|
-
|
|
28791
|
-
|
|
28792
|
-
|
|
28753
|
+
if (humanMode) {
|
|
28754
|
+
const human = new HumanClient(client);
|
|
28755
|
+
await human.type({
|
|
28756
|
+
selector,
|
|
28757
|
+
text,
|
|
28758
|
+
clear: opts?.clear ?? false,
|
|
28759
|
+
speed: opts?.speed
|
|
28760
|
+
}, t2);
|
|
28761
|
+
} else {
|
|
28762
|
+
if (opts?.clear) {
|
|
28793
28763
|
await client.evaluate(`
|
|
28794
|
-
|
|
28795
|
-
|
|
28796
|
-
|
|
28797
|
-
nativeSetter.call(el, '${current.replace(/'/g, "\\'")}');
|
|
28798
|
-
el.dispatchEvent(new Event('input', { bubbles: true }));
|
|
28799
|
-
el.dispatchEvent(new Event('change', { bubbles: true }));
|
|
28800
|
-
})()
|
|
28801
|
-
`, t2);
|
|
28802
|
-
const wpm = opts?.wpm ?? 120;
|
|
28803
|
-
const msPerChar = Math.round(60000 / (wpm * 5));
|
|
28804
|
-
await randomDelay(msPerChar * 0.5, msPerChar * 1.8);
|
|
28805
|
-
}
|
|
28806
|
-
} else if (opts?.delay) {
|
|
28807
|
-
for (const ch of text) {
|
|
28808
|
-
await client.type(selector, ch, t2);
|
|
28809
|
-
await new Promise((r) => setTimeout(r, opts.delay));
|
|
28764
|
+
const el = document.querySelector('${selector.replace(/'/g, "\\'")}');
|
|
28765
|
+
if (el) { el.value = ''; el.dispatchEvent(new Event('input', { bubbles: true })); }
|
|
28766
|
+
`, t2);
|
|
28810
28767
|
}
|
|
28811
|
-
} else {
|
|
28812
28768
|
await client.type(selector, text, t2);
|
|
28813
28769
|
}
|
|
28814
28770
|
await client.evaluate(`
|
|
28815
|
-
|
|
28816
|
-
|
|
28771
|
+
document.querySelector('${selector.replace(/'/g, "\\'")}')?.dispatchEvent(new Event('blur', { bubbles: true }));
|
|
28772
|
+
`, t2);
|
|
28817
28773
|
logger_default.success(`[${name}] typed into: ${selector}`);
|
|
28818
28774
|
return true;
|
|
28819
28775
|
}), `type(${selector})`),
|
|
@@ -28838,7 +28794,7 @@ function createSiteObject(name, registeredUrl, client, tabId, pool) {
|
|
|
28838
28794
|
const chunk = px / steps;
|
|
28839
28795
|
for (let i = 0;i < steps; i++) {
|
|
28840
28796
|
await client.scrollBy(chunk, t2);
|
|
28841
|
-
await
|
|
28797
|
+
await new Promise((r) => setTimeout(r, 30 + Math.random() * 50));
|
|
28842
28798
|
}
|
|
28843
28799
|
} else {
|
|
28844
28800
|
await client.scrollBy(px, t2);
|
|
@@ -29140,11 +29096,788 @@ class TabPool {
|
|
|
29140
29096
|
}
|
|
29141
29097
|
}
|
|
29142
29098
|
|
|
29099
|
+
// piggy/capture/index.ts
|
|
29100
|
+
class CaptureClient {
|
|
29101
|
+
client;
|
|
29102
|
+
constructor(client) {
|
|
29103
|
+
this.client = client;
|
|
29104
|
+
}
|
|
29105
|
+
start(tabId = "default") {
|
|
29106
|
+
return this.client.send("capture.start", { tabId });
|
|
29107
|
+
}
|
|
29108
|
+
stop(tabId = "default") {
|
|
29109
|
+
return this.client.send("capture.stop", { tabId });
|
|
29110
|
+
}
|
|
29111
|
+
requests(tabId = "default") {
|
|
29112
|
+
return this.client.send("capture.requests", { tabId });
|
|
29113
|
+
}
|
|
29114
|
+
ws(tabId = "default") {
|
|
29115
|
+
return this.client.send("capture.ws", { tabId });
|
|
29116
|
+
}
|
|
29117
|
+
cookies(tabId = "default") {
|
|
29118
|
+
return this.client.send("capture.cookies", { tabId });
|
|
29119
|
+
}
|
|
29120
|
+
storage(tabId = "default") {
|
|
29121
|
+
return this.client.send("capture.storage", { tabId });
|
|
29122
|
+
}
|
|
29123
|
+
clear(tabId = "default") {
|
|
29124
|
+
return this.client.send("capture.clear", { tabId });
|
|
29125
|
+
}
|
|
29126
|
+
}
|
|
29127
|
+
function createCaptureAPI(client) {
|
|
29128
|
+
return new CaptureClient(client);
|
|
29129
|
+
}
|
|
29130
|
+
|
|
29131
|
+
// piggy/captcha/index.ts
|
|
29132
|
+
class CaptchaClient {
|
|
29133
|
+
client;
|
|
29134
|
+
constructor(client) {
|
|
29135
|
+
this.client = client;
|
|
29136
|
+
}
|
|
29137
|
+
status(tabId = "default") {
|
|
29138
|
+
return this.client.send("captcha.status", { tabId });
|
|
29139
|
+
}
|
|
29140
|
+
resolve(tabId = "default") {
|
|
29141
|
+
return this.client.send("captcha.resolve", { tabId });
|
|
29142
|
+
}
|
|
29143
|
+
pause(tabId = "default") {
|
|
29144
|
+
return this.client.send("captcha.pause", { tabId });
|
|
29145
|
+
}
|
|
29146
|
+
check(tabId = "default") {
|
|
29147
|
+
return this.client.send("captcha.check", { tabId });
|
|
29148
|
+
}
|
|
29149
|
+
setAutoRetry(enabled) {
|
|
29150
|
+
return this.client.send("captcha.autoRetry", { enabled });
|
|
29151
|
+
}
|
|
29152
|
+
blockStatus(tabId = "default") {
|
|
29153
|
+
return this.client.send("block.status", { tabId });
|
|
29154
|
+
}
|
|
29155
|
+
blockRetry(tabId = "default") {
|
|
29156
|
+
return this.client.send("block.retry", { tabId });
|
|
29157
|
+
}
|
|
29158
|
+
onCaptcha(tabId, handler) {
|
|
29159
|
+
return this.client.onEvent("captcha", tabId, handler);
|
|
29160
|
+
}
|
|
29161
|
+
onCaptchaResolved(tabId, handler) {
|
|
29162
|
+
return this.client.onEvent("captcha:resolved", tabId, handler);
|
|
29163
|
+
}
|
|
29164
|
+
onBlocked(tabId, handler) {
|
|
29165
|
+
return this.client.onEvent("blocked", tabId, handler);
|
|
29166
|
+
}
|
|
29167
|
+
onBlockRetry(tabId, handler) {
|
|
29168
|
+
return this.client.onEvent("block:retry", tabId, handler);
|
|
29169
|
+
}
|
|
29170
|
+
waitForResolution(tabId = "default", timeoutMs = 300000) {
|
|
29171
|
+
return new Promise((resolve2, reject) => {
|
|
29172
|
+
const timer = setTimeout(() => {
|
|
29173
|
+
unsub();
|
|
29174
|
+
reject(new Error(`captcha.waitForResolution: timed out after ${timeoutMs}ms`));
|
|
29175
|
+
}, timeoutMs);
|
|
29176
|
+
const unsub = this.onCaptchaResolved(tabId, () => {
|
|
29177
|
+
clearTimeout(timer);
|
|
29178
|
+
unsub();
|
|
29179
|
+
resolve2();
|
|
29180
|
+
});
|
|
29181
|
+
logger_default.warn(`[captcha] waiting for manual resolution on tab ${tabId}…`);
|
|
29182
|
+
});
|
|
29183
|
+
}
|
|
29184
|
+
}
|
|
29185
|
+
function createCaptchaAPI(client) {
|
|
29186
|
+
return new CaptchaClient(client);
|
|
29187
|
+
}
|
|
29188
|
+
|
|
29189
|
+
// piggy/dialog/index.ts
|
|
29190
|
+
class DialogClient {
|
|
29191
|
+
client;
|
|
29192
|
+
constructor(client) {
|
|
29193
|
+
this.client = client;
|
|
29194
|
+
}
|
|
29195
|
+
accept(tabId = "default", text) {
|
|
29196
|
+
return this.client.send("dialog.accept", { tabId, ...text !== undefined ? { text } : {} });
|
|
29197
|
+
}
|
|
29198
|
+
dismiss(tabId = "default") {
|
|
29199
|
+
return this.client.send("dialog.dismiss", { tabId });
|
|
29200
|
+
}
|
|
29201
|
+
status(tabId = "default") {
|
|
29202
|
+
return this.client.send("dialog.status", { tabId });
|
|
29203
|
+
}
|
|
29204
|
+
setAutoAction(tabId = "default", action) {
|
|
29205
|
+
return this.client.send("dialog.onDialog", { tabId, action });
|
|
29206
|
+
}
|
|
29207
|
+
upload(selector, filePath, tabId = "default") {
|
|
29208
|
+
return this.client.send("upload", { selector, path: filePath, tabId });
|
|
29209
|
+
}
|
|
29210
|
+
onDialog(tabId, handler) {
|
|
29211
|
+
return this.client.onEvent("dialog", tabId, handler);
|
|
29212
|
+
}
|
|
29213
|
+
waitAndAccept(tabId = "default", text, timeoutMs = 30000) {
|
|
29214
|
+
return new Promise((resolve2, reject) => {
|
|
29215
|
+
const timer = setTimeout(() => {
|
|
29216
|
+
unsub();
|
|
29217
|
+
reject(new Error(`dialog.waitAndAccept: timed out after ${timeoutMs}ms`));
|
|
29218
|
+
}, timeoutMs);
|
|
29219
|
+
const unsub = this.onDialog(tabId, async (data) => {
|
|
29220
|
+
clearTimeout(timer);
|
|
29221
|
+
unsub();
|
|
29222
|
+
await this.accept(tabId, text);
|
|
29223
|
+
resolve2(data);
|
|
29224
|
+
});
|
|
29225
|
+
});
|
|
29226
|
+
}
|
|
29227
|
+
waitAndDismiss(tabId = "default", timeoutMs = 30000) {
|
|
29228
|
+
return new Promise((resolve2, reject) => {
|
|
29229
|
+
const timer = setTimeout(() => {
|
|
29230
|
+
unsub();
|
|
29231
|
+
reject(new Error(`dialog.waitAndDismiss: timed out after ${timeoutMs}ms`));
|
|
29232
|
+
}, timeoutMs);
|
|
29233
|
+
const unsub = this.onDialog(tabId, async (data) => {
|
|
29234
|
+
clearTimeout(timer);
|
|
29235
|
+
unsub();
|
|
29236
|
+
await this.dismiss(tabId);
|
|
29237
|
+
resolve2(data);
|
|
29238
|
+
});
|
|
29239
|
+
});
|
|
29240
|
+
}
|
|
29241
|
+
}
|
|
29242
|
+
function createDialogAPI(client) {
|
|
29243
|
+
return new DialogClient(client);
|
|
29244
|
+
}
|
|
29245
|
+
|
|
29246
|
+
// piggy/export/index.ts
|
|
29247
|
+
class ExportClient {
|
|
29248
|
+
client;
|
|
29249
|
+
constructor(client) {
|
|
29250
|
+
this.client = client;
|
|
29251
|
+
}
|
|
29252
|
+
searchCss(query, tabId = "default") {
|
|
29253
|
+
return this.client.send("search.css", { query, tabId });
|
|
29254
|
+
}
|
|
29255
|
+
searchId(query, tabId = "default") {
|
|
29256
|
+
return this.client.send("search.id", { query, tabId });
|
|
29257
|
+
}
|
|
29258
|
+
setCookie(opts, tabId = "default") {
|
|
29259
|
+
return this.client.send("cookie.set", { ...opts, tabId });
|
|
29260
|
+
}
|
|
29261
|
+
deleteCookie(opts, tabId = "default") {
|
|
29262
|
+
return this.client.send("cookie.delete", { ...opts, tabId });
|
|
29263
|
+
}
|
|
29264
|
+
sessionReload(tabId = "default") {
|
|
29265
|
+
return this.client.send("session.reload", { tabId });
|
|
29266
|
+
}
|
|
29267
|
+
cookiesPath() {
|
|
29268
|
+
return this.client.send("session.cookies.path", {});
|
|
29269
|
+
}
|
|
29270
|
+
profilePath() {
|
|
29271
|
+
return this.client.send("session.profile.path", {});
|
|
29272
|
+
}
|
|
29273
|
+
wsPath() {
|
|
29274
|
+
return this.client.send("session.ws.path", {});
|
|
29275
|
+
}
|
|
29276
|
+
pingsPath() {
|
|
29277
|
+
return this.client.send("session.pings.path", {});
|
|
29278
|
+
}
|
|
29279
|
+
sessionPaths() {
|
|
29280
|
+
return this.client.send("session.paths", {});
|
|
29281
|
+
}
|
|
29282
|
+
setWsSave(enabled) {
|
|
29283
|
+
return this.client.send("session.ws.save", { enabled });
|
|
29284
|
+
}
|
|
29285
|
+
setPingsSave(enabled) {
|
|
29286
|
+
return this.client.send("session.pings.save", { enabled });
|
|
29287
|
+
}
|
|
29288
|
+
addInterceptRule(rule, tabId = "default") {
|
|
29289
|
+
return this.client.send("intercept.rule.add", { ...rule, tabId });
|
|
29290
|
+
}
|
|
29291
|
+
clearInterceptRules(tabId = "default") {
|
|
29292
|
+
return this.client.send("intercept.rule.clear", { tabId });
|
|
29293
|
+
}
|
|
29294
|
+
async exportSession(tabId = "default") {
|
|
29295
|
+
const raw = await this.client.send("session.export", { tabId });
|
|
29296
|
+
return typeof raw === "string" ? JSON.parse(raw) : raw;
|
|
29297
|
+
}
|
|
29298
|
+
importSession(data, tabId = "default") {
|
|
29299
|
+
return this.client.send("session.import", {
|
|
29300
|
+
data: JSON.stringify(data),
|
|
29301
|
+
tabId
|
|
29302
|
+
});
|
|
29303
|
+
}
|
|
29304
|
+
exposeFunction(name, tabId = "default") {
|
|
29305
|
+
return this.client.send("expose.function", { name, tabId });
|
|
29306
|
+
}
|
|
29307
|
+
resolveExposed(callId, result, isError = false, tabId = "default") {
|
|
29308
|
+
return this.client.send("exposed.result", { callId, result, isError, tabId });
|
|
29309
|
+
}
|
|
29310
|
+
addInitScript(js, tabId = "default") {
|
|
29311
|
+
return this.client.send("addInitScript", { js, tabId });
|
|
29312
|
+
}
|
|
29313
|
+
onExposedFunctionCalled(tabId, handler) {
|
|
29314
|
+
return this.client.onEvent("exposed_call", tabId, handler);
|
|
29315
|
+
}
|
|
29316
|
+
}
|
|
29317
|
+
function createExportAPI(client) {
|
|
29318
|
+
return new ExportClient(client);
|
|
29319
|
+
}
|
|
29320
|
+
|
|
29321
|
+
// piggy/find/index.ts
|
|
29322
|
+
class FindClient {
|
|
29323
|
+
client;
|
|
29324
|
+
constructor(client) {
|
|
29325
|
+
this.client = client;
|
|
29326
|
+
}
|
|
29327
|
+
css(selector, tabId = "default") {
|
|
29328
|
+
return this.client.send("find.css", { selector, tabId });
|
|
29329
|
+
}
|
|
29330
|
+
all(selector, tabId = "default") {
|
|
29331
|
+
return this.client.send("find.all", { selector, tabId });
|
|
29332
|
+
}
|
|
29333
|
+
first(selector, tabId = "default") {
|
|
29334
|
+
return this.client.send("find.first", { selector, tabId });
|
|
29335
|
+
}
|
|
29336
|
+
byText(opts, tabId = "default") {
|
|
29337
|
+
return this.client.send("find.byText", { ...opts, tabId });
|
|
29338
|
+
}
|
|
29339
|
+
byAttr(opts, tabId = "default") {
|
|
29340
|
+
return this.client.send("find.byAttr", { ...opts, tabId });
|
|
29341
|
+
}
|
|
29342
|
+
byTag(tag, tabId = "default") {
|
|
29343
|
+
return this.client.send("find.byTag", { tag, tabId });
|
|
29344
|
+
}
|
|
29345
|
+
byPlaceholder(text, tabId = "default") {
|
|
29346
|
+
return this.client.send("find.byPlaceholder", { text, tabId });
|
|
29347
|
+
}
|
|
29348
|
+
byRole(opts, tabId = "default") {
|
|
29349
|
+
return this.client.send("find.byRole", { ...opts, tabId });
|
|
29350
|
+
}
|
|
29351
|
+
children(selector, tabId = "default") {
|
|
29352
|
+
return this.client.send("find.children", { selector, tabId });
|
|
29353
|
+
}
|
|
29354
|
+
filter(opts, tabId = "default") {
|
|
29355
|
+
return this.client.send("find.filter", { ...opts, tabId });
|
|
29356
|
+
}
|
|
29357
|
+
closest(opts, tabId = "default") {
|
|
29358
|
+
return this.client.send("find.closest", { ...opts, tabId });
|
|
29359
|
+
}
|
|
29360
|
+
parent(selector, tabId = "default") {
|
|
29361
|
+
return this.client.send("find.parent", { selector, tabId });
|
|
29362
|
+
}
|
|
29363
|
+
count(selector, tabId = "default") {
|
|
29364
|
+
return this.client.send("find.count", { selector, tabId });
|
|
29365
|
+
}
|
|
29366
|
+
exists(selector, tabId = "default") {
|
|
29367
|
+
return this.client.send("find.exists", { selector, tabId });
|
|
29368
|
+
}
|
|
29369
|
+
visible(selector, tabId = "default") {
|
|
29370
|
+
return this.client.send("find.visible", { selector, tabId });
|
|
29371
|
+
}
|
|
29372
|
+
enabled(selector, tabId = "default") {
|
|
29373
|
+
return this.client.send("find.enabled", { selector, tabId });
|
|
29374
|
+
}
|
|
29375
|
+
checked(selector, tabId = "default") {
|
|
29376
|
+
return this.client.send("find.checked", { selector, tabId });
|
|
29377
|
+
}
|
|
29378
|
+
}
|
|
29379
|
+
function createFindAPI(client) {
|
|
29380
|
+
return new FindClient(client);
|
|
29381
|
+
}
|
|
29382
|
+
|
|
29383
|
+
// piggy/iframe/index.ts
|
|
29384
|
+
class IframeClient {
|
|
29385
|
+
client;
|
|
29386
|
+
constructor(client) {
|
|
29387
|
+
this.client = client;
|
|
29388
|
+
}
|
|
29389
|
+
list(tabId = "default") {
|
|
29390
|
+
return this.client.send("iframe.list", { tabId });
|
|
29391
|
+
}
|
|
29392
|
+
evaluate(opts, tabId = "default") {
|
|
29393
|
+
return this.client.send("iframe.evaluate", { ...opts, tabId });
|
|
29394
|
+
}
|
|
29395
|
+
click(opts, tabId = "default") {
|
|
29396
|
+
return this.client.send("iframe.click", { ...opts, tabId });
|
|
29397
|
+
}
|
|
29398
|
+
type(opts, tabId = "default") {
|
|
29399
|
+
return this.client.send("iframe.type", { ...opts, tabId });
|
|
29400
|
+
}
|
|
29401
|
+
text(opts, tabId = "default") {
|
|
29402
|
+
return this.client.send("iframe.text", { ...opts, tabId });
|
|
29403
|
+
}
|
|
29404
|
+
html(opts, tabId = "default") {
|
|
29405
|
+
return this.client.send("iframe.html", { ...opts, tabId });
|
|
29406
|
+
}
|
|
29407
|
+
waitSel(opts, tabId = "default") {
|
|
29408
|
+
return this.client.send("iframe.waitSel", { ...opts, tabId });
|
|
29409
|
+
}
|
|
29410
|
+
}
|
|
29411
|
+
function createIframeAPI(client) {
|
|
29412
|
+
return new IframeClient(client);
|
|
29413
|
+
}
|
|
29414
|
+
|
|
29415
|
+
// piggy/interactions/index.ts
|
|
29416
|
+
class InteractionsClient {
|
|
29417
|
+
client;
|
|
29418
|
+
constructor(client) {
|
|
29419
|
+
this.client = client;
|
|
29420
|
+
}
|
|
29421
|
+
click(selector, tabId = "default") {
|
|
29422
|
+
return this.client.send("click", { selector, tabId });
|
|
29423
|
+
}
|
|
29424
|
+
dblclick(selector, tabId = "default") {
|
|
29425
|
+
return this.client.send("dblclick", { selector, tabId });
|
|
29426
|
+
}
|
|
29427
|
+
hover(selector, tabId = "default") {
|
|
29428
|
+
return this.client.send("hover", { selector, tabId });
|
|
29429
|
+
}
|
|
29430
|
+
type(selector, text, tabId = "default") {
|
|
29431
|
+
return this.client.send("type", { selector, text, tabId });
|
|
29432
|
+
}
|
|
29433
|
+
typeClear(selector, text, tabId = "default") {
|
|
29434
|
+
return this.client.send("type", { selector, text, clear: true, tabId });
|
|
29435
|
+
}
|
|
29436
|
+
select(selector, value, tabId = "default") {
|
|
29437
|
+
return this.client.send("select", { selector, value, tabId });
|
|
29438
|
+
}
|
|
29439
|
+
scrollTo(selector, tabId = "default") {
|
|
29440
|
+
return this.client.send("scroll.to", { selector, tabId });
|
|
29441
|
+
}
|
|
29442
|
+
scrollBy(px, tabId = "default") {
|
|
29443
|
+
return this.client.send("scroll.by", { px, tabId });
|
|
29444
|
+
}
|
|
29445
|
+
keyPress(key, tabId = "default") {
|
|
29446
|
+
return this.client.send("keyboard.press", { key, tabId });
|
|
29447
|
+
}
|
|
29448
|
+
keyCombo(combo, tabId = "default") {
|
|
29449
|
+
return this.client.send("keyboard.combo", { combo, tabId });
|
|
29450
|
+
}
|
|
29451
|
+
mouseMove(x, y, tabId = "default") {
|
|
29452
|
+
return this.client.send("mouse.move", { x, y, tabId });
|
|
29453
|
+
}
|
|
29454
|
+
mouseDrag(from, to, tabId = "default") {
|
|
29455
|
+
return this.client.send("mouse.drag", { from, to, tabId });
|
|
29456
|
+
}
|
|
29457
|
+
evaluate(js, tabId = "default") {
|
|
29458
|
+
return this.client.send("evaluate", { js, tabId });
|
|
29459
|
+
}
|
|
29460
|
+
}
|
|
29461
|
+
function createInteractionsAPI(client) {
|
|
29462
|
+
return new InteractionsClient(client);
|
|
29463
|
+
}
|
|
29464
|
+
|
|
29465
|
+
// piggy/media/index.ts
|
|
29466
|
+
import { writeFileSync as writeFileSync3, mkdirSync as mkdirSync3 } from "fs";
|
|
29467
|
+
import { dirname as dirname3 } from "path";
|
|
29468
|
+
|
|
29469
|
+
class MediaClient {
|
|
29470
|
+
client;
|
|
29471
|
+
constructor(client) {
|
|
29472
|
+
this.client = client;
|
|
29473
|
+
}
|
|
29474
|
+
async screenshot(filePath, tabId = "default") {
|
|
29475
|
+
const b64 = await this.client.send("screenshot", { tabId });
|
|
29476
|
+
if (filePath) {
|
|
29477
|
+
mkdirSync3(dirname3(filePath), { recursive: true });
|
|
29478
|
+
writeFileSync3(filePath, Buffer.from(b64, "base64"));
|
|
29479
|
+
return filePath;
|
|
29480
|
+
}
|
|
29481
|
+
return b64;
|
|
29482
|
+
}
|
|
29483
|
+
async pdf(filePath, tabId = "default") {
|
|
29484
|
+
const b64 = await this.client.send("pdf", { tabId });
|
|
29485
|
+
if (filePath) {
|
|
29486
|
+
mkdirSync3(dirname3(filePath), { recursive: true });
|
|
29487
|
+
writeFileSync3(filePath, Buffer.from(b64, "base64"));
|
|
29488
|
+
return filePath;
|
|
29489
|
+
}
|
|
29490
|
+
return b64;
|
|
29491
|
+
}
|
|
29492
|
+
blockImages(tabId = "default") {
|
|
29493
|
+
return this.client.send("intercept.block.images", { tabId });
|
|
29494
|
+
}
|
|
29495
|
+
unblockImages(tabId = "default") {
|
|
29496
|
+
return this.client.send("intercept.unblock.images", { tabId });
|
|
29497
|
+
}
|
|
29498
|
+
}
|
|
29499
|
+
function createMediaAPI(client) {
|
|
29500
|
+
return new MediaClient(client);
|
|
29501
|
+
}
|
|
29502
|
+
|
|
29503
|
+
// piggy/navigation/index.ts
|
|
29504
|
+
class NavigationClient {
|
|
29505
|
+
client;
|
|
29506
|
+
constructor(client) {
|
|
29507
|
+
this.client = client;
|
|
29508
|
+
}
|
|
29509
|
+
navigate(url2, tabId = "default") {
|
|
29510
|
+
return this.client.send("navigate", { url: url2, tabId });
|
|
29511
|
+
}
|
|
29512
|
+
reload(tabId = "default") {
|
|
29513
|
+
return this.client.send("reload", { tabId });
|
|
29514
|
+
}
|
|
29515
|
+
goBack(tabId = "default") {
|
|
29516
|
+
return this.client.send("go.back", { tabId });
|
|
29517
|
+
}
|
|
29518
|
+
goForward(tabId = "default") {
|
|
29519
|
+
return this.client.send("go.forward", { tabId });
|
|
29520
|
+
}
|
|
29521
|
+
url(tabId = "default") {
|
|
29522
|
+
return this.client.send("page.url", { tabId });
|
|
29523
|
+
}
|
|
29524
|
+
title(tabId = "default") {
|
|
29525
|
+
return this.client.send("page.title", { tabId });
|
|
29526
|
+
}
|
|
29527
|
+
content(tabId = "default") {
|
|
29528
|
+
return this.client.send("page.content", { tabId });
|
|
29529
|
+
}
|
|
29530
|
+
waitForNavigation(tabId = "default") {
|
|
29531
|
+
return this.client.send("wait.navigation", { tabId });
|
|
29532
|
+
}
|
|
29533
|
+
waitForSelector(selector, timeout = 1e4, tabId = "default") {
|
|
29534
|
+
return this.client.send("wait.selector", { selector, timeout, tabId });
|
|
29535
|
+
}
|
|
29536
|
+
}
|
|
29537
|
+
function createNavigationAPI(client) {
|
|
29538
|
+
return new NavigationClient(client);
|
|
29539
|
+
}
|
|
29540
|
+
|
|
29541
|
+
// piggy/provide/index.ts
|
|
29542
|
+
class ProvideClient {
|
|
29543
|
+
client;
|
|
29544
|
+
constructor(client) {
|
|
29545
|
+
this.client = client;
|
|
29546
|
+
}
|
|
29547
|
+
text(selector, tabId = "default") {
|
|
29548
|
+
return this.client.send("provide.text", { selector, tabId });
|
|
29549
|
+
}
|
|
29550
|
+
textAll(selector, tabId = "default") {
|
|
29551
|
+
return this.client.send("provide.textAll", { selector, tabId });
|
|
29552
|
+
}
|
|
29553
|
+
attr(selector, attr, tabId = "default") {
|
|
29554
|
+
return this.client.send("provide.attr", { selector, attr, tabId });
|
|
29555
|
+
}
|
|
29556
|
+
attrAll(selector, attr, tabId = "default") {
|
|
29557
|
+
return this.client.send("provide.attrAll", { selector, attr, tabId });
|
|
29558
|
+
}
|
|
29559
|
+
html(selector, tabId = "default") {
|
|
29560
|
+
return this.client.send("provide.html", { selector, tabId });
|
|
29561
|
+
}
|
|
29562
|
+
table(selector, tabId = "default") {
|
|
29563
|
+
return this.client.send("provide.table", { selector, tabId });
|
|
29564
|
+
}
|
|
29565
|
+
list(selector, itemSel, tabId = "default") {
|
|
29566
|
+
return this.client.send("provide.list", { selector, itemSel, tabId });
|
|
29567
|
+
}
|
|
29568
|
+
links(selector, tabId = "default") {
|
|
29569
|
+
return this.client.send("provide.links", { selector, tabId });
|
|
29570
|
+
}
|
|
29571
|
+
images(selector, tabId = "default") {
|
|
29572
|
+
return this.client.send("provide.images", { selector, tabId });
|
|
29573
|
+
}
|
|
29574
|
+
form(selector, tabId = "default") {
|
|
29575
|
+
return this.client.send("provide.form", { selector, tabId });
|
|
29576
|
+
}
|
|
29577
|
+
page(tabId = "default") {
|
|
29578
|
+
return this.client.send("provide.page", { tabId });
|
|
29579
|
+
}
|
|
29580
|
+
div(selector, tabId = "default") {
|
|
29581
|
+
return this.client.send("provide.div", { selector, tabId });
|
|
29582
|
+
}
|
|
29583
|
+
meta(tabId = "default") {
|
|
29584
|
+
return this.client.send("provide.meta", { tabId });
|
|
29585
|
+
}
|
|
29586
|
+
select(selector, tabId = "default") {
|
|
29587
|
+
return this.client.send("provide.select", { selector, tabId });
|
|
29588
|
+
}
|
|
29589
|
+
json(selector, tabId = "default") {
|
|
29590
|
+
return this.client.send("provide.json", { selector, tabId });
|
|
29591
|
+
}
|
|
29592
|
+
}
|
|
29593
|
+
function createProvideAPI(client) {
|
|
29594
|
+
return new ProvideClient(client);
|
|
29595
|
+
}
|
|
29596
|
+
|
|
29597
|
+
// piggy/proxy/index.ts
|
|
29598
|
+
class ProxyClient {
|
|
29599
|
+
client;
|
|
29600
|
+
constructor(client) {
|
|
29601
|
+
this.client = client;
|
|
29602
|
+
}
|
|
29603
|
+
load(path) {
|
|
29604
|
+
return this.client.send("proxy.load", { path });
|
|
29605
|
+
}
|
|
29606
|
+
fetch(url2) {
|
|
29607
|
+
return this.client.send("proxy.fetch", { url: url2 });
|
|
29608
|
+
}
|
|
29609
|
+
ovpn(path) {
|
|
29610
|
+
return this.client.send("proxy.ovpn", { path });
|
|
29611
|
+
}
|
|
29612
|
+
set(opts) {
|
|
29613
|
+
return this.client.send("proxy.set", opts);
|
|
29614
|
+
}
|
|
29615
|
+
test() {
|
|
29616
|
+
return this.client.send("proxy.test", {});
|
|
29617
|
+
}
|
|
29618
|
+
testStop() {
|
|
29619
|
+
return this.client.send("proxy.test.stop", {});
|
|
29620
|
+
}
|
|
29621
|
+
next() {
|
|
29622
|
+
return this.client.send("proxy.next", {});
|
|
29623
|
+
}
|
|
29624
|
+
rotate() {
|
|
29625
|
+
return this.client.send("proxy.rotate", {});
|
|
29626
|
+
}
|
|
29627
|
+
disable() {
|
|
29628
|
+
return this.client.send("proxy.disable", {});
|
|
29629
|
+
}
|
|
29630
|
+
enable() {
|
|
29631
|
+
return this.client.send("proxy.enable", {});
|
|
29632
|
+
}
|
|
29633
|
+
current() {
|
|
29634
|
+
return this.client.send("proxy.current", {});
|
|
29635
|
+
}
|
|
29636
|
+
stats() {
|
|
29637
|
+
return this.client.send("proxy.stats", {});
|
|
29638
|
+
}
|
|
29639
|
+
list(limit) {
|
|
29640
|
+
return this.client.send("proxy.list", { limit });
|
|
29641
|
+
}
|
|
29642
|
+
rotation(mode, interval) {
|
|
29643
|
+
return this.client.send("proxy.rotation", { mode, interval });
|
|
29644
|
+
}
|
|
29645
|
+
config(opts) {
|
|
29646
|
+
return this.client.send("proxy.config", opts);
|
|
29647
|
+
}
|
|
29648
|
+
save(path, filter) {
|
|
29649
|
+
return this.client.send("proxy.save", { path, filter });
|
|
29650
|
+
}
|
|
29651
|
+
}
|
|
29652
|
+
function createProxyAPI(client) {
|
|
29653
|
+
return new ProxyClient(client);
|
|
29654
|
+
}
|
|
29655
|
+
|
|
29656
|
+
// piggy/session/index.ts
|
|
29657
|
+
class SessionClient {
|
|
29658
|
+
client;
|
|
29659
|
+
constructor(client) {
|
|
29660
|
+
this.client = client;
|
|
29661
|
+
}
|
|
29662
|
+
reload(tabId = "default") {
|
|
29663
|
+
return this.client.send("session.reload", { tabId });
|
|
29664
|
+
}
|
|
29665
|
+
paths() {
|
|
29666
|
+
return this.client.send("session.paths", {});
|
|
29667
|
+
}
|
|
29668
|
+
cookiesPath() {
|
|
29669
|
+
return this.client.send("session.cookies.path", {});
|
|
29670
|
+
}
|
|
29671
|
+
profilePath() {
|
|
29672
|
+
return this.client.send("session.profile.path", {});
|
|
29673
|
+
}
|
|
29674
|
+
wsPath() {
|
|
29675
|
+
return this.client.send("session.ws.path", {});
|
|
29676
|
+
}
|
|
29677
|
+
pingsPath() {
|
|
29678
|
+
return this.client.send("session.pings.path", {});
|
|
29679
|
+
}
|
|
29680
|
+
setWsSave(enabled) {
|
|
29681
|
+
return this.client.send("session.ws.save", { enabled });
|
|
29682
|
+
}
|
|
29683
|
+
setPingsSave(enabled) {
|
|
29684
|
+
return this.client.send("session.pings.save", { enabled });
|
|
29685
|
+
}
|
|
29686
|
+
async export(tabId = "default") {
|
|
29687
|
+
const raw = await this.client.send("session.export", { tabId });
|
|
29688
|
+
return typeof raw === "string" ? JSON.parse(raw) : raw;
|
|
29689
|
+
}
|
|
29690
|
+
import(data, tabId = "default") {
|
|
29691
|
+
return this.client.send("session.import", {
|
|
29692
|
+
data: JSON.stringify(data),
|
|
29693
|
+
tabId
|
|
29694
|
+
});
|
|
29695
|
+
}
|
|
29696
|
+
setCookie(opts, tabId = "default") {
|
|
29697
|
+
return this.client.send("cookie.set", { ...opts, tabId });
|
|
29698
|
+
}
|
|
29699
|
+
deleteCookie(opts, tabId = "default") {
|
|
29700
|
+
return this.client.send("cookie.delete", { ...opts, tabId });
|
|
29701
|
+
}
|
|
29702
|
+
}
|
|
29703
|
+
function createSessionAPI(client) {
|
|
29704
|
+
return new SessionClient(client);
|
|
29705
|
+
}
|
|
29706
|
+
|
|
29707
|
+
// piggy/tabs/index.ts
|
|
29708
|
+
class TabsClient {
|
|
29709
|
+
client;
|
|
29710
|
+
constructor(client) {
|
|
29711
|
+
this.client = client;
|
|
29712
|
+
}
|
|
29713
|
+
new() {
|
|
29714
|
+
return this.client.send("tab.new", {});
|
|
29715
|
+
}
|
|
29716
|
+
close(tabId) {
|
|
29717
|
+
return this.client.send("tab.close", { tabId });
|
|
29718
|
+
}
|
|
29719
|
+
list() {
|
|
29720
|
+
return this.client.send("tab.list", {});
|
|
29721
|
+
}
|
|
29722
|
+
}
|
|
29723
|
+
function createTabsAPI(client) {
|
|
29724
|
+
return new TabsClient(client);
|
|
29725
|
+
}
|
|
29726
|
+
|
|
29727
|
+
// piggy/wait/index.ts
|
|
29728
|
+
class WaitClient {
|
|
29729
|
+
client;
|
|
29730
|
+
constructor(client) {
|
|
29731
|
+
this.client = client;
|
|
29732
|
+
}
|
|
29733
|
+
function(js, timeout = 1e4, tabId = "default") {
|
|
29734
|
+
return this.client.send("wait.function", { js, timeout, tabId });
|
|
29735
|
+
}
|
|
29736
|
+
selector(selector, state = "attached", timeout = 1e4, tabId = "default") {
|
|
29737
|
+
return this.client.send("wait.selector", { selector, state, timeout, tabId });
|
|
29738
|
+
}
|
|
29739
|
+
}
|
|
29740
|
+
|
|
29741
|
+
class EvaluateClient {
|
|
29742
|
+
client;
|
|
29743
|
+
constructor(client) {
|
|
29744
|
+
this.client = client;
|
|
29745
|
+
}
|
|
29746
|
+
run(js, timeout, tabId = "default") {
|
|
29747
|
+
return this.client.send("evaluate", {
|
|
29748
|
+
js,
|
|
29749
|
+
tabId,
|
|
29750
|
+
...timeout !== undefined ? { timeout } : {}
|
|
29751
|
+
});
|
|
29752
|
+
}
|
|
29753
|
+
}
|
|
29754
|
+
|
|
29755
|
+
class FetchClient {
|
|
29756
|
+
client;
|
|
29757
|
+
constructor(client) {
|
|
29758
|
+
this.client = client;
|
|
29759
|
+
}
|
|
29760
|
+
text(selector, tabId = "default") {
|
|
29761
|
+
return this.client.send("fetch.text", { query: selector, tabId });
|
|
29762
|
+
}
|
|
29763
|
+
textAll(selector, tabId = "default") {
|
|
29764
|
+
return this.client.send("fetch.textAll", { selector, tabId });
|
|
29765
|
+
}
|
|
29766
|
+
attr(selector, attr, tabId = "default") {
|
|
29767
|
+
return this.client.send("fetch.attr", { selector, attr, tabId });
|
|
29768
|
+
}
|
|
29769
|
+
attrAll(selector, attr, tabId = "default") {
|
|
29770
|
+
return this.client.send("fetch.attrAll", { selector, attr, tabId });
|
|
29771
|
+
}
|
|
29772
|
+
links(selector, tabId = "default") {
|
|
29773
|
+
return this.client.send("fetch.links", { query: selector, tabId });
|
|
29774
|
+
}
|
|
29775
|
+
linksAll(tabId = "default") {
|
|
29776
|
+
return this.client.send("fetch.links.all", { tabId });
|
|
29777
|
+
}
|
|
29778
|
+
images(selector, tabId = "default") {
|
|
29779
|
+
return this.client.send("fetch.image", { query: selector, tabId });
|
|
29780
|
+
}
|
|
29781
|
+
}
|
|
29782
|
+
function createWaitAPI(client) {
|
|
29783
|
+
return new WaitClient(client);
|
|
29784
|
+
}
|
|
29785
|
+
function createEvaluateAPI(client) {
|
|
29786
|
+
return new EvaluateClient(client);
|
|
29787
|
+
}
|
|
29788
|
+
function createFetchAPI(client) {
|
|
29789
|
+
return new FetchClient(client);
|
|
29790
|
+
}
|
|
29791
|
+
|
|
29792
|
+
// piggy/router/index.ts
|
|
29793
|
+
function createRouter(client) {
|
|
29794
|
+
return {
|
|
29795
|
+
client,
|
|
29796
|
+
tabs: createTabsAPI(client),
|
|
29797
|
+
navigation: createNavigationAPI(client),
|
|
29798
|
+
interactions: createInteractionsAPI(client),
|
|
29799
|
+
media: createMediaAPI(client),
|
|
29800
|
+
capture: createCaptureAPI(client),
|
|
29801
|
+
find: createFindAPI(client),
|
|
29802
|
+
provide: createProvideAPI(client),
|
|
29803
|
+
wait: createWaitAPI(client),
|
|
29804
|
+
evaluate: createEvaluateAPI(client),
|
|
29805
|
+
fetch: createFetchAPI(client),
|
|
29806
|
+
proxy: createProxyAPI(client),
|
|
29807
|
+
captcha: createCaptchaAPI(client),
|
|
29808
|
+
dialog: createDialogAPI(client),
|
|
29809
|
+
human: createHumanAPI(client),
|
|
29810
|
+
iframe: createIframeAPI(client),
|
|
29811
|
+
session: createSessionAPI(client),
|
|
29812
|
+
export: createExportAPI(client)
|
|
29813
|
+
};
|
|
29814
|
+
}
|
|
29815
|
+
|
|
29816
|
+
// piggy/http/index.ts
|
|
29817
|
+
class PiggyHttpClient {
|
|
29818
|
+
baseUrl;
|
|
29819
|
+
key;
|
|
29820
|
+
constructor(opts) {
|
|
29821
|
+
const host = opts.host ?? "localhost";
|
|
29822
|
+
const port = opts.port ?? 2005;
|
|
29823
|
+
this.baseUrl = `http://${host}:${port}`;
|
|
29824
|
+
this.key = opts.key;
|
|
29825
|
+
}
|
|
29826
|
+
async ping() {
|
|
29827
|
+
try {
|
|
29828
|
+
const res = await fetch(this.baseUrl, {
|
|
29829
|
+
method: "POST",
|
|
29830
|
+
headers: {
|
|
29831
|
+
"Content-Type": "application/json",
|
|
29832
|
+
"X-Piggy-Key": this.key
|
|
29833
|
+
},
|
|
29834
|
+
body: "hello"
|
|
29835
|
+
});
|
|
29836
|
+
const text = await res.text();
|
|
29837
|
+
return text.includes("active");
|
|
29838
|
+
} catch {
|
|
29839
|
+
return false;
|
|
29840
|
+
}
|
|
29841
|
+
}
|
|
29842
|
+
async send(cmd, payload = {}) {
|
|
29843
|
+
const res = await fetch(this.baseUrl, {
|
|
29844
|
+
method: "POST",
|
|
29845
|
+
headers: {
|
|
29846
|
+
"Content-Type": "application/json",
|
|
29847
|
+
"X-Piggy-Key": this.key
|
|
29848
|
+
},
|
|
29849
|
+
body: JSON.stringify({ id: String(Date.now()), cmd, payload })
|
|
29850
|
+
});
|
|
29851
|
+
if (res.status === 401)
|
|
29852
|
+
throw new Error("Unauthorized — invalid X-Piggy-Key");
|
|
29853
|
+
if (res.status === 400)
|
|
29854
|
+
throw new Error("Bad request — invalid JSON");
|
|
29855
|
+
if (!res.ok)
|
|
29856
|
+
throw new Error(`HTTP ${res.status}`);
|
|
29857
|
+
const data = await res.json();
|
|
29858
|
+
if (!data.ok)
|
|
29859
|
+
throw new Error(String(data.data) ?? "command failed");
|
|
29860
|
+
return data.data;
|
|
29861
|
+
}
|
|
29862
|
+
}
|
|
29863
|
+
function createHttpClient(opts) {
|
|
29864
|
+
return new PiggyHttpClient(opts);
|
|
29865
|
+
}
|
|
29866
|
+
|
|
29143
29867
|
// piggy.ts
|
|
29144
29868
|
var _client = null;
|
|
29869
|
+
var _router = null;
|
|
29145
29870
|
var _tabMode = "tab";
|
|
29146
29871
|
var _extraProcs = [];
|
|
29147
|
-
var _sites =
|
|
29872
|
+
var _sites = {};
|
|
29873
|
+
function guardClient() {
|
|
29874
|
+
if (!_client)
|
|
29875
|
+
throw new Error("No client. Call piggy.launch() or piggy.connect() first.");
|
|
29876
|
+
return _client;
|
|
29877
|
+
}
|
|
29878
|
+
function buildAPIs(client) {
|
|
29879
|
+
_router = createRouter(client);
|
|
29880
|
+
}
|
|
29148
29881
|
var piggy = {
|
|
29149
29882
|
launch: async (opts) => {
|
|
29150
29883
|
_tabMode = opts?.mode ?? "tab";
|
|
@@ -29154,6 +29887,7 @@ var piggy = {
|
|
|
29154
29887
|
_client = new PiggyClient;
|
|
29155
29888
|
await _client.connect();
|
|
29156
29889
|
setClient(_client);
|
|
29890
|
+
buildAPIs(_client);
|
|
29157
29891
|
logger_default.info(`[piggy] launched — tab mode: "${_tabMode}", binary: "${binaryMode}"`);
|
|
29158
29892
|
return piggy;
|
|
29159
29893
|
},
|
|
@@ -29162,27 +29896,28 @@ var piggy = {
|
|
|
29162
29896
|
_client = new PiggyClient({ host: opts.host, key: opts.key });
|
|
29163
29897
|
await _client.connect();
|
|
29164
29898
|
setClient(_client);
|
|
29899
|
+
buildAPIs(_client);
|
|
29165
29900
|
logger_default.info(`[piggy] connected (HTTP) → ${opts.host}`);
|
|
29166
29901
|
return piggy;
|
|
29167
29902
|
},
|
|
29903
|
+
http: (opts) => createHttpClient(opts),
|
|
29168
29904
|
register: async (name, url2, opts) => {
|
|
29169
29905
|
if (!url2?.trim())
|
|
29170
29906
|
throw new Error(`No URL for site "${name}"`);
|
|
29171
29907
|
const binaryMode = opts?.binary ?? "headless";
|
|
29172
29908
|
const poolSize = opts?.pool ?? 0;
|
|
29173
29909
|
if (_tabMode === "tab") {
|
|
29174
|
-
|
|
29175
|
-
throw new Error("No client. Call piggy.launch() or piggy.connect() first.");
|
|
29910
|
+
const client = guardClient();
|
|
29176
29911
|
if (poolSize > 1) {
|
|
29177
|
-
const pool = new TabPool(
|
|
29912
|
+
const pool = new TabPool(client, poolSize, url2, name);
|
|
29178
29913
|
await pool.init();
|
|
29179
|
-
const siteObj = createSiteObject(name, url2,
|
|
29914
|
+
const siteObj = createSiteObject(name, url2, client, "default", pool);
|
|
29180
29915
|
_sites[name] = siteObj;
|
|
29181
29916
|
piggy[name] = siteObj;
|
|
29182
29917
|
logger_default.success(`[${name}] registered with pool of ${poolSize} tabs`);
|
|
29183
29918
|
} else {
|
|
29184
|
-
const tabId = await
|
|
29185
|
-
const siteObj = createSiteObject(name, url2,
|
|
29919
|
+
const tabId = await client.newTab();
|
|
29920
|
+
const siteObj = createSiteObject(name, url2, client, tabId);
|
|
29186
29921
|
_sites[name] = siteObj;
|
|
29187
29922
|
piggy[name] = siteObj;
|
|
29188
29923
|
logger_default.success(`[${name}] registered as tab ${tabId}`);
|
|
@@ -29201,6 +29936,76 @@ var piggy = {
|
|
|
29201
29936
|
}
|
|
29202
29937
|
return piggy;
|
|
29203
29938
|
},
|
|
29939
|
+
get tabs() {
|
|
29940
|
+
return _router?.tabs ?? createTabsAPI(guardClient());
|
|
29941
|
+
},
|
|
29942
|
+
get navigation() {
|
|
29943
|
+
return _router?.navigation ?? createNavigationAPI(guardClient());
|
|
29944
|
+
},
|
|
29945
|
+
get interactions() {
|
|
29946
|
+
return _router?.interactions ?? createInteractionsAPI(guardClient());
|
|
29947
|
+
},
|
|
29948
|
+
get media() {
|
|
29949
|
+
return _router?.media ?? createMediaAPI(guardClient());
|
|
29950
|
+
},
|
|
29951
|
+
get capture() {
|
|
29952
|
+
return _router?.capture ?? createCaptureAPI(guardClient());
|
|
29953
|
+
},
|
|
29954
|
+
get find() {
|
|
29955
|
+
return _router?.find ?? createFindAPI(guardClient());
|
|
29956
|
+
},
|
|
29957
|
+
get provide() {
|
|
29958
|
+
return _router?.provide ?? createProvideAPI(guardClient());
|
|
29959
|
+
},
|
|
29960
|
+
get wait() {
|
|
29961
|
+
return _router?.wait ?? createWaitAPI(guardClient());
|
|
29962
|
+
},
|
|
29963
|
+
get evaluate() {
|
|
29964
|
+
return _router?.evaluate ?? createEvaluateAPI(guardClient());
|
|
29965
|
+
},
|
|
29966
|
+
get fetch() {
|
|
29967
|
+
return _router?.fetch ?? createFetchAPI(guardClient());
|
|
29968
|
+
},
|
|
29969
|
+
get captcha() {
|
|
29970
|
+
return _router?.captcha ?? createCaptchaAPI(guardClient());
|
|
29971
|
+
},
|
|
29972
|
+
get dialog() {
|
|
29973
|
+
return _router?.dialog ?? createDialogAPI(guardClient());
|
|
29974
|
+
},
|
|
29975
|
+
get human() {
|
|
29976
|
+
return _router?.human ?? createHumanAPI(guardClient());
|
|
29977
|
+
},
|
|
29978
|
+
get iframe() {
|
|
29979
|
+
return _router?.iframe ?? createIframeAPI(guardClient());
|
|
29980
|
+
},
|
|
29981
|
+
get session() {
|
|
29982
|
+
return _router?.session ?? createSessionAPI(guardClient());
|
|
29983
|
+
},
|
|
29984
|
+
get export() {
|
|
29985
|
+
return _router?.export ?? createExportAPI(guardClient());
|
|
29986
|
+
},
|
|
29987
|
+
get proxy() {
|
|
29988
|
+
const api = _router?.proxy ?? createProxyAPI(guardClient());
|
|
29989
|
+
return {
|
|
29990
|
+
load: (path) => api.load(path),
|
|
29991
|
+
fetch: (url2) => api.fetch(url2),
|
|
29992
|
+
ovpn: (path) => api.ovpn(path),
|
|
29993
|
+
set: (opts) => api.set(opts),
|
|
29994
|
+
test: () => api.test(),
|
|
29995
|
+
testStop: () => api.testStop(),
|
|
29996
|
+
next: () => api.next(),
|
|
29997
|
+
rotate: () => api.rotate(),
|
|
29998
|
+
disable: () => api.disable(),
|
|
29999
|
+
enable: () => api.enable(),
|
|
30000
|
+
current: () => api.current(),
|
|
30001
|
+
stats: () => api.stats(),
|
|
30002
|
+
list: (limit) => api.list(limit),
|
|
30003
|
+
rotation: (mode, interval) => api.rotation(mode, interval),
|
|
30004
|
+
config: (opts) => api.config(opts),
|
|
30005
|
+
save: (path, filter) => api.save(path, filter),
|
|
30006
|
+
on: (event, handler) => guardClient().onProxyEvent(event, handler)
|
|
30007
|
+
};
|
|
30008
|
+
},
|
|
29204
30009
|
actHuman: (enable) => {
|
|
29205
30010
|
setHumanMode(enable);
|
|
29206
30011
|
logger_default.info(`[piggy] actHuman: ${enable}`);
|
|
@@ -29211,101 +30016,15 @@ var piggy = {
|
|
|
29211
30016
|
return piggy;
|
|
29212
30017
|
},
|
|
29213
30018
|
expose: async (name, handler, tabId = "default") => {
|
|
29214
|
-
|
|
29215
|
-
throw new Error("No client. Call piggy.launch() or piggy.connect() first.");
|
|
29216
|
-
await _client.exposeFunction(name, handler, tabId);
|
|
30019
|
+
await guardClient().exposeFunction(name, handler, tabId);
|
|
29217
30020
|
logger_default.success(`[piggy] exposed global function: ${name}`);
|
|
29218
30021
|
return piggy;
|
|
29219
30022
|
},
|
|
29220
30023
|
unexpose: async (name, tabId = "default") => {
|
|
29221
|
-
|
|
29222
|
-
throw new Error("No client. Call piggy.launch() or piggy.connect() first.");
|
|
29223
|
-
await _client.unexposeFunction(name, tabId);
|
|
30024
|
+
await guardClient().unexposeFunction(name, tabId);
|
|
29224
30025
|
logger_default.info(`[piggy] unexposed function: ${name}`);
|
|
29225
30026
|
return piggy;
|
|
29226
30027
|
},
|
|
29227
|
-
proxy: {
|
|
29228
|
-
load: (path) => {
|
|
29229
|
-
if (!_client)
|
|
29230
|
-
throw new Error("No client");
|
|
29231
|
-
return _client.proxyLoad(path);
|
|
29232
|
-
},
|
|
29233
|
-
fetch: (url2) => {
|
|
29234
|
-
if (!_client)
|
|
29235
|
-
throw new Error("No client");
|
|
29236
|
-
return _client.proxyFetch(url2);
|
|
29237
|
-
},
|
|
29238
|
-
ovpn: (path) => {
|
|
29239
|
-
if (!_client)
|
|
29240
|
-
throw new Error("No client");
|
|
29241
|
-
return _client.proxyOvpn(path);
|
|
29242
|
-
},
|
|
29243
|
-
set: (opts) => {
|
|
29244
|
-
if (!_client)
|
|
29245
|
-
throw new Error("No client");
|
|
29246
|
-
return _client.proxySet(opts);
|
|
29247
|
-
},
|
|
29248
|
-
test: () => {
|
|
29249
|
-
if (!_client)
|
|
29250
|
-
throw new Error("No client");
|
|
29251
|
-
return _client.proxyTest();
|
|
29252
|
-
},
|
|
29253
|
-
testStop: () => {
|
|
29254
|
-
if (!_client)
|
|
29255
|
-
throw new Error("No client");
|
|
29256
|
-
return _client.proxyTestStop();
|
|
29257
|
-
},
|
|
29258
|
-
next: () => {
|
|
29259
|
-
if (!_client)
|
|
29260
|
-
throw new Error("No client");
|
|
29261
|
-
return _client.proxyNext();
|
|
29262
|
-
},
|
|
29263
|
-
disable: () => {
|
|
29264
|
-
if (!_client)
|
|
29265
|
-
throw new Error("No client");
|
|
29266
|
-
return _client.proxyDisable();
|
|
29267
|
-
},
|
|
29268
|
-
enable: () => {
|
|
29269
|
-
if (!_client)
|
|
29270
|
-
throw new Error("No client");
|
|
29271
|
-
return _client.proxyEnable();
|
|
29272
|
-
},
|
|
29273
|
-
current: () => {
|
|
29274
|
-
if (!_client)
|
|
29275
|
-
throw new Error("No client");
|
|
29276
|
-
return _client.proxyCurrent();
|
|
29277
|
-
},
|
|
29278
|
-
stats: () => {
|
|
29279
|
-
if (!_client)
|
|
29280
|
-
throw new Error("No client");
|
|
29281
|
-
return _client.proxyStats();
|
|
29282
|
-
},
|
|
29283
|
-
list: (limit) => {
|
|
29284
|
-
if (!_client)
|
|
29285
|
-
throw new Error("No client");
|
|
29286
|
-
return _client.proxyList(limit);
|
|
29287
|
-
},
|
|
29288
|
-
rotation: (mode, interval) => {
|
|
29289
|
-
if (!_client)
|
|
29290
|
-
throw new Error("No client");
|
|
29291
|
-
return _client.proxyRotation(mode, interval);
|
|
29292
|
-
},
|
|
29293
|
-
config: (opts) => {
|
|
29294
|
-
if (!_client)
|
|
29295
|
-
throw new Error("No client");
|
|
29296
|
-
return _client.proxyConfig(opts);
|
|
29297
|
-
},
|
|
29298
|
-
save: (path, filter) => {
|
|
29299
|
-
if (!_client)
|
|
29300
|
-
throw new Error("No client");
|
|
29301
|
-
return _client.proxySave(path, filter);
|
|
29302
|
-
},
|
|
29303
|
-
on: (event, handler) => {
|
|
29304
|
-
if (!_client)
|
|
29305
|
-
throw new Error("No client");
|
|
29306
|
-
return _client.onProxyEvent(event, handler);
|
|
29307
|
-
}
|
|
29308
|
-
},
|
|
29309
30028
|
serve: (port, opts) => startServer(port, opts?.hostname, opts),
|
|
29310
30029
|
stopServer,
|
|
29311
30030
|
routes: () => Array.from(routeRegistry.entries()).map(([key, cfg]) => {
|
|
@@ -29347,6 +30066,7 @@ var piggy = {
|
|
|
29347
30066
|
_extraProcs.length = 0;
|
|
29348
30067
|
_client?.disconnect();
|
|
29349
30068
|
_client = null;
|
|
30069
|
+
_router = null;
|
|
29350
30070
|
setClient(null);
|
|
29351
30071
|
killBrowser();
|
|
29352
30072
|
}
|