@codebolt/codeboltjs 1.1.32 → 1.1.34
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/index.d.ts +3 -3
- package/modules/browser.d.ts +8 -4
- package/modules/browser.js +40 -12
- package/package.json +1 -1
- package/src/modules/browser.ts +46 -15
package/index.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ declare class Codebolt {
|
|
|
44
44
|
inference: (message: string, llmrole: string) => Promise<import("@codebolt/types").LLMResponse>;
|
|
45
45
|
};
|
|
46
46
|
browser: {
|
|
47
|
-
newPage: () =>
|
|
47
|
+
newPage: () => Promise<unknown>;
|
|
48
48
|
getUrl: () => Promise<import("@codebolt/types").UrlResponse>;
|
|
49
49
|
goToPage: (url: string) => Promise<import("@codebolt/types").GoToPageResponse>;
|
|
50
50
|
screenshot: () => void;
|
|
@@ -52,8 +52,8 @@ declare class Codebolt {
|
|
|
52
52
|
getMarkdown: () => Promise<import("@codebolt/types").GetMarkdownResponse>;
|
|
53
53
|
getPDF: () => void;
|
|
54
54
|
pdfToText: () => void;
|
|
55
|
-
getContent: () =>
|
|
56
|
-
extractText: () =>
|
|
55
|
+
getContent: () => Promise<import("@codebolt/types").GetContentResponse>;
|
|
56
|
+
extractText: () => Promise<import("@codebolt/types").ExtractTextResponse>;
|
|
57
57
|
close: () => void;
|
|
58
58
|
scroll: (direction: string, pixels: string) => Promise<unknown>;
|
|
59
59
|
type: (elementid: string, text: string) => Promise<unknown>;
|
package/modules/browser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GoToPageResponse, UrlResponse, GetMarkdownResponse, HtmlReceived } from '@codebolt/types';
|
|
1
|
+
import { GoToPageResponse, UrlResponse, GetMarkdownResponse, HtmlReceived, ExtractTextResponse, GetContentResponse } from '@codebolt/types';
|
|
2
2
|
/**
|
|
3
3
|
* A module for interacting with a browser through WebSockets.
|
|
4
4
|
*/
|
|
@@ -6,7 +6,7 @@ declare const cbbrowser: {
|
|
|
6
6
|
/**
|
|
7
7
|
* Opens a new page in the browser.
|
|
8
8
|
*/
|
|
9
|
-
newPage: () =>
|
|
9
|
+
newPage: () => Promise<unknown>;
|
|
10
10
|
/**
|
|
11
11
|
* Retrieves the current URL of the browser's active page.
|
|
12
12
|
* @returns {Promise<UrlResponse>} A promise that resolves with the URL.
|
|
@@ -34,6 +34,7 @@ declare const cbbrowser: {
|
|
|
34
34
|
getMarkdown: () => Promise<GetMarkdownResponse>;
|
|
35
35
|
/**
|
|
36
36
|
* Retrieves the PDF content of the current page.
|
|
37
|
+
*
|
|
37
38
|
*/
|
|
38
39
|
getPDF: () => void;
|
|
39
40
|
/**
|
|
@@ -42,12 +43,15 @@ declare const cbbrowser: {
|
|
|
42
43
|
pdfToText: () => void;
|
|
43
44
|
/**
|
|
44
45
|
* Retrieves the content of the current page.
|
|
46
|
+
* @returns {Promise<GetContentResponse>} A promise that resolves with the content.
|
|
45
47
|
*/
|
|
46
|
-
getContent: () =>
|
|
48
|
+
getContent: () => Promise<GetContentResponse>;
|
|
47
49
|
/**
|
|
48
50
|
* Extracts text from the current page.
|
|
51
|
+
* @returns {Promise<ExtractTextResponse>} A promise that resolves with the extracted text.
|
|
52
|
+
*
|
|
49
53
|
*/
|
|
50
|
-
extractText: () =>
|
|
54
|
+
extractText: () => Promise<ExtractTextResponse>;
|
|
51
55
|
/**
|
|
52
56
|
* Closes the current page.
|
|
53
57
|
*/
|
package/modules/browser.js
CHANGED
|
@@ -12,10 +12,18 @@ const cbbrowser = {
|
|
|
12
12
|
* Opens a new page in the browser.
|
|
13
13
|
*/
|
|
14
14
|
newPage: () => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
17
|
+
"type": "browserEvent",
|
|
18
|
+
action: 'newPage'
|
|
19
|
+
}));
|
|
20
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
21
|
+
const response = JSON.parse(data);
|
|
22
|
+
if (response.event === "newPageResponse") {
|
|
23
|
+
resolve(response);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
19
27
|
},
|
|
20
28
|
/**
|
|
21
29
|
* Retrieves the current URL of the browser's active page.
|
|
@@ -102,6 +110,7 @@ const cbbrowser = {
|
|
|
102
110
|
},
|
|
103
111
|
/**
|
|
104
112
|
* Retrieves the PDF content of the current page.
|
|
113
|
+
*
|
|
105
114
|
*/
|
|
106
115
|
getPDF: () => {
|
|
107
116
|
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
@@ -120,21 +129,40 @@ const cbbrowser = {
|
|
|
120
129
|
},
|
|
121
130
|
/**
|
|
122
131
|
* Retrieves the content of the current page.
|
|
132
|
+
* @returns {Promise<GetContentResponse>} A promise that resolves with the content.
|
|
123
133
|
*/
|
|
124
134
|
getContent: () => {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
135
|
+
return new Promise((resolve, reject) => {
|
|
136
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
137
|
+
"type": "browserEvent",
|
|
138
|
+
action: 'getContent'
|
|
139
|
+
}));
|
|
140
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
141
|
+
const response = JSON.parse(data);
|
|
142
|
+
if (response.event === "getContentResponse") {
|
|
143
|
+
resolve(response);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
});
|
|
129
147
|
},
|
|
130
148
|
/**
|
|
131
149
|
* Extracts text from the current page.
|
|
150
|
+
* @returns {Promise<ExtractTextResponse>} A promise that resolves with the extracted text.
|
|
151
|
+
*
|
|
132
152
|
*/
|
|
133
153
|
extractText: () => {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
154
|
+
return new Promise((resolve, reject) => {
|
|
155
|
+
websocket_1.default.getWebsocket.send(JSON.stringify({
|
|
156
|
+
"type": "browserEvent",
|
|
157
|
+
action: 'extractText'
|
|
158
|
+
}));
|
|
159
|
+
websocket_1.default.getWebsocket.on('message', (data) => {
|
|
160
|
+
const response = JSON.parse(data);
|
|
161
|
+
if (response.event === "extractTextResponse") {
|
|
162
|
+
resolve(response);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
});
|
|
138
166
|
},
|
|
139
167
|
/**
|
|
140
168
|
* Closes the current page.
|
package/package.json
CHANGED
package/src/modules/browser.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import cbws from './websocket';
|
|
2
|
-
import {GoToPageResponse,UrlResponse,GetMarkdownResponse,HtmlReceived} from '@codebolt/types'
|
|
2
|
+
import {GoToPageResponse,UrlResponse,GetMarkdownResponse,HtmlReceived,ExtractTextResponse,GetContentResponse} from '@codebolt/types'
|
|
3
3
|
/**
|
|
4
4
|
* A module for interacting with a browser through WebSockets.
|
|
5
5
|
*/
|
|
@@ -9,10 +9,19 @@ const cbbrowser = {
|
|
|
9
9
|
* Opens a new page in the browser.
|
|
10
10
|
*/
|
|
11
11
|
newPage: () => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
15
|
+
"type": "browserEvent",
|
|
16
|
+
action: 'newPage'
|
|
17
|
+
}));
|
|
18
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
19
|
+
const response = JSON.parse(data);
|
|
20
|
+
if (response.event === "newPageResponse") {
|
|
21
|
+
resolve(response);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
});
|
|
16
25
|
},
|
|
17
26
|
|
|
18
27
|
/**
|
|
@@ -105,6 +114,7 @@ const cbbrowser = {
|
|
|
105
114
|
|
|
106
115
|
/**
|
|
107
116
|
* Retrieves the PDF content of the current page.
|
|
117
|
+
*
|
|
108
118
|
*/
|
|
109
119
|
getPDF: () => {
|
|
110
120
|
cbws.getWebsocket.send(JSON.stringify({
|
|
@@ -125,22 +135,43 @@ const cbbrowser = {
|
|
|
125
135
|
|
|
126
136
|
/**
|
|
127
137
|
* Retrieves the content of the current page.
|
|
138
|
+
* @returns {Promise<GetContentResponse>} A promise that resolves with the content.
|
|
128
139
|
*/
|
|
129
|
-
getContent: () => {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
140
|
+
getContent: ():Promise<GetContentResponse> => {
|
|
141
|
+
|
|
142
|
+
return new Promise((resolve, reject) => {
|
|
143
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
144
|
+
"type": "browserEvent",
|
|
145
|
+
action: 'getContent'
|
|
146
|
+
}));
|
|
147
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
148
|
+
const response = JSON.parse(data);
|
|
149
|
+
if (response.event === "getContentResponse") {
|
|
150
|
+
resolve(response);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
134
154
|
},
|
|
135
155
|
|
|
136
156
|
/**
|
|
137
157
|
* Extracts text from the current page.
|
|
158
|
+
* @returns {Promise<ExtractTextResponse>} A promise that resolves with the extracted text.
|
|
159
|
+
*
|
|
138
160
|
*/
|
|
139
|
-
extractText: () => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
161
|
+
extractText: ():Promise<ExtractTextResponse> => {
|
|
162
|
+
|
|
163
|
+
return new Promise((resolve, reject) => {
|
|
164
|
+
cbws.getWebsocket.send(JSON.stringify({
|
|
165
|
+
"type": "browserEvent",
|
|
166
|
+
action: 'extractText'
|
|
167
|
+
}));
|
|
168
|
+
cbws.getWebsocket.on('message', (data: string) => {
|
|
169
|
+
const response = JSON.parse(data);
|
|
170
|
+
if (response.event === "extractTextResponse") {
|
|
171
|
+
resolve(response);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
});
|
|
144
175
|
},
|
|
145
176
|
|
|
146
177
|
/**
|