Skip to content

Commit 8008f7f

Browse files
authored
Collapse RemovePlaywrightStyle into a single evaluate (#856)
Replace the per-style-element querySelectorAll + InnerHTML + remove round-trips with one EvaluateAsync that does the work in the browser, turning 1+N+M sequential CDP hops into a single round-trip.
1 parent 113c373 commit 8008f7f

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
static class StyleHelper
22
{
3-
public static async Task RemovePlaywrightStyle(this IPage page)
4-
{
5-
var elements = await page.QuerySelectorAllAsync("style");
6-
foreach (var element in elements)
7-
{
8-
var value = await element.InnerHTMLAsync();
9-
if (value.Contains("*:not(#playwright"))
10-
{
11-
await element.EvaluateAsync("element => element.remove()", element);
3+
public static Task RemovePlaywrightStyle(this IPage page) =>
4+
page.EvaluateAsync(
5+
"""
6+
() => {
7+
for (const style of document.querySelectorAll('style')) {
8+
if (style.innerHTML.includes('*:not(#playwright')) {
9+
style.remove();
10+
}
11+
}
1212
}
13-
}
14-
}
13+
""");
1514
}

0 commit comments

Comments
 (0)