nothing-browser 0.0.21 → 0.1.1

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 (68) hide show
  1. package/LICENSE +1 -1
  2. package/dist/human/index.js +25 -1
  3. package/dist/piggy/captcha/index.d.ts +39 -0
  4. package/dist/piggy/captcha/index.d.ts.map +1 -0
  5. package/dist/piggy/capture/index.d.ts +48 -0
  6. package/dist/piggy/capture/index.d.ts.map +1 -0
  7. package/dist/piggy/dialog/index.d.ts +28 -0
  8. package/dist/piggy/dialog/index.d.ts.map +1 -0
  9. package/dist/piggy/export/index.d.ts +62 -0
  10. package/dist/piggy/export/index.d.ts.map +1 -0
  11. package/dist/piggy/find/index.d.ts +52 -0
  12. package/dist/piggy/find/index.d.ts.map +1 -0
  13. package/dist/piggy/http/index.d.ts +14 -0
  14. package/dist/piggy/http/index.d.ts.map +1 -0
  15. package/dist/piggy/human/index.d.ts +36 -4
  16. package/dist/piggy/human/index.d.ts.map +1 -1
  17. package/dist/piggy/iframe/index.d.ts +53 -0
  18. package/dist/piggy/iframe/index.d.ts.map +1 -0
  19. package/dist/piggy/interactions/index.d.ts +24 -0
  20. package/dist/piggy/interactions/index.d.ts.map +1 -0
  21. package/dist/piggy/media/index.d.ts +11 -0
  22. package/dist/piggy/media/index.d.ts.map +1 -0
  23. package/dist/piggy/navigation/index.d.ts +16 -0
  24. package/dist/piggy/navigation/index.d.ts.map +1 -0
  25. package/dist/piggy/provide/index.d.ts +98 -0
  26. package/dist/piggy/provide/index.d.ts.map +1 -0
  27. package/dist/piggy/proxy/index.d.ts +94 -0
  28. package/dist/piggy/proxy/index.d.ts.map +1 -0
  29. package/dist/piggy/register/index.d.ts.map +1 -1
  30. package/dist/piggy/router/index.d.ts +38 -0
  31. package/dist/piggy/router/index.d.ts.map +1 -0
  32. package/dist/piggy/session/index.d.ts +27 -0
  33. package/dist/piggy/session/index.d.ts.map +1 -0
  34. package/dist/piggy/tabs/index.d.ts +10 -0
  35. package/dist/piggy/tabs/index.d.ts.map +1 -0
  36. package/dist/piggy/wait/index.d.ts +28 -0
  37. package/dist/piggy/wait/index.d.ts.map +1 -0
  38. package/dist/piggy.d.ts.map +1 -1
  39. package/dist/piggy.js +898 -181
  40. package/dist/register/index.js +39 -86
  41. package/package.json +1 -1
  42. package/piggy/captcha/index.d.ts +35 -0
  43. package/piggy/captcha/index.ts +93 -0
  44. package/piggy/capture/index.ts +76 -0
  45. package/piggy/dialog/index.d.ts +29 -0
  46. package/piggy/dialog/index.ts +85 -0
  47. package/piggy/export/index.d.ts +117 -0
  48. package/piggy/export/index.ts +147 -0
  49. package/piggy/find/index.ts +118 -0
  50. package/piggy/http/index.ts +65 -0
  51. package/piggy/human/index.ts +115 -53
  52. package/piggy/iframe/index.ts +79 -0
  53. package/piggy/interactions/index.ts +79 -0
  54. package/piggy/media/index.ts +46 -0
  55. package/piggy/navigation/index.ts +52 -0
  56. package/piggy/provide/index.ts +170 -0
  57. package/piggy/proxy/index.ts +154 -0
  58. package/piggy/register/index.ts +41 -59
  59. package/piggy/router/index.ts +69 -0
  60. package/piggy/session/index.ts +76 -0
  61. package/piggy/tabs/index.ts +22 -0
  62. package/piggy/wait/index.ts +90 -0
  63. package/piggy.ts +94 -39
  64. package/dist/piggy/open/index.d.ts +0 -4
  65. package/dist/piggy/open/index.d.ts.map +0 -1
  66. package/piggy/open/index.d.ts +0 -4
  67. package/piggy/open/index.d.ts.map +0 -1
  68. 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 randomDelay(80, 220);
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 randomDelay(80, 200);
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 randomDelay(50, 150);
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 && !opts?.fact) {
28786
- const seq = humanTypeSequence(text);
28787
- let current = "";
28788
- for (const action of seq) {
28789
- if (action === "BACKSPACE")
28790
- current = current.slice(0, -1);
28791
- else
28792
- current += action;
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
- (function() {
28795
- const el = document.querySelector('${selector}');
28796
- const nativeSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
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
- document.querySelector('${selector}').dispatchEvent(new Event('blur', { bubbles: true }))
28816
- `, t2);
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 randomDelay(30, 80);
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,785 @@ 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(text, tabId = "default") {
29337
+ return this.client.send("find.byText", { text, tabId });
29338
+ }
29339
+ byAttr(attr, value, tabId = "default") {
29340
+ return this.client.send("find.byAttr", { attr, value, 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(role, name, tabId = "default") {
29349
+ return this.client.send("find.byRole", { role, name, tabId });
29350
+ }
29351
+ children(selector, tabId = "default") {
29352
+ return this.client.send("find.children", { selector, tabId });
29353
+ }
29354
+ parent(selector, tabId = "default") {
29355
+ return this.client.send("find.parent", { selector, tabId });
29356
+ }
29357
+ closest(selector, ancestor, tabId = "default") {
29358
+ return this.client.send("find.closest", { selector, ancestor, tabId });
29359
+ }
29360
+ count(selector, tabId = "default") {
29361
+ return this.client.send("find.count", { selector, tabId });
29362
+ }
29363
+ exists(selector, tabId = "default") {
29364
+ return this.client.send("find.exists", { selector, tabId });
29365
+ }
29366
+ visible(selector, tabId = "default") {
29367
+ return this.client.send("find.visible", { selector, tabId });
29368
+ }
29369
+ enabled(selector, tabId = "default") {
29370
+ return this.client.send("find.enabled", { selector, tabId });
29371
+ }
29372
+ checked(selector, tabId = "default") {
29373
+ return this.client.send("find.checked", { selector, tabId });
29374
+ }
29375
+ }
29376
+ function createFindAPI(client) {
29377
+ return new FindClient(client);
29378
+ }
29379
+
29380
+ // piggy/iframe/index.ts
29381
+ class IframeClient {
29382
+ client;
29383
+ constructor(client) {
29384
+ this.client = client;
29385
+ }
29386
+ list(tabId = "default") {
29387
+ return this.client.send("iframe.list", { tabId });
29388
+ }
29389
+ evaluate(opts, tabId = "default") {
29390
+ return this.client.send("iframe.evaluate", { ...opts, tabId });
29391
+ }
29392
+ click(opts, tabId = "default") {
29393
+ return this.client.send("iframe.click", { ...opts, tabId });
29394
+ }
29395
+ type(opts, tabId = "default") {
29396
+ return this.client.send("iframe.type", { ...opts, tabId });
29397
+ }
29398
+ text(opts, tabId = "default") {
29399
+ return this.client.send("iframe.text", { ...opts, tabId });
29400
+ }
29401
+ html(opts, tabId = "default") {
29402
+ return this.client.send("iframe.html", { ...opts, tabId });
29403
+ }
29404
+ waitSel(opts, tabId = "default") {
29405
+ return this.client.send("iframe.waitSel", { ...opts, tabId });
29406
+ }
29407
+ }
29408
+ function createIframeAPI(client) {
29409
+ return new IframeClient(client);
29410
+ }
29411
+
29412
+ // piggy/interactions/index.ts
29413
+ class InteractionsClient {
29414
+ client;
29415
+ constructor(client) {
29416
+ this.client = client;
29417
+ }
29418
+ click(selector, tabId = "default") {
29419
+ return this.client.send("click", { selector, tabId });
29420
+ }
29421
+ dblclick(selector, tabId = "default") {
29422
+ return this.client.send("dblclick", { selector, tabId });
29423
+ }
29424
+ hover(selector, tabId = "default") {
29425
+ return this.client.send("hover", { selector, tabId });
29426
+ }
29427
+ type(selector, text, tabId = "default") {
29428
+ return this.client.send("type", { selector, text, tabId });
29429
+ }
29430
+ typeClear(selector, text, tabId = "default") {
29431
+ return this.client.send("type", { selector, text, clear: true, tabId });
29432
+ }
29433
+ select(selector, value, tabId = "default") {
29434
+ return this.client.send("select", { selector, value, tabId });
29435
+ }
29436
+ scrollTo(selector, tabId = "default") {
29437
+ return this.client.send("scroll.to", { selector, tabId });
29438
+ }
29439
+ scrollBy(px, tabId = "default") {
29440
+ return this.client.send("scroll.by", { px, tabId });
29441
+ }
29442
+ keyPress(key, tabId = "default") {
29443
+ return this.client.send("keyboard.press", { key, tabId });
29444
+ }
29445
+ keyCombo(combo, tabId = "default") {
29446
+ return this.client.send("keyboard.combo", { combo, tabId });
29447
+ }
29448
+ mouseMove(x, y, tabId = "default") {
29449
+ return this.client.send("mouse.move", { x, y, tabId });
29450
+ }
29451
+ mouseDrag(from, to, tabId = "default") {
29452
+ return this.client.send("mouse.drag", { from, to, tabId });
29453
+ }
29454
+ evaluate(js, tabId = "default") {
29455
+ return this.client.send("evaluate", { js, tabId });
29456
+ }
29457
+ }
29458
+ function createInteractionsAPI(client) {
29459
+ return new InteractionsClient(client);
29460
+ }
29461
+
29462
+ // piggy/media/index.ts
29463
+ import { writeFileSync as writeFileSync3, mkdirSync as mkdirSync3 } from "fs";
29464
+ import { dirname as dirname3 } from "path";
29465
+
29466
+ class MediaClient {
29467
+ client;
29468
+ constructor(client) {
29469
+ this.client = client;
29470
+ }
29471
+ async screenshot(filePath, tabId = "default") {
29472
+ const b64 = await this.client.send("screenshot", { tabId });
29473
+ if (filePath) {
29474
+ mkdirSync3(dirname3(filePath), { recursive: true });
29475
+ writeFileSync3(filePath, Buffer.from(b64, "base64"));
29476
+ return filePath;
29477
+ }
29478
+ return b64;
29479
+ }
29480
+ async pdf(filePath, tabId = "default") {
29481
+ const b64 = await this.client.send("pdf", { tabId });
29482
+ if (filePath) {
29483
+ mkdirSync3(dirname3(filePath), { recursive: true });
29484
+ writeFileSync3(filePath, Buffer.from(b64, "base64"));
29485
+ return filePath;
29486
+ }
29487
+ return b64;
29488
+ }
29489
+ blockImages(tabId = "default") {
29490
+ return this.client.send("intercept.block.images", { tabId });
29491
+ }
29492
+ unblockImages(tabId = "default") {
29493
+ return this.client.send("intercept.unblock.images", { tabId });
29494
+ }
29495
+ }
29496
+ function createMediaAPI(client) {
29497
+ return new MediaClient(client);
29498
+ }
29499
+
29500
+ // piggy/navigation/index.ts
29501
+ class NavigationClient {
29502
+ client;
29503
+ constructor(client) {
29504
+ this.client = client;
29505
+ }
29506
+ navigate(url2, tabId = "default") {
29507
+ return this.client.send("navigate", { url: url2, tabId });
29508
+ }
29509
+ reload(tabId = "default") {
29510
+ return this.client.send("reload", { tabId });
29511
+ }
29512
+ goBack(tabId = "default") {
29513
+ return this.client.send("go.back", { tabId });
29514
+ }
29515
+ goForward(tabId = "default") {
29516
+ return this.client.send("go.forward", { tabId });
29517
+ }
29518
+ url(tabId = "default") {
29519
+ return this.client.send("page.url", { tabId });
29520
+ }
29521
+ title(tabId = "default") {
29522
+ return this.client.send("page.title", { tabId });
29523
+ }
29524
+ content(tabId = "default") {
29525
+ return this.client.send("page.content", { tabId });
29526
+ }
29527
+ waitForNavigation(tabId = "default") {
29528
+ return this.client.send("wait.navigation", { tabId });
29529
+ }
29530
+ waitForSelector(selector, timeout = 1e4, tabId = "default") {
29531
+ return this.client.send("wait.selector", { selector, timeout, tabId });
29532
+ }
29533
+ }
29534
+ function createNavigationAPI(client) {
29535
+ return new NavigationClient(client);
29536
+ }
29537
+
29538
+ // piggy/provide/index.ts
29539
+ class ProvideClient {
29540
+ client;
29541
+ constructor(client) {
29542
+ this.client = client;
29543
+ }
29544
+ text(opts, tabId = "default") {
29545
+ return this.client.send("provide.text", { ...opts, tabId });
29546
+ }
29547
+ textAll(opts, tabId = "default") {
29548
+ return this.client.send("provide.textAll", { ...opts, tabId });
29549
+ }
29550
+ attr(opts, tabId = "default") {
29551
+ return this.client.send("provide.attr", { ...opts, tabId });
29552
+ }
29553
+ attrAll(opts, tabId = "default") {
29554
+ return this.client.send("provide.attrAll", { ...opts, tabId });
29555
+ }
29556
+ html(opts, tabId = "default") {
29557
+ return this.client.send("provide.html", { ...opts, tabId });
29558
+ }
29559
+ table(opts, tabId = "default") {
29560
+ return this.client.send("provide.table", { ...opts, tabId });
29561
+ }
29562
+ list(opts, tabId = "default") {
29563
+ return this.client.send("provide.list", { ...opts, tabId });
29564
+ }
29565
+ links(opts, tabId = "default") {
29566
+ return this.client.send("provide.links", { ...opts, tabId });
29567
+ }
29568
+ images(opts, tabId = "default") {
29569
+ return this.client.send("provide.images", { ...opts, tabId });
29570
+ }
29571
+ form(opts, tabId = "default") {
29572
+ return this.client.send("provide.form", { ...opts, tabId });
29573
+ }
29574
+ page(tabId = "default") {
29575
+ return this.client.send("provide.page", { tabId });
29576
+ }
29577
+ div(opts, tabId = "default") {
29578
+ return this.client.send("provide.div", { ...opts, tabId });
29579
+ }
29580
+ meta(tabId = "default") {
29581
+ return this.client.send("provide.meta", { tabId });
29582
+ }
29583
+ select(opts, tabId = "default") {
29584
+ return this.client.send("provide.select", { ...opts, tabId });
29585
+ }
29586
+ json(opts, tabId = "default") {
29587
+ return this.client.send("provide.json", { ...opts, tabId });
29588
+ }
29589
+ }
29590
+ function createProvideAPI(client) {
29591
+ return new ProvideClient(client);
29592
+ }
29593
+
29594
+ // piggy/proxy/index.ts
29595
+ class ProxyClient {
29596
+ client;
29597
+ constructor(client) {
29598
+ this.client = client;
29599
+ }
29600
+ load(path) {
29601
+ return this.client.send("proxy.load", { path });
29602
+ }
29603
+ fetch(url2) {
29604
+ return this.client.send("proxy.fetch", { url: url2 });
29605
+ }
29606
+ ovpn(path) {
29607
+ return this.client.send("proxy.ovpn", { path });
29608
+ }
29609
+ set(opts) {
29610
+ return this.client.send("proxy.set", opts);
29611
+ }
29612
+ test() {
29613
+ return this.client.send("proxy.test", {});
29614
+ }
29615
+ testStop() {
29616
+ return this.client.send("proxy.test.stop", {});
29617
+ }
29618
+ next() {
29619
+ return this.client.send("proxy.next", {});
29620
+ }
29621
+ rotate() {
29622
+ return this.client.send("proxy.rotate", {});
29623
+ }
29624
+ disable() {
29625
+ return this.client.send("proxy.disable", {});
29626
+ }
29627
+ enable() {
29628
+ return this.client.send("proxy.enable", {});
29629
+ }
29630
+ current() {
29631
+ return this.client.send("proxy.current", {});
29632
+ }
29633
+ stats() {
29634
+ return this.client.send("proxy.stats", {});
29635
+ }
29636
+ list(limit) {
29637
+ return this.client.send("proxy.list", { limit });
29638
+ }
29639
+ rotation(mode, interval) {
29640
+ return this.client.send("proxy.rotation", { mode, interval });
29641
+ }
29642
+ config(opts) {
29643
+ return this.client.send("proxy.config", opts);
29644
+ }
29645
+ save(path, filter) {
29646
+ return this.client.send("proxy.save", { path, filter });
29647
+ }
29648
+ }
29649
+ function createProxyAPI(client) {
29650
+ return new ProxyClient(client);
29651
+ }
29652
+
29653
+ // piggy/session/index.ts
29654
+ class SessionClient {
29655
+ client;
29656
+ constructor(client) {
29657
+ this.client = client;
29658
+ }
29659
+ reload(tabId = "default") {
29660
+ return this.client.send("session.reload", { tabId });
29661
+ }
29662
+ paths() {
29663
+ return this.client.send("session.paths", {});
29664
+ }
29665
+ cookiesPath() {
29666
+ return this.client.send("session.cookies.path", {});
29667
+ }
29668
+ profilePath() {
29669
+ return this.client.send("session.profile.path", {});
29670
+ }
29671
+ wsPath() {
29672
+ return this.client.send("session.ws.path", {});
29673
+ }
29674
+ pingsPath() {
29675
+ return this.client.send("session.pings.path", {});
29676
+ }
29677
+ setWsSave(enabled) {
29678
+ return this.client.send("session.ws.save", { enabled });
29679
+ }
29680
+ setPingsSave(enabled) {
29681
+ return this.client.send("session.pings.save", { enabled });
29682
+ }
29683
+ async export(tabId = "default") {
29684
+ const raw = await this.client.send("session.export", { tabId });
29685
+ return typeof raw === "string" ? JSON.parse(raw) : raw;
29686
+ }
29687
+ import(data, tabId = "default") {
29688
+ return this.client.send("session.import", {
29689
+ data: JSON.stringify(data),
29690
+ tabId
29691
+ });
29692
+ }
29693
+ setCookie(opts, tabId = "default") {
29694
+ return this.client.send("cookie.set", { ...opts, tabId });
29695
+ }
29696
+ deleteCookie(opts, tabId = "default") {
29697
+ return this.client.send("cookie.delete", { ...opts, tabId });
29698
+ }
29699
+ }
29700
+ function createSessionAPI(client) {
29701
+ return new SessionClient(client);
29702
+ }
29703
+
29704
+ // piggy/tabs/index.ts
29705
+ class TabsClient {
29706
+ client;
29707
+ constructor(client) {
29708
+ this.client = client;
29709
+ }
29710
+ new() {
29711
+ return this.client.send("tab.new", {});
29712
+ }
29713
+ close(tabId) {
29714
+ return this.client.send("tab.close", { tabId });
29715
+ }
29716
+ list() {
29717
+ return this.client.send("tab.list", {});
29718
+ }
29719
+ }
29720
+ function createTabsAPI(client) {
29721
+ return new TabsClient(client);
29722
+ }
29723
+
29724
+ // piggy/wait/index.ts
29725
+ class WaitClient {
29726
+ client;
29727
+ constructor(client) {
29728
+ this.client = client;
29729
+ }
29730
+ function(js, timeout = 1e4, tabId = "default") {
29731
+ return this.client.send("wait.function", { js, timeout, tabId });
29732
+ }
29733
+ selector(selector, state = "attached", timeout = 1e4, tabId = "default") {
29734
+ return this.client.send("wait.selector", { selector, state, timeout, tabId });
29735
+ }
29736
+ }
29737
+
29738
+ class EvaluateClient {
29739
+ client;
29740
+ constructor(client) {
29741
+ this.client = client;
29742
+ }
29743
+ run(js, timeout, tabId = "default") {
29744
+ return this.client.send("evaluate", {
29745
+ js,
29746
+ tabId,
29747
+ ...timeout !== undefined ? { timeout } : {}
29748
+ });
29749
+ }
29750
+ }
29751
+
29752
+ class FetchClient {
29753
+ client;
29754
+ constructor(client) {
29755
+ this.client = client;
29756
+ }
29757
+ text(selector, tabId = "default") {
29758
+ return this.client.send("fetch.text", { query: selector, tabId });
29759
+ }
29760
+ textAll(selector, tabId = "default") {
29761
+ return this.client.send("fetch.textAll", { selector, tabId });
29762
+ }
29763
+ attr(selector, attr, tabId = "default") {
29764
+ return this.client.send("fetch.attr", { selector, attr, tabId });
29765
+ }
29766
+ attrAll(selector, attr, tabId = "default") {
29767
+ return this.client.send("fetch.attrAll", { selector, attr, tabId });
29768
+ }
29769
+ links(selector, tabId = "default") {
29770
+ return this.client.send("fetch.links", { query: selector, tabId });
29771
+ }
29772
+ linksAll(tabId = "default") {
29773
+ return this.client.send("fetch.links.all", { tabId });
29774
+ }
29775
+ images(selector, tabId = "default") {
29776
+ return this.client.send("fetch.image", { query: selector, tabId });
29777
+ }
29778
+ }
29779
+ function createWaitAPI(client) {
29780
+ return new WaitClient(client);
29781
+ }
29782
+ function createEvaluateAPI(client) {
29783
+ return new EvaluateClient(client);
29784
+ }
29785
+ function createFetchAPI(client) {
29786
+ return new FetchClient(client);
29787
+ }
29788
+
29789
+ // piggy/router/index.ts
29790
+ function createRouter(client) {
29791
+ return {
29792
+ client,
29793
+ tabs: createTabsAPI(client),
29794
+ navigation: createNavigationAPI(client),
29795
+ interactions: createInteractionsAPI(client),
29796
+ media: createMediaAPI(client),
29797
+ capture: createCaptureAPI(client),
29798
+ find: createFindAPI(client),
29799
+ provide: createProvideAPI(client),
29800
+ wait: createWaitAPI(client),
29801
+ evaluate: createEvaluateAPI(client),
29802
+ fetch: createFetchAPI(client),
29803
+ proxy: createProxyAPI(client),
29804
+ captcha: createCaptchaAPI(client),
29805
+ dialog: createDialogAPI(client),
29806
+ human: createHumanAPI(client),
29807
+ iframe: createIframeAPI(client),
29808
+ session: createSessionAPI(client),
29809
+ export: createExportAPI(client)
29810
+ };
29811
+ }
29812
+
29813
+ // piggy/http/index.ts
29814
+ class PiggyHttpClient {
29815
+ baseUrl;
29816
+ key;
29817
+ constructor(opts) {
29818
+ const host = opts.host ?? "localhost";
29819
+ const port = opts.port ?? 2005;
29820
+ this.baseUrl = `http://${host}:${port}`;
29821
+ this.key = opts.key;
29822
+ }
29823
+ async ping() {
29824
+ try {
29825
+ const res = await fetch(this.baseUrl, {
29826
+ method: "POST",
29827
+ headers: {
29828
+ "Content-Type": "application/json",
29829
+ "X-Piggy-Key": this.key
29830
+ },
29831
+ body: "hello"
29832
+ });
29833
+ const text = await res.text();
29834
+ return text.includes("active");
29835
+ } catch {
29836
+ return false;
29837
+ }
29838
+ }
29839
+ async send(cmd, payload = {}) {
29840
+ const res = await fetch(this.baseUrl, {
29841
+ method: "POST",
29842
+ headers: {
29843
+ "Content-Type": "application/json",
29844
+ "X-Piggy-Key": this.key
29845
+ },
29846
+ body: JSON.stringify({ id: String(Date.now()), cmd, payload })
29847
+ });
29848
+ if (res.status === 401)
29849
+ throw new Error("Unauthorized — invalid X-Piggy-Key");
29850
+ if (res.status === 400)
29851
+ throw new Error("Bad request — invalid JSON");
29852
+ if (!res.ok)
29853
+ throw new Error(`HTTP ${res.status}`);
29854
+ const data = await res.json();
29855
+ if (!data.ok)
29856
+ throw new Error(String(data.data) ?? "command failed");
29857
+ return data.data;
29858
+ }
29859
+ }
29860
+ function createHttpClient(opts) {
29861
+ return new PiggyHttpClient(opts);
29862
+ }
29863
+
29143
29864
  // piggy.ts
29144
29865
  var _client = null;
29866
+ var _router = null;
29145
29867
  var _tabMode = "tab";
29146
29868
  var _extraProcs = [];
29147
- var _sites = [];
29869
+ var _sites = {};
29870
+ function guardClient() {
29871
+ if (!_client)
29872
+ throw new Error("No client. Call piggy.launch() or piggy.connect() first.");
29873
+ return _client;
29874
+ }
29875
+ function buildAPIs(client) {
29876
+ _router = createRouter(client);
29877
+ }
29148
29878
  var piggy = {
29149
29879
  launch: async (opts) => {
29150
29880
  _tabMode = opts?.mode ?? "tab";
@@ -29154,6 +29884,7 @@ var piggy = {
29154
29884
  _client = new PiggyClient;
29155
29885
  await _client.connect();
29156
29886
  setClient(_client);
29887
+ buildAPIs(_client);
29157
29888
  logger_default.info(`[piggy] launched — tab mode: "${_tabMode}", binary: "${binaryMode}"`);
29158
29889
  return piggy;
29159
29890
  },
@@ -29162,27 +29893,28 @@ var piggy = {
29162
29893
  _client = new PiggyClient({ host: opts.host, key: opts.key });
29163
29894
  await _client.connect();
29164
29895
  setClient(_client);
29896
+ buildAPIs(_client);
29165
29897
  logger_default.info(`[piggy] connected (HTTP) → ${opts.host}`);
29166
29898
  return piggy;
29167
29899
  },
29900
+ http: (opts) => createHttpClient(opts),
29168
29901
  register: async (name, url2, opts) => {
29169
29902
  if (!url2?.trim())
29170
29903
  throw new Error(`No URL for site "${name}"`);
29171
29904
  const binaryMode = opts?.binary ?? "headless";
29172
29905
  const poolSize = opts?.pool ?? 0;
29173
29906
  if (_tabMode === "tab") {
29174
- if (!_client)
29175
- throw new Error("No client. Call piggy.launch() or piggy.connect() first.");
29907
+ const client = guardClient();
29176
29908
  if (poolSize > 1) {
29177
- const pool = new TabPool(_client, poolSize, url2, name);
29909
+ const pool = new TabPool(client, poolSize, url2, name);
29178
29910
  await pool.init();
29179
- const siteObj = createSiteObject(name, url2, _client, "default", pool);
29911
+ const siteObj = createSiteObject(name, url2, client, "default", pool);
29180
29912
  _sites[name] = siteObj;
29181
29913
  piggy[name] = siteObj;
29182
29914
  logger_default.success(`[${name}] registered with pool of ${poolSize} tabs`);
29183
29915
  } else {
29184
- const tabId = await _client.newTab();
29185
- const siteObj = createSiteObject(name, url2, _client, tabId);
29916
+ const tabId = await client.newTab();
29917
+ const siteObj = createSiteObject(name, url2, client, tabId);
29186
29918
  _sites[name] = siteObj;
29187
29919
  piggy[name] = siteObj;
29188
29920
  logger_default.success(`[${name}] registered as tab ${tabId}`);
@@ -29201,6 +29933,76 @@ var piggy = {
29201
29933
  }
29202
29934
  return piggy;
29203
29935
  },
29936
+ get tabs() {
29937
+ return _router?.tabs ?? createTabsAPI(guardClient());
29938
+ },
29939
+ get navigation() {
29940
+ return _router?.navigation ?? createNavigationAPI(guardClient());
29941
+ },
29942
+ get interactions() {
29943
+ return _router?.interactions ?? createInteractionsAPI(guardClient());
29944
+ },
29945
+ get media() {
29946
+ return _router?.media ?? createMediaAPI(guardClient());
29947
+ },
29948
+ get capture() {
29949
+ return _router?.capture ?? createCaptureAPI(guardClient());
29950
+ },
29951
+ get find() {
29952
+ return _router?.find ?? createFindAPI(guardClient());
29953
+ },
29954
+ get provide() {
29955
+ return _router?.provide ?? createProvideAPI(guardClient());
29956
+ },
29957
+ get wait() {
29958
+ return _router?.wait ?? createWaitAPI(guardClient());
29959
+ },
29960
+ get evaluate() {
29961
+ return _router?.evaluate ?? createEvaluateAPI(guardClient());
29962
+ },
29963
+ get fetch() {
29964
+ return _router?.fetch ?? createFetchAPI(guardClient());
29965
+ },
29966
+ get captcha() {
29967
+ return _router?.captcha ?? createCaptchaAPI(guardClient());
29968
+ },
29969
+ get dialog() {
29970
+ return _router?.dialog ?? createDialogAPI(guardClient());
29971
+ },
29972
+ get human() {
29973
+ return _router?.human ?? createHumanAPI(guardClient());
29974
+ },
29975
+ get iframe() {
29976
+ return _router?.iframe ?? createIframeAPI(guardClient());
29977
+ },
29978
+ get session() {
29979
+ return _router?.session ?? createSessionAPI(guardClient());
29980
+ },
29981
+ get export() {
29982
+ return _router?.export ?? createExportAPI(guardClient());
29983
+ },
29984
+ get proxy() {
29985
+ const api = _router?.proxy ?? createProxyAPI(guardClient());
29986
+ return {
29987
+ load: (path) => api.load(path),
29988
+ fetch: (url2) => api.fetch(url2),
29989
+ ovpn: (path) => api.ovpn(path),
29990
+ set: (opts) => api.set(opts),
29991
+ test: () => api.test(),
29992
+ testStop: () => api.testStop(),
29993
+ next: () => api.next(),
29994
+ rotate: () => api.rotate(),
29995
+ disable: () => api.disable(),
29996
+ enable: () => api.enable(),
29997
+ current: () => api.current(),
29998
+ stats: () => api.stats(),
29999
+ list: (limit) => api.list(limit),
30000
+ rotation: (mode, interval) => api.rotation(mode, interval),
30001
+ config: (opts) => api.config(opts),
30002
+ save: (path, filter) => api.save(path, filter),
30003
+ on: (event, handler) => guardClient().onProxyEvent(event, handler)
30004
+ };
30005
+ },
29204
30006
  actHuman: (enable) => {
29205
30007
  setHumanMode(enable);
29206
30008
  logger_default.info(`[piggy] actHuman: ${enable}`);
@@ -29211,101 +30013,15 @@ var piggy = {
29211
30013
  return piggy;
29212
30014
  },
29213
30015
  expose: async (name, handler, tabId = "default") => {
29214
- if (!_client)
29215
- throw new Error("No client. Call piggy.launch() or piggy.connect() first.");
29216
- await _client.exposeFunction(name, handler, tabId);
30016
+ await guardClient().exposeFunction(name, handler, tabId);
29217
30017
  logger_default.success(`[piggy] exposed global function: ${name}`);
29218
30018
  return piggy;
29219
30019
  },
29220
30020
  unexpose: async (name, tabId = "default") => {
29221
- if (!_client)
29222
- throw new Error("No client. Call piggy.launch() or piggy.connect() first.");
29223
- await _client.unexposeFunction(name, tabId);
30021
+ await guardClient().unexposeFunction(name, tabId);
29224
30022
  logger_default.info(`[piggy] unexposed function: ${name}`);
29225
30023
  return piggy;
29226
30024
  },
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
30025
  serve: (port, opts) => startServer(port, opts?.hostname, opts),
29310
30026
  stopServer,
29311
30027
  routes: () => Array.from(routeRegistry.entries()).map(([key, cfg]) => {
@@ -29347,6 +30063,7 @@ var piggy = {
29347
30063
  _extraProcs.length = 0;
29348
30064
  _client?.disconnect();
29349
30065
  _client = null;
30066
+ _router = null;
29350
30067
  setClient(null);
29351
30068
  killBrowser();
29352
30069
  }