nothing-browser 0.1.2 → 0.1.4
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/package.json +14 -26
- package/piggy/cache/{memory.ts → memory.js} +5 -10
- package/piggy/captcha/{index.ts → index.js} +19 -28
- package/piggy/capture/index.js +40 -0
- package/piggy/client/{index.ts → index.js} +133 -154
- package/piggy/dialog/{index.ts → index.js} +15 -31
- package/piggy/export/index.js +105 -0
- package/piggy/expose/index.js +24 -0
- package/piggy/find/{index.ts → index.js} +24 -39
- package/piggy/http/{index.ts → index.js} +7 -16
- package/piggy/human/{index.ts → index.js} +18 -49
- package/piggy/iframe/index.js +56 -0
- package/piggy/interactions/{index.ts → index.js} +20 -23
- package/piggy/intercept/{scripts.ts → scripts.js} +4 -13
- package/piggy/launch/{detect.ts → detect.js} +4 -6
- package/piggy/launch/{spawn.ts → spawn.js} +17 -22
- package/piggy/media/{index.ts → index.js} +13 -11
- package/piggy/navigation/{index.ts → index.js} +16 -14
- package/piggy/pool/index.js +76 -0
- package/piggy/provide/index.js +97 -0
- package/piggy/proxy/index.js +95 -0
- package/piggy/register/index.js +543 -0
- package/piggy/router/index.js +44 -0
- package/piggy/server/{index.ts → index.js} +16 -64
- package/piggy/session/index.js +69 -0
- package/piggy/store/{index.ts → index.js} +22 -62
- package/piggy/tabs/index.js +24 -0
- package/piggy/wait/index.js +77 -0
- package/piggy.js +316 -0
- package/dist/cache/memory.js +0 -35
- package/dist/client/index.js +0 -1284
- package/dist/human/index.js +0 -82
- package/dist/launch/detect.js +0 -782
- package/dist/launch/spawn.js +0 -915
- package/dist/logger/index.js +0 -733
- package/dist/piggy/cache/memory.d.ts +0 -7
- package/dist/piggy/cache/memory.d.ts.map +0 -1
- package/dist/piggy/captcha/index.d.ts +0 -39
- package/dist/piggy/captcha/index.d.ts.map +0 -1
- package/dist/piggy/capture/index.d.ts +0 -48
- package/dist/piggy/capture/index.d.ts.map +0 -1
- package/dist/piggy/client/index.d.ts +0 -146
- package/dist/piggy/client/index.d.ts.map +0 -1
- package/dist/piggy/dialog/index.d.ts +0 -28
- package/dist/piggy/dialog/index.d.ts.map +0 -1
- package/dist/piggy/export/index.d.ts +0 -62
- package/dist/piggy/export/index.d.ts.map +0 -1
- package/dist/piggy/expose/index.d.ts +0 -6
- package/dist/piggy/expose/index.d.ts.map +0 -1
- package/dist/piggy/find/index.d.ts +0 -52
- package/dist/piggy/find/index.d.ts.map +0 -1
- package/dist/piggy/http/index.d.ts +0 -14
- package/dist/piggy/http/index.d.ts.map +0 -1
- package/dist/piggy/human/index.d.ts +0 -39
- package/dist/piggy/human/index.d.ts.map +0 -1
- package/dist/piggy/iframe/index.d.ts +0 -53
- package/dist/piggy/iframe/index.d.ts.map +0 -1
- package/dist/piggy/interactions/index.d.ts +0 -24
- package/dist/piggy/interactions/index.d.ts.map +0 -1
- package/dist/piggy/intercept/scripts.d.ts +0 -13
- package/dist/piggy/intercept/scripts.d.ts.map +0 -1
- package/dist/piggy/launch/detect.d.ts +0 -3
- package/dist/piggy/launch/detect.d.ts.map +0 -1
- package/dist/piggy/launch/spawn.d.ts +0 -6
- package/dist/piggy/launch/spawn.d.ts.map +0 -1
- package/dist/piggy/logger/index.d.ts +0 -3
- package/dist/piggy/logger/index.d.ts.map +0 -1
- package/dist/piggy/media/index.d.ts +0 -11
- package/dist/piggy/media/index.d.ts.map +0 -1
- package/dist/piggy/navigation/index.d.ts +0 -16
- package/dist/piggy/navigation/index.d.ts.map +0 -1
- package/dist/piggy/pool/index.d.ts +0 -23
- package/dist/piggy/pool/index.d.ts.map +0 -1
- package/dist/piggy/provide/index.d.ts +0 -98
- package/dist/piggy/provide/index.d.ts.map +0 -1
- package/dist/piggy/proxy/index.d.ts +0 -94
- package/dist/piggy/proxy/index.d.ts.map +0 -1
- package/dist/piggy/register/index.d.ts +0 -9
- package/dist/piggy/register/index.d.ts.map +0 -1
- package/dist/piggy/router/index.d.ts +0 -38
- package/dist/piggy/router/index.d.ts.map +0 -1
- package/dist/piggy/server/index.d.ts +0 -42
- package/dist/piggy/server/index.d.ts.map +0 -1
- package/dist/piggy/session/index.d.ts +0 -27
- package/dist/piggy/session/index.d.ts.map +0 -1
- package/dist/piggy/store/index.d.ts +0 -22
- package/dist/piggy/store/index.d.ts.map +0 -1
- package/dist/piggy/tabs/index.d.ts +0 -12
- package/dist/piggy/tabs/index.d.ts.map +0 -1
- package/dist/piggy/wait/index.d.ts +0 -28
- package/dist/piggy/wait/index.d.ts.map +0 -1
- package/dist/piggy.d.ts +0 -10
- package/dist/piggy.d.ts.map +0 -1
- package/dist/piggy.js +0 -30186
- package/dist/register/index.js +0 -23710
- package/dist/server/index.js +0 -26831
- package/piggy/capture/index.ts +0 -76
- package/piggy/export/index.d.ts +0 -117
- package/piggy/export/index.ts +0 -147
- package/piggy/expose/index.ts +0 -42
- package/piggy/iframe/index.ts +0 -79
- package/piggy/intercept/scripts.d.ts +0 -13
- package/piggy/intercept/scripts.d.ts.map +0 -1
- package/piggy/launch/detect.d.ts +0 -3
- package/piggy/launch/detect.d.ts.map +0 -1
- package/piggy/launch/spawn.d.ts +0 -6
- package/piggy/launch/spawn.d.ts.map +0 -1
- package/piggy/logger/index.d.ts +0 -3
- package/piggy/logger/index.d.ts.map +0 -1
- package/piggy/pool/index.d.ts +0 -12
- package/piggy/pool/index.ts +0 -75
- package/piggy/provide/index.ts +0 -170
- package/piggy/proxy/index.ts +0 -154
- package/piggy/register/index.ts +0 -575
- package/piggy/router/index.ts +0 -69
- package/piggy/session/index.ts +0 -76
- package/piggy/store/index.d.ts +0 -26
- package/piggy/tabs/index.ts +0 -23
- package/piggy/wait/index.ts +0 -90
- package/piggy.ts +0 -274
- /package/piggy/logger/{index.ts → index.js} +0 -0
package/piggy/capture/index.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
// piggy/capture/index.ts
|
|
2
|
-
import { PiggyClient } from "../client";
|
|
3
|
-
|
|
4
|
-
export interface CapturedRequest {
|
|
5
|
-
method: string;
|
|
6
|
-
url: string;
|
|
7
|
-
status: string;
|
|
8
|
-
type: string;
|
|
9
|
-
mime: string;
|
|
10
|
-
reqHeaders: string;
|
|
11
|
-
reqBody: string;
|
|
12
|
-
resHeaders: string;
|
|
13
|
-
resBody: string;
|
|
14
|
-
size: number;
|
|
15
|
-
timestamp: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface WebSocketFrame {
|
|
19
|
-
connectionId: string;
|
|
20
|
-
url: string;
|
|
21
|
-
direction: string;
|
|
22
|
-
data: string;
|
|
23
|
-
binary: boolean;
|
|
24
|
-
timestamp: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface CapturedCookie {
|
|
28
|
-
name: string;
|
|
29
|
-
value: string;
|
|
30
|
-
domain: string;
|
|
31
|
-
path: string;
|
|
32
|
-
httpOnly: boolean;
|
|
33
|
-
secure: boolean;
|
|
34
|
-
expires: string;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface StorageEntry {
|
|
38
|
-
key: string;
|
|
39
|
-
value: string;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export class CaptureClient {
|
|
43
|
-
constructor(private client: PiggyClient) {}
|
|
44
|
-
|
|
45
|
-
start(tabId = "default"): Promise<void> {
|
|
46
|
-
return this.client.send("capture.start", { tabId });
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
stop(tabId = "default"): Promise<void> {
|
|
50
|
-
return this.client.send("capture.stop", { tabId });
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
requests(tabId = "default"): Promise<CapturedRequest[]> {
|
|
54
|
-
return this.client.send("capture.requests", { tabId });
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
ws(tabId = "default"): Promise<WebSocketFrame[]> {
|
|
58
|
-
return this.client.send("capture.ws", { tabId });
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
cookies(tabId = "default"): Promise<CapturedCookie[]> {
|
|
62
|
-
return this.client.send("capture.cookies", { tabId });
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
storage(tabId = "default"): Promise<StorageEntry[]> {
|
|
66
|
-
return this.client.send("capture.storage", { tabId });
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
clear(tabId = "default"): Promise<void> {
|
|
70
|
-
return this.client.send("capture.clear", { tabId });
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function createCaptureAPI(client: PiggyClient): CaptureClient {
|
|
75
|
-
return new CaptureClient(client);
|
|
76
|
-
}
|
package/piggy/export/index.d.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
// piggy/export/index.d.ts
|
|
2
|
-
import { PiggyClient } from "../client";
|
|
3
|
-
|
|
4
|
-
export interface CookieSetOptions {
|
|
5
|
-
name: string;
|
|
6
|
-
value: string;
|
|
7
|
-
domain: string;
|
|
8
|
-
/** @default "/" */
|
|
9
|
-
path?: string;
|
|
10
|
-
/** @default false */
|
|
11
|
-
httpOnly?: boolean;
|
|
12
|
-
/** @default false */
|
|
13
|
-
secure?: boolean;
|
|
14
|
-
/** Unix epoch seconds. Omit for a session cookie. */
|
|
15
|
-
expiry?: number;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface CookieDeleteOptions {
|
|
19
|
-
name: string;
|
|
20
|
-
domain: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface CapturedRequest {
|
|
24
|
-
method: string;
|
|
25
|
-
url: string;
|
|
26
|
-
status: string;
|
|
27
|
-
type: string;
|
|
28
|
-
mime: string;
|
|
29
|
-
reqHeaders: string;
|
|
30
|
-
reqBody: string;
|
|
31
|
-
resHeaders: string;
|
|
32
|
-
resBody: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface WebSocketFrame {
|
|
36
|
-
url: string;
|
|
37
|
-
direction: string;
|
|
38
|
-
data: string;
|
|
39
|
-
binary: boolean;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface CapturedCookie {
|
|
43
|
-
name: string;
|
|
44
|
-
value: string;
|
|
45
|
-
domain: string;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface SessionExport {
|
|
49
|
-
url: string;
|
|
50
|
-
requests: CapturedRequest[];
|
|
51
|
-
ws: WebSocketFrame[];
|
|
52
|
-
cookies: CapturedCookie[];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export interface SessionPaths {
|
|
56
|
-
workDir: string;
|
|
57
|
-
cookies: string;
|
|
58
|
-
profile: string;
|
|
59
|
-
ws: string;
|
|
60
|
-
pings: string;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export interface InterceptRule {
|
|
64
|
-
pattern: string;
|
|
65
|
-
block?: boolean;
|
|
66
|
-
redirect?: string;
|
|
67
|
-
setHeaders?: Record<string, string>;
|
|
68
|
-
removeHeaders?: string[];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export interface ExposedFunctionCall {
|
|
72
|
-
name: string;
|
|
73
|
-
callId: string;
|
|
74
|
-
data: string;
|
|
75
|
-
tabId: string;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export declare class ExportClient {
|
|
79
|
-
constructor(client: PiggyClient);
|
|
80
|
-
|
|
81
|
-
// Cookies
|
|
82
|
-
setCookie(opts: CookieSetOptions, tabId?: string): Promise<void>;
|
|
83
|
-
deleteCookie(opts: CookieDeleteOptions, tabId?: string): Promise<void>;
|
|
84
|
-
|
|
85
|
-
// Session
|
|
86
|
-
sessionReload(tabId?: string): Promise<void>;
|
|
87
|
-
cookiesPath(tabId?: string): Promise<string>;
|
|
88
|
-
profilePath(tabId?: string): Promise<string>;
|
|
89
|
-
wsPath(tabId?: string): Promise<string>;
|
|
90
|
-
pingsPath(tabId?: string): Promise<string>;
|
|
91
|
-
sessionPaths(tabId?: string): Promise<SessionPaths>;
|
|
92
|
-
setWsSave(enabled: boolean, tabId?: string): Promise<void>;
|
|
93
|
-
setPingsSave(enabled: boolean, tabId?: string): Promise<void>;
|
|
94
|
-
|
|
95
|
-
// Intercept rules
|
|
96
|
-
addInterceptRule(rule: InterceptRule, tabId?: string): Promise<void>;
|
|
97
|
-
clearInterceptRules(tabId?: string): Promise<void>;
|
|
98
|
-
|
|
99
|
-
// Session export / import
|
|
100
|
-
exportSession(tabId?: string): Promise<SessionExport>;
|
|
101
|
-
importSession(data: SessionExport, tabId?: string): Promise<void>;
|
|
102
|
-
|
|
103
|
-
// Exposed functions
|
|
104
|
-
exposeFunction(name: string, tabId?: string): Promise<void>;
|
|
105
|
-
resolveExposed(callId: string, result: string, isError?: boolean, tabId?: string): Promise<void>;
|
|
106
|
-
|
|
107
|
-
// Init scripts
|
|
108
|
-
addInitScript(js: string, tabId?: string): Promise<void>;
|
|
109
|
-
|
|
110
|
-
// Events
|
|
111
|
-
onExposedFunctionCalled(
|
|
112
|
-
tabId: string,
|
|
113
|
-
handler: (call: ExposedFunctionCall) => void
|
|
114
|
-
): () => void;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export declare function createExportAPI(client: PiggyClient): ExportClient;
|
package/piggy/export/index.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
// piggy/export/index.ts
|
|
2
|
-
import { PiggyClient } from "../client";
|
|
3
|
-
import type { CapturedRequest, WebSocketFrame, CapturedCookie } from "../capture";
|
|
4
|
-
import type { SessionPaths } from "../session";
|
|
5
|
-
|
|
6
|
-
// ─── Intercept ────────────────────────────────────────────────────────────────
|
|
7
|
-
export interface InterceptRule {
|
|
8
|
-
pattern: string;
|
|
9
|
-
block?: boolean;
|
|
10
|
-
redirect?: string;
|
|
11
|
-
setHeaders?: Record<string, string>;
|
|
12
|
-
removeHeaders?: string[];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// ─── Cookie types (defined here, imported by session) ────────────────────────
|
|
16
|
-
export interface CookieSetOptions {
|
|
17
|
-
name: string;
|
|
18
|
-
value: string;
|
|
19
|
-
domain: string;
|
|
20
|
-
path?: string;
|
|
21
|
-
httpOnly?: boolean;
|
|
22
|
-
secure?: boolean;
|
|
23
|
-
expiry?: number;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface CookieDeleteOptions {
|
|
27
|
-
name: string;
|
|
28
|
-
domain: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// ─── Session export types (re-exported from capture) ────────────────────────
|
|
32
|
-
export type { CapturedRequest, WebSocketFrame, CapturedCookie, SessionPaths };
|
|
33
|
-
|
|
34
|
-
export interface SessionExport {
|
|
35
|
-
url: string;
|
|
36
|
-
requests: CapturedRequest[];
|
|
37
|
-
ws: WebSocketFrame[];
|
|
38
|
-
cookies: CapturedCookie[];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface ExposedFunctionCall {
|
|
42
|
-
name: string;
|
|
43
|
-
callId: string;
|
|
44
|
-
data: string;
|
|
45
|
-
tabId: string;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// ─── ExportClient ─────────────────────────────────────────────────────────────
|
|
49
|
-
export class ExportClient {
|
|
50
|
-
constructor(private client: PiggyClient) {}
|
|
51
|
-
|
|
52
|
-
// DOM fetch
|
|
53
|
-
searchCss(query: string, tabId = "default"): Promise<any> {
|
|
54
|
-
return this.client.send("search.css", { query, tabId });
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
searchId(query: string, tabId = "default"): Promise<any> {
|
|
58
|
-
return this.client.send("search.id", { query, tabId });
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Cookies
|
|
62
|
-
setCookie(opts: CookieSetOptions, tabId = "default"): Promise<void> {
|
|
63
|
-
return this.client.send("cookie.set", { ...opts, tabId });
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
deleteCookie(opts: CookieDeleteOptions, tabId = "default"): Promise<void> {
|
|
67
|
-
return this.client.send("cookie.delete", { ...opts, tabId });
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Session
|
|
71
|
-
sessionReload(tabId = "default"): Promise<void> {
|
|
72
|
-
return this.client.send("session.reload", { tabId });
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
cookiesPath(): Promise<string> {
|
|
76
|
-
return this.client.send("session.cookies.path", {});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
profilePath(): Promise<string> {
|
|
80
|
-
return this.client.send("session.profile.path", {});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
wsPath(): Promise<string> {
|
|
84
|
-
return this.client.send("session.ws.path", {});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
pingsPath(): Promise<string> {
|
|
88
|
-
return this.client.send("session.pings.path", {});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
sessionPaths(): Promise<SessionPaths> {
|
|
92
|
-
return this.client.send("session.paths", {});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
setWsSave(enabled: boolean): Promise<void> {
|
|
96
|
-
return this.client.send("session.ws.save", { enabled });
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
setPingsSave(enabled: boolean): Promise<void> {
|
|
100
|
-
return this.client.send("session.pings.save", { enabled });
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Intercept rules
|
|
104
|
-
addInterceptRule(rule: InterceptRule, tabId = "default"): Promise<void> {
|
|
105
|
-
return this.client.send("intercept.rule.add", { ...rule, tabId });
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
clearInterceptRules(tabId = "default"): Promise<void> {
|
|
109
|
-
return this.client.send("intercept.rule.clear", { tabId });
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Session export / import
|
|
113
|
-
async exportSession(tabId = "default"): Promise<SessionExport> {
|
|
114
|
-
const raw = await this.client.send<string>("session.export", { tabId });
|
|
115
|
-
return typeof raw === "string" ? JSON.parse(raw) : raw;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
importSession(data: SessionExport, tabId = "default"): Promise<void> {
|
|
119
|
-
return this.client.send("session.import", {
|
|
120
|
-
data: JSON.stringify(data),
|
|
121
|
-
tabId,
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Exposed functions
|
|
126
|
-
exposeFunction(name: string, tabId = "default"): Promise<void> {
|
|
127
|
-
return this.client.send("expose.function", { name, tabId });
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
resolveExposed(callId: string, result: string, isError = false, tabId = "default"): Promise<void> {
|
|
131
|
-
return this.client.send("exposed.result", { callId, result, isError, tabId });
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Init scripts
|
|
135
|
-
addInitScript(js: string, tabId = "default"): Promise<void> {
|
|
136
|
-
return this.client.send("addInitScript", { js, tabId });
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Events
|
|
140
|
-
onExposedFunctionCalled(tabId: string, handler: (call: ExposedFunctionCall) => void): () => void {
|
|
141
|
-
return this.client.onEvent("exposed_call", tabId, handler);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export function createExportAPI(client: PiggyClient): ExportClient {
|
|
146
|
-
return new ExportClient(client);
|
|
147
|
-
}
|
package/piggy/expose/index.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { PiggyClient } from "../client";
|
|
2
|
-
import logger from "../logger";
|
|
3
|
-
|
|
4
|
-
export async function exposeFunction(
|
|
5
|
-
client: PiggyClient,
|
|
6
|
-
fnName: string,
|
|
7
|
-
handler: (data: any) => Promise<any> | any,
|
|
8
|
-
tabId: string
|
|
9
|
-
): Promise<void> {
|
|
10
|
-
await client.exposeFunction(fnName, handler, tabId);
|
|
11
|
-
logger.success(`[${tabId}] exposed function: ${fnName}`);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function unexposeFunction(
|
|
15
|
-
client: PiggyClient,
|
|
16
|
-
fnName: string,
|
|
17
|
-
tabId: string
|
|
18
|
-
): Promise<void> {
|
|
19
|
-
await client.unexposeFunction(fnName, tabId);
|
|
20
|
-
logger.info(`[${tabId}] unexposed function: ${fnName}`);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function clearExposedFunctions(
|
|
24
|
-
client: PiggyClient,
|
|
25
|
-
tabId: string
|
|
26
|
-
): Promise<void> {
|
|
27
|
-
await client.clearExposedFunctions(tabId);
|
|
28
|
-
logger.info(`[${tabId}] cleared all exposed functions`);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export async function exposeAndInject(
|
|
32
|
-
client: PiggyClient,
|
|
33
|
-
fnName: string,
|
|
34
|
-
handler: (data: any) => Promise<any> | any,
|
|
35
|
-
injectionJs: string | ((fnName: string) => string),
|
|
36
|
-
tabId: string
|
|
37
|
-
): Promise<void> {
|
|
38
|
-
await client.exposeFunction(fnName, handler, tabId);
|
|
39
|
-
const js = typeof injectionJs === "function" ? injectionJs(fnName) : injectionJs;
|
|
40
|
-
await client.evaluate(js, tabId);
|
|
41
|
-
logger.success(`[${tabId}] exposed and injected: ${fnName}`);
|
|
42
|
-
}
|
package/piggy/iframe/index.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
// piggy/iframe/index.ts
|
|
2
|
-
import { PiggyClient } from "../client";
|
|
3
|
-
|
|
4
|
-
// ─── Descriptor types ─────────────────────────────────────────────────────────
|
|
5
|
-
|
|
6
|
-
export interface IframeDescriptor {
|
|
7
|
-
index: number;
|
|
8
|
-
src: string;
|
|
9
|
-
id: string;
|
|
10
|
-
name: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// ─── Option types ─────────────────────────────────────────────────────────────
|
|
14
|
-
|
|
15
|
-
/** Target an iframe by its index or src. One must be provided. */
|
|
16
|
-
export type IframeTarget =
|
|
17
|
-
| { index: number; src?: never }
|
|
18
|
-
| { src: string; index?: never };
|
|
19
|
-
|
|
20
|
-
export type IframeEvaluateOptions = IframeTarget & { js: string };
|
|
21
|
-
export type IframeClickOptions = IframeTarget & { sel: string };
|
|
22
|
-
export type IframeTypeOptions = IframeTarget & { sel: string; text: string };
|
|
23
|
-
export type IframeTextOptions = IframeTarget & { sel: string };
|
|
24
|
-
export type IframeHtmlOptions = IframeTarget;
|
|
25
|
-
export type IframeWaitSelOptions = IframeTarget & { sel: string; timeout?: number };
|
|
26
|
-
|
|
27
|
-
// ─── IframeClient ─────────────────────────────────────────────────────────────
|
|
28
|
-
|
|
29
|
-
export class IframeClient {
|
|
30
|
-
constructor(private client: PiggyClient) {}
|
|
31
|
-
|
|
32
|
-
/** List all iframes on the page: index, src, id, name. */
|
|
33
|
-
list(tabId = "default"): Promise<IframeDescriptor[]> {
|
|
34
|
-
return this.client.send("iframe.list", { tabId });
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** Run arbitrary JS inside the targeted iframe. Returns whatever the script returns. */
|
|
38
|
-
evaluate(opts: IframeEvaluateOptions, tabId = "default"): Promise<unknown> {
|
|
39
|
-
return this.client.send("iframe.evaluate", { ...opts, tabId });
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** Click a selector inside the targeted iframe. */
|
|
43
|
-
click(opts: IframeClickOptions, tabId = "default"): Promise<boolean> {
|
|
44
|
-
return this.client.send("iframe.click", { ...opts, tabId });
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** Type text into a selector inside the targeted iframe. */
|
|
48
|
-
type(opts: IframeTypeOptions, tabId = "default"): Promise<boolean> {
|
|
49
|
-
return this.client.send("iframe.type", { ...opts, tabId });
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** Get innerText of a selector inside the targeted iframe. */
|
|
53
|
-
text(opts: IframeTextOptions, tabId = "default"): Promise<string> {
|
|
54
|
-
return this.client.send("iframe.text", { ...opts, tabId });
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** Get the full HTML of the targeted iframe. */
|
|
58
|
-
html(opts: IframeHtmlOptions, tabId = "default"): Promise<string> {
|
|
59
|
-
return this.client.send("iframe.html", { ...opts, tabId });
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** Wait until a selector appears inside the targeted iframe. */
|
|
63
|
-
waitSel(opts: IframeWaitSelOptions, tabId = "default"): Promise<boolean> {
|
|
64
|
-
return this.client.send("iframe.waitSel", { ...opts, tabId });
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// ─── Factory helper ───────────────────────────────────────────────────────────
|
|
69
|
-
|
|
70
|
-
export function createIframeAPI(client: PiggyClient): IframeClient {
|
|
71
|
-
return new IframeClient(client);
|
|
72
|
-
}
|
|
73
|
-
// Done. One thing worth noting — `IframeTarget` is a discriminated union so TypeScript enforces you pass either `index` or `src`, never both. Usage looks like:
|
|
74
|
-
|
|
75
|
-
// ```js
|
|
76
|
-
// piggy.google.iframe.list()
|
|
77
|
-
// piggy.google.iframe.click({ index: 0, sel: "#btn" })
|
|
78
|
-
// piggy.google.iframe.evaluate({ src: "https://...", js: "document.title" })
|
|
79
|
-
// ```
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates a script that short-circuits matching fetch/XHR requests
|
|
3
|
-
* and returns a static fake response — the request never hits the network.
|
|
4
|
-
*/
|
|
5
|
-
export declare function buildRespondScript(pattern: string, status: number, contentType: string, body: string): string;
|
|
6
|
-
/**
|
|
7
|
-
* Generates a script that lets the request hit the network, then calls
|
|
8
|
-
* an exposed function with { body, status, headers }.
|
|
9
|
-
* The exposed function returns { body?, status?, headers? } modifications
|
|
10
|
-
* or an empty object {} to pass through unchanged.
|
|
11
|
-
*/
|
|
12
|
-
export declare function buildModifyResponseScript(pattern: string, exposedFnName: string): string;
|
|
13
|
-
//# sourceMappingURL=scripts.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scripts.d.ts","sourceRoot":"","sources":["scripts.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,GACX,MAAM,CAyER;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CA0DxF"}
|
package/piggy/launch/detect.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["detect.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,SAAS,CAAC;AAOhD,wBAAgB,YAAY,CAAC,IAAI,GAAE,UAAuB,GAAG,MAAM,GAAG,IAAI,CA+BzE"}
|
package/piggy/launch/spawn.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type BinaryMode } from "./detect";
|
|
2
|
-
export declare function killAllBrowsers(): void;
|
|
3
|
-
export declare function spawnBrowser(mode?: BinaryMode): Promise<string>;
|
|
4
|
-
export declare function spawnBrowserOnSocket(socketName: string, mode?: BinaryMode): Promise<void>;
|
|
5
|
-
export declare function killBrowser(): void;
|
|
6
|
-
//# sourceMappingURL=spawn.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["spawn.ts"],"names":[],"mappings":"AAIA,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AASzD,wBAAgB,eAAe,IAAI,IAAI,CAiBtC;AAED,wBAAsB,YAAY,CAAC,IAAI,GAAE,UAAuB,GAAG,OAAO,CAAC,MAAM,CAAC,CAqEjF;AAED,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,MAAM,EAClB,IAAI,GAAE,UAAuB,GAC5B,OAAO,CAAC,IAAI,CAAC,CAqCf;AAED,wBAAgB,WAAW,IAAI,IAAI,CAmBlC"}
|
package/piggy/logger/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,MAAM,gCAiDV,CAAC;AAKH,eAAe,MAAM,CAAC"}
|
package/piggy/pool/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// piggy/pool/index.d.ts
|
|
2
|
-
import { PiggyClient } from "../client";
|
|
3
|
-
|
|
4
|
-
export declare class TabPool {
|
|
5
|
-
constructor(client: PiggyClient, size: number, seedUrl: string, name: string);
|
|
6
|
-
init(): Promise<void>;
|
|
7
|
-
acquire(): Promise<string>;
|
|
8
|
-
release(tabId: string): void;
|
|
9
|
-
withTab<T>(fn: (tabId: string) => Promise<T>): Promise<T>;
|
|
10
|
-
close(): Promise<void>;
|
|
11
|
-
get stats(): { idle: number; busy: number; queued: number; total: number };
|
|
12
|
-
}
|
package/piggy/pool/index.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
// piggy/pool/index.ts
|
|
2
|
-
import { PiggyClient } from "../client";
|
|
3
|
-
import logger from "../logger";
|
|
4
|
-
|
|
5
|
-
export class TabPool {
|
|
6
|
-
private idle: string[] = [];
|
|
7
|
-
private busy = new Set<string>();
|
|
8
|
-
private queue: ((tabId: string) => void)[] = [];
|
|
9
|
-
|
|
10
|
-
constructor(
|
|
11
|
-
private client: PiggyClient,
|
|
12
|
-
private size: number,
|
|
13
|
-
private seedUrl: string,
|
|
14
|
-
private name: string
|
|
15
|
-
) {}
|
|
16
|
-
|
|
17
|
-
async init() {
|
|
18
|
-
for (let i = 0; i < this.size; i++) {
|
|
19
|
-
const tabId = await this.client.newTab();
|
|
20
|
-
await this.client.navigate(this.seedUrl, tabId);
|
|
21
|
-
this.idle.push(tabId);
|
|
22
|
-
logger.success(`[${this.name}] pool tab ${i + 1}/${this.size} ready: ${tabId}`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
acquire(): Promise<string> {
|
|
27
|
-
return new Promise(resolve => {
|
|
28
|
-
const tabId = this.idle.pop();
|
|
29
|
-
if (tabId) {
|
|
30
|
-
this.busy.add(tabId);
|
|
31
|
-
resolve(tabId);
|
|
32
|
-
} else {
|
|
33
|
-
this.queue.push(resolve);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
release(tabId: string) {
|
|
39
|
-
this.busy.delete(tabId);
|
|
40
|
-
const next = this.queue.shift();
|
|
41
|
-
if (next) {
|
|
42
|
-
this.busy.add(tabId);
|
|
43
|
-
next(tabId);
|
|
44
|
-
} else {
|
|
45
|
-
this.idle.push(tabId);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async withTab<T>(fn: (tabId: string) => Promise<T>): Promise<T> {
|
|
50
|
-
const tabId = await this.acquire();
|
|
51
|
-
try {
|
|
52
|
-
return await fn(tabId);
|
|
53
|
-
} finally {
|
|
54
|
-
this.release(tabId);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async close() {
|
|
59
|
-
for (const tabId of [...this.idle, ...this.busy]) {
|
|
60
|
-
try { await this.client.closeTab(tabId); } catch {}
|
|
61
|
-
}
|
|
62
|
-
this.idle = [];
|
|
63
|
-
this.busy.clear();
|
|
64
|
-
this.queue = [];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
get stats() {
|
|
68
|
-
return {
|
|
69
|
-
idle: this.idle.length,
|
|
70
|
-
busy: this.busy.size,
|
|
71
|
-
queued: this.queue.length,
|
|
72
|
-
total: this.size,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
}
|