Skip to content

Commit bc55e2b

Browse files
changes
1 parent 1b1ccb3 commit bc55e2b

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codebolt/codeboltjs",
3-
"version": "1.1.32",
3+
"version": "1.1.33",
44
"description": "",
55
"keywords": [],
66
"author": "",

src/modules/browser.ts

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import cbws from './websocket';
2-
import {GoToPageResponse,UrlResponse,GetMarkdownResponse,HtmlReceived} from '@codebolt/types'
2+
import {GoToPageResponse,UrlResponse,GetMarkdownResponse,HtmlReceived,ExtractTextResponse,GetContentResponse} from '@codebolt/types'
33
/**
44
* A module for interacting with a browser through WebSockets.
55
*/
@@ -105,6 +105,7 @@ const cbbrowser = {
105105

106106
/**
107107
* Retrieves the PDF content of the current page.
108+
*
108109
*/
109110
getPDF: () => {
110111
cbws.getWebsocket.send(JSON.stringify({
@@ -125,22 +126,43 @@ const cbbrowser = {
125126

126127
/**
127128
* Retrieves the content of the current page.
129+
* @returns {Promise<GetContentResponse>} A promise that resolves with the content.
128130
*/
129-
getContent: () => {
130-
cbws.getWebsocket.send(JSON.stringify({
131-
"type": "browserEvent",
132-
action: 'getContent'
133-
}));
131+
getContent: ():Promise<GetContentResponse> => {
132+
133+
return new Promise((resolve, reject) => {
134+
cbws.getWebsocket.send(JSON.stringify({
135+
"type": "browserEvent",
136+
action: 'getContent'
137+
}));
138+
cbws.getWebsocket.on('message', (data: string) => {
139+
const response = JSON.parse(data);
140+
if (response.event === "getContentResponse") {
141+
resolve(response);
142+
}
143+
});
144+
});
134145
},
135146

136147
/**
137148
* Extracts text from the current page.
149+
* @returns {Promise<ExtractTextResponse>} A promise that resolves with the extracted text.
150+
*
138151
*/
139-
extractText: () => {
140-
cbws.getWebsocket.send(JSON.stringify({
141-
"type": "browserEvent",
142-
action: 'extractText'
143-
}));
152+
extractText: ():Promise<ExtractTextResponse> => {
153+
154+
return new Promise((resolve, reject) => {
155+
cbws.getWebsocket.send(JSON.stringify({
156+
"type": "browserEvent",
157+
action: 'extractText'
158+
}));
159+
cbws.getWebsocket.on('message', (data: string) => {
160+
const response = JSON.parse(data);
161+
if (response.event === "extractTextResponse") {
162+
resolve(response);
163+
}
164+
});
165+
});
144166
},
145167

146168
/**

0 commit comments

Comments
 (0)