Spaces:
Running
Running
import { Page } from "playwright/test"; | |
export async function extractAndCleanCode(page: Page): Promise<string> { | |
const outerHTML = await page | |
.locator('//*[@id="codeValue"]') | |
.evaluate((el) => el.outerHTML); | |
const valueMatch = outerHTML.match(/value="([\s\S]*?)"/); | |
if (!valueMatch) { | |
throw new Error("Could not find value attribute in the HTML"); | |
} | |
let codeContent = valueMatch[1] | |
.replace(/"/g, '"') | |
.replace(/&/g, "&") | |
.replace(/</g, "<") | |
.replace(/>/g, ">") | |
.replace(/'/g, "'") | |
.replace(///g, "/"); | |
return codeContent; | |
} | |