Skip to content

Commit 6e94c11

Browse files
authored
docs: prepare docs for tabbed snippets (#5026)
1 parent 56ba0b3 commit 6e94c11

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

docs/src/api/class-frame.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,9 +1046,8 @@ async def run(playwright):
10461046
webkit = playwright.webkit
10471047
browser = await webkit.launch()
10481048
page = await browser.new_page()
1049-
watch_dog = asyncio.create_task(page.main_frame.wait_for_function("() => window.innerWidth < 100")
1050-
await page.set_viewport_size({"width": 50, "height": 50})
1051-
await watch_dog
1049+
await page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);", force_expr=True)
1050+
await page.main_frame.wait_for_function("() => window.x > 0")
10521051
await browser.close()
10531052

10541053
async def main():
@@ -1057,6 +1056,21 @@ async def main():
10571056
asyncio.run(main())
10581057
```
10591058

1059+
```python sync
1060+
from playwright.sync_api import sync_playwright
1061+
1062+
def run(playwright):
1063+
webkit = playwright.webkit
1064+
browser = webkit.launch()
1065+
page = browser.new_page()
1066+
page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);", force_expr=True)
1067+
page.main_frame.wait_for_function("() => window.x > 0")
1068+
browser.close()
1069+
1070+
with sync_playwright() as playwright:
1071+
run(playwright)
1072+
```
1073+
10601074
To pass an argument to the predicate of `frame.waitForFunction` function:
10611075

10621076
```js

docs/src/api/class-page.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,9 +2209,8 @@ async def run(playwright):
22092209
webkit = playwright.webkit
22102210
browser = await webkit.launch()
22112211
page = await browser.new_page()
2212-
watch_dog = page.wait_for_function("() => window.innerWidth < 100")
2213-
await page.set_viewport_size({"width": 50, "height": 50})
2214-
await watch_dog
2212+
await page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);", force_expr=True)
2213+
await page.wait_for_function("() => window.x > 0")
22152214
await browser.close()
22162215

22172216
async def main():
@@ -2225,12 +2224,11 @@ from playwright.sync_api import sync_playwright
22252224

22262225
def run(playwright):
22272226
webkit = playwright.webkit
2228-
browser = await webkit.launch()
2229-
page = await browser.new_page()
2230-
watch_dog = page.wait_for_function("() => window.innerWidth < 100")
2231-
await page.set_viewport_size({"width": 50, "height": 50})
2232-
await watch_dog
2233-
await browser.close()
2227+
browser = webkit.launch()
2228+
page = browser.new_page()
2229+
page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);", force_expr=True)
2230+
page.wait_for_function("() => window.x > 0")
2231+
browser.close()
22342232

22352233
with sync_playwright() as playwright:
22362234
run(playwright)

utils/markdown.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ function innerRenderMdNode(indent, node, lastNode, result, maxColumns) {
247247
const bothLinks = node.text.match(/\[[^\]]+\]:/) && lastNode && lastNode.type === 'text' && lastNode.text.match(/\[[^\]]+\]:/);
248248
if (!bothTables && !bothGen && !bothComments && !bothLinks && lastNode && lastNode.text)
249249
newLine();
250-
result.push(wrapText(node.text, maxColumns, indent));
250+
for (const line of node.text.split('\n'))
251+
result.push(wrapText(line, maxColumns, indent));
251252
return;
252253
}
253254

0 commit comments

Comments
 (0)