nothing-browser 0.0.16 → 0.0.17
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/dist/piggy/pool/index.d.ts +23 -0
- package/dist/piggy/pool/index.d.ts.map +1 -0
- package/dist/piggy/register/index.d.ts +3 -1
- package/dist/piggy/register/index.d.ts.map +1 -1
- package/dist/piggy/server/index.d.ts +22 -1
- package/dist/piggy/server/index.d.ts.map +1 -1
- package/dist/piggy/store/index.d.ts +22 -0
- package/dist/piggy/store/index.d.ts.map +1 -0
- package/dist/piggy.d.ts +6 -174
- package/dist/piggy.d.ts.map +1 -1
- package/dist/piggy.js +7391 -205
- package/dist/register/index.js +6291 -205
- package/dist/server/index.js +6252 -79
- package/package.json +3 -1
- package/piggy/pool/index.d.ts +12 -0
- package/piggy/pool/index.ts +75 -0
- package/piggy/register/index.ts +231 -214
- package/piggy/server/index.d.ts +51 -14
- package/piggy/server/index.ts +68 -15
- package/piggy/store/index.d.ts +26 -0
- package/piggy/store/index.ts +230 -0
- package/piggy.ts +95 -316
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nothing-browser",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "Browser automation library powered by Nothing Browser",
|
|
5
5
|
"homepage": "https://github.com/ernest-tech-house-co-operation/nothing-browser#readme",
|
|
6
6
|
"repository": {
|
|
@@ -49,6 +49,8 @@
|
|
|
49
49
|
"prepublishOnly": "bun run build"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
+
"@elysiajs/openapi": "^1.4.15",
|
|
53
|
+
"better-sqlite3": "^12.9.0",
|
|
52
54
|
"elysia": "^1.0.0"
|
|
53
55
|
},
|
|
54
56
|
"peerDependencies": {
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
}
|