feat: subscribe to screencast on CDP

This commit is contained in:
karishmas6
2024-06-01 10:58:23 +05:30
parent 15700fab0c
commit c42919e374

View File

@@ -128,4 +128,33 @@ export class RemoteBrowser {
}
});
}
/**
* Subscribes the remote browser for a screencast session
* on [CDP](https://chromedevtools.github.io/devtools-protocol/) level,
* where screenshot is being sent through the socket
* every time the browser's active page updates.
* @returns {Promise<void>}
*/
public subscribeToScreencast = async() : Promise<void> => {
await this.startScreencast();
if (!this.client) {
logger.log('warn','client is not initialized');
return;
}
this.client.on('Page.screencastFrame', ({ data: base64, sessionId }) => {
this.emitScreenshot(base64);
setTimeout(async () => {
try {
if (!this.client) {
logger.log('warn','client is not initialized');
return;
}
await this.client.send('Page.screencastFrameAck', { sessionId: sessionId });
} catch (e) {
logger.log('error', e);
}
}, 100);
});
};
}