browser-functions-mock.ts•2.32 kB
// Placeholder browser functions - actual implementation requires CDP from main extension
async function getCDPClient(): Promise<any> {
return {
isHealthy: true,
isActive: true,
connect: async () => {},
navigate: async () => {},
execute: async () => ({ result: null }),
getPageInfo: async () => ({}),
getConsoleMessages: () => [],
clearConsoleMessages: () => {},
getDOMSnapshot: async () => ({}),
click: async () => {},
type: async () => {},
screenshot: async () => ({ data: '' }),
waitForSelector: async () => {},
}
}
function _resetCDPClient(): void {}
const _logger = {
info: console.error,
error: console.error,
warn: console.warn,
}
export async function ensureCDPConnection() {
return getCDPClient()
}
export async function executeInBrowser(expression: string, url?: string) {
const client = await getCDPClient()
if (url) {
await client.navigate(url)
}
const result = await client.execute(expression)
return JSON.stringify(result)
}
export async function getBrowserConsole(filter?: string, clear?: boolean) {
const client = await getCDPClient()
const messages = client.getConsoleMessages()
if (clear) {
client.clearConsoleMessages()
}
return JSON.stringify({ messages })
}
export async function navigateBrowser(url: string) {
const client = await getCDPClient()
await client.navigate(url)
return JSON.stringify({ success: true })
}
export async function getDOMSnapshot() {
const client = await getCDPClient()
const snapshot = await client.getDOMSnapshot()
return JSON.stringify(snapshot)
}
export async function clickElement(selector: string) {
const client = await getCDPClient()
await client.click(selector)
return JSON.stringify({ success: true })
}
export async function typeInBrowser(selector: string, text: string) {
const client = await getCDPClient()
await client.type(selector, text)
return JSON.stringify({ success: true })
}
export async function takeScreenshot() {
const client = await getCDPClient()
const result = await client.screenshot()
return result.data
}
export async function waitForElement(selector: string, timeout?: number) {
const client = await getCDPClient()
await client.waitForSelector(selector, timeout)
return JSON.stringify({ success: true })
}