Skip to content

Commit 3e626f4

Browse files
authored
Merge pull request #1564 from voidking/main
bugfix: #1547 Make sure the SVG element exists before calling serializeToString
2 parents b5bb4d7 + 0443865 commit 3e626f4

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

metagpt/utils/mmdc_playwright.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,13 @@ async def console_message(msg):
8181
if "svg" in suffixes:
8282
svg_xml = await page.evaluate(
8383
"""() => {
84-
const svg = document.querySelector('svg');
85-
const xmlSerializer = new XMLSerializer();
86-
return xmlSerializer.serializeToString(svg);
87-
}"""
84+
const svg = document.querySelector('svg');
85+
if (!svg) {
86+
throw new Error('SVG element not found');
87+
}
88+
const xmlSerializer = new XMLSerializer();
89+
return xmlSerializer.serializeToString(svg);
90+
}"""
8891
)
8992
logger.info(f"Generating {output_file_without_suffix}.svg..")
9093
with open(f"{output_file_without_suffix}.svg", "wb") as f:

0 commit comments

Comments
 (0)