Skip to content

Commit 0443865

Browse files
committed
bugfix: #1547 Before calling serializeToString in mmdc_playwright.py, make sure the SVG element exists.
1 parent b5bb4d7 commit 0443865

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)