11import cbws from '../core/websocket' ;
2- import { GoToPageResponse , UrlResponse , GetMarkdownResponse , HtmlReceived , ExtractTextResponse , GetContentResponse } from '@codebolt /types'
2+ import { GoToPageResponse , UrlResponse , GetMarkdownResponse , HtmlReceived , ExtractTextResponse , GetContentResponse , BrowserActionResponseData , BrowserScreenshotResponse , BrowserInfoResponse , BrowserSnapshotResponse } from '.. /types/cliWebSocketInterfaces' ;
33/**
44 * A module for interacting with a browser through WebSockets.
55 */
@@ -8,7 +8,7 @@ const cbbrowser = {
88 /**
99 * Opens a new page in the browser.
1010 */
11- newPage : ( ) => {
11+ newPage : ( ) : Promise < BrowserActionResponseData > => {
1212
1313 return cbws . messageManager . sendAndWaitForResponse (
1414 {
@@ -23,7 +23,7 @@ const cbbrowser = {
2323 * Retrieves the current URL of the browser's active page.
2424 * @returns {Promise<UrlResponse> } A promise that resolves with the URL.
2525 */
26- getUrl : ( ) :Promise < UrlResponse > => {
26+ getUrl : ( ) : Promise < UrlResponse > => {
2727 return cbws . messageManager . sendAndWaitForResponse (
2828 {
2929 "type" : "browserEvent" ,
@@ -38,7 +38,7 @@ const cbbrowser = {
3838 * @param {string } url - The URL to navigate to.
3939 * @returns {Promise<GoToPageResponse> } A promise that resolves when navigation is complete.
4040 */
41- goToPage : ( url : string ) :Promise < GoToPageResponse > => {
41+ goToPage : ( url : string ) : Promise < GoToPageResponse > => {
4242 return cbws . messageManager . sendAndWaitForResponse (
4343 {
4444 "type" : "browserEvent" ,
@@ -52,7 +52,7 @@ const cbbrowser = {
5252 /**
5353 * Takes a screenshot of the current page.
5454 */
55- screenshot : ( ) => {
55+ screenshot : ( ) : Promise < BrowserScreenshotResponse > => {
5656 return cbws . messageManager . sendAndWaitForResponse (
5757 {
5858 "type" : "browserEvent" ,
@@ -66,7 +66,7 @@ const cbbrowser = {
6666 * Retrieves the HTML content of the current page.
6767 * @returns {Promise<HtmlReceived> } A promise that resolves with the HTML content.
6868 */
69- getHTML : ( ) :Promise < HtmlReceived > => {
69+ getHTML : ( ) : Promise < HtmlReceived > => {
7070 return cbws . messageManager . sendAndWaitForResponse (
7171 {
7272 "type" : "browserEvent" ,
@@ -80,7 +80,7 @@ const cbbrowser = {
8080 * Retrieves the Markdown content of the current page.
8181 * @returns {Promise<GetMarkdownResponse> } A promise that resolves with the Markdown content.
8282 */
83- getMarkdown : ( ) :Promise < GetMarkdownResponse > => {
83+ getMarkdown : ( ) : Promise < GetMarkdownResponse > => {
8484 return cbws . messageManager . sendAndWaitForResponse (
8585 {
8686 "type" : "browserEvent" ,
@@ -94,7 +94,7 @@ const cbbrowser = {
9494 * Retrieves the PDF content of the current page.
9595 *
9696 */
97- getPDF : ( ) => {
97+ getPDF : ( ) : void => {
9898 cbws . messageManager . send ( {
9999 "type" : "browserEvent" ,
100100 action : 'getPDF'
@@ -104,7 +104,7 @@ const cbbrowser = {
104104 /**
105105 * Converts the PDF content of the current page to text.
106106 */
107- pdfToText : ( ) => {
107+ pdfToText : ( ) : void => {
108108 cbws . messageManager . send ( {
109109 "type" : "browserEvent" ,
110110 action : 'pdfToText'
@@ -115,7 +115,7 @@ const cbbrowser = {
115115 * Retrieves the content of the current page.
116116 * @returns {Promise<GetContentResponse> } A promise that resolves with the content.
117117 */
118- getContent : ( ) :Promise < GetContentResponse > => {
118+ getContent : ( ) : Promise < GetContentResponse > => {
119119
120120 return cbws . messageManager . sendAndWaitForResponse (
121121 {
@@ -127,9 +127,9 @@ const cbbrowser = {
127127 } ,
128128 /**
129129 * Retrieves the snapshot of the current page.
130- * @returns {Promise<GetContentResponse > } A promise that resolves with the content .
130+ * @returns {Promise<BrowserSnapshotResponse > } A promise that resolves with the snapshot .
131131 */
132- getSnapShot : ( ) :Promise < any > => {
132+ getSnapShot : ( ) : Promise < BrowserSnapshotResponse > => {
133133
134134 return cbws . messageManager . sendAndWaitForResponse (
135135 {
@@ -141,9 +141,9 @@ const cbbrowser = {
141141 } ,
142142 /**
143143 * Retrieves browser info like height width scrollx scrolly of the current page.
144- * @returns {Promise<GetContentResponse > } A promise that resolves with the content .
144+ * @returns {Promise<BrowserInfoResponse > } A promise that resolves with the browser info .
145145 */
146- getBrowserInfo : ( ) :Promise < any > => {
146+ getBrowserInfo : ( ) : Promise < BrowserInfoResponse > => {
147147
148148 return cbws . messageManager . sendAndWaitForResponse (
149149 {
@@ -159,7 +159,7 @@ const cbbrowser = {
159159 * @returns {Promise<ExtractTextResponse> } A promise that resolves with the extracted text.
160160 *
161161 */
162- extractText : ( ) :Promise < ExtractTextResponse > => {
162+ extractText : ( ) : Promise < ExtractTextResponse > => {
163163
164164 return cbws . messageManager . sendAndWaitForResponse (
165165 {
@@ -173,7 +173,7 @@ const cbbrowser = {
173173 /**
174174 * Closes the current page.
175175 */
176- close : ( ) => {
176+ close : ( ) : void => {
177177 cbws . messageManager . send ( {
178178 "type" : "browserEvent" ,
179179 action : 'close'
@@ -184,9 +184,9 @@ const cbbrowser = {
184184 * Scrolls the current page in a specified direction by a specified number of pixels.
185185 * @param {string } direction - The direction to scroll.
186186 * @param {string } pixels - The number of pixels to scroll.
187- * @returns {Promise<any > } A promise that resolves when the scroll action is complete.
187+ * @returns {Promise<BrowserActionResponseData > } A promise that resolves when the scroll action is complete.
188188 */
189- scroll : ( direction : string , pixels : string ) => {
189+ scroll : ( direction : string , pixels : string ) : Promise < BrowserActionResponseData > => {
190190 return cbws . messageManager . sendAndWaitForResponse (
191191 {
192192 "type" : "browserEvent" ,
@@ -202,9 +202,9 @@ const cbbrowser = {
202202 * Types text into a specified element on the page.
203203 * @param {string } elementid - The ID of the element to type into.
204204 * @param {string } text - The text to type.
205- * @returns {Promise<any > } A promise that resolves when the typing action is complete.
205+ * @returns {Promise<BrowserActionResponseData > } A promise that resolves when the typing action is complete.
206206 */
207- type : ( elementid : string , text : string ) => {
207+ type : ( elementid : string , text : string ) : Promise < BrowserActionResponseData > => {
208208 return cbws . messageManager . sendAndWaitForResponse (
209209 {
210210 "type" : "browserEvent" ,
@@ -219,9 +219,9 @@ const cbbrowser = {
219219 /**
220220 * Clicks on a specified element on the page.
221221 * @param {string } elementid - The ID of the element to click.
222- * @returns {Promise<any > } A promise that resolves when the click action is complete.
222+ * @returns {Promise<BrowserActionResponseData > } A promise that resolves when the click action is complete.
223223 */
224- click : ( elementid : string ) => {
224+ click : ( elementid : string ) : Promise < BrowserActionResponseData > => {
225225 return cbws . messageManager . sendAndWaitForResponse (
226226 {
227227 "type" : "browserEvent" ,
@@ -234,9 +234,9 @@ const cbbrowser = {
234234
235235 /**
236236 * Simulates the Enter key press on the current page.
237- * @returns {Promise<any > } A promise that resolves when the Enter action is complete.
237+ * @returns {Promise<BrowserActionResponseData > } A promise that resolves when the Enter action is complete.
238238 */
239- enter : ( ) => {
239+ enter : ( ) : Promise < BrowserActionResponseData > => {
240240 return cbws . messageManager . sendAndWaitForResponse (
241241 {
242242 "type" : "browserEvent" ,
@@ -250,9 +250,9 @@ const cbbrowser = {
250250 * Performs a search on the current page using a specified query.
251251 * @param {string } elementid - The ID of the element to perform the search in.
252252 * @param {string } query - The search query.
253- * @returns {Promise<any > } A promise that resolves with the search results.
253+ * @returns {Promise<BrowserActionResponseData > } A promise that resolves with the search results.
254254 */
255- search : ( elementid : string , query : string ) => {
255+ search : ( elementid : string , query : string ) : Promise < BrowserActionResponseData > => {
256256 return cbws . messageManager . sendAndWaitForResponse (
257257 {
258258 "type" : "browserEvent" ,
0 commit comments