Skip to content

Commit

Permalink
docs: prepare docs for tabbed snippets (#5026)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Jan 15, 2021
1 parent 56ba0b3 commit 6e94c11
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
20 changes: 17 additions & 3 deletions docs/src/api/class-frame.md
Original file line number Diff line number Diff line change
Expand Up @@ -1046,9 +1046,8 @@ async def run(playwright):
webkit = playwright.webkit
browser = await webkit.launch()
page = await browser.new_page()
watch_dog = asyncio.create_task(page.main_frame.wait_for_function("() => window.innerWidth < 100")
await page.set_viewport_size({"width": 50, "height": 50})
await watch_dog
await page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);", force_expr=True)
await page.main_frame.wait_for_function("() => window.x > 0")
await browser.close()

async def main():
Expand All @@ -1057,6 +1056,21 @@ async def main():
asyncio.run(main())
```

```python sync
from playwright.sync_api import sync_playwright

def run(playwright):
webkit = playwright.webkit
browser = webkit.launch()
page = browser.new_page()
page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);", force_expr=True)
page.main_frame.wait_for_function("() => window.x > 0")
browser.close()

with sync_playwright() as playwright:
run(playwright)
```

To pass an argument to the predicate of `frame.waitForFunction` function:

```js
Expand Down
16 changes: 7 additions & 9 deletions docs/src/api/class-page.md
Original file line number Diff line number Diff line change
Expand Up @@ -2209,9 +2209,8 @@ async def run(playwright):
webkit = playwright.webkit
browser = await webkit.launch()
page = await browser.new_page()
watch_dog = page.wait_for_function("() => window.innerWidth < 100")
await page.set_viewport_size({"width": 50, "height": 50})
await watch_dog
await page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);", force_expr=True)
await page.wait_for_function("() => window.x > 0")
await browser.close()

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

def run(playwright):
webkit = playwright.webkit
browser = await webkit.launch()
page = await browser.new_page()
watch_dog = page.wait_for_function("() => window.innerWidth < 100")
await page.set_viewport_size({"width": 50, "height": 50})
await watch_dog
await browser.close()
browser = webkit.launch()
page = browser.new_page()
page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);", force_expr=True)
page.wait_for_function("() => window.x > 0")
browser.close()

with sync_playwright() as playwright:
run(playwright)
Expand Down
3 changes: 2 additions & 1 deletion utils/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ function innerRenderMdNode(indent, node, lastNode, result, maxColumns) {
const bothLinks = node.text.match(/\[[^\]]+\]:/) && lastNode && lastNode.type === 'text' && lastNode.text.match(/\[[^\]]+\]:/);
if (!bothTables && !bothGen && !bothComments && !bothLinks && lastNode && lastNode.text)
newLine();
result.push(wrapText(node.text, maxColumns, indent));
for (const line of node.text.split('\n'))
result.push(wrapText(line, maxColumns, indent));
return;
}

Expand Down

0 comments on commit 6e94c11

Please sign in to comment.