MCPcopy Create free account
hub / github.com/caffeinum/vibeOS / createBrowserInstance

Function createBrowserInstance

scripts/start-browser.js:153–206  ·  view source on GitHub ↗
(instanceId)

Source from the content-addressed store, hash-verified

151
152// Create browser instance
153async function createBrowserInstance(instanceId) {
154 try {
155 const client = await CDP({
156 host: '127.0.0.1',
157 port: 9222
158 });
159
160 // Enable required domains
161 await client.Runtime.enable();
162 await client.Page.enable();
163 await client.Network.enable();
164 await client.Input.enable();
165
166 // Navigate to blank page initially
167 await client.Page.navigate({ url: 'about:blank' });
168
169 const instance = {
170 id: instanceId,
171 client,
172 connectedClients: new Set()
173 };
174
175 browserInstances.set(instanceId, instance);
176
177 // Set up screenshot streaming
178 const screenshotInterval = setInterval(async () => {
179 try {
180 const { data } = await client.Page.captureScreenshot({
181 format: 'jpeg',
182 quality: 80
183 });
184
185 // Send screenshot to all connected clients
186 instance.connectedClients.forEach(ws => {
187 if (ws.readyState === 1) { // OPEN
188 ws.send(JSON.stringify({
189 type: 'screenshot',
190 data: data,
191 timestamp: Date.now()
192 }));
193 }
194 });
195 } catch (error) {
196 console.error('Screenshot error:', error);
197 clearInterval(screenshotInterval);
198 }
199 }, 100); // 10 FPS
200
201 return instance;
202 } catch (error) {
203 console.error('Failed to create browser instance:', error);
204 throw error;
205 }
206}
207
208// Initialize Chrome when module loads
209let chromeProcess = null;

Callers 1

start-browser.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected