Skip to content

Commit 1368bca

Browse files
committed
cherry-pick(#31419): docs: deprecate handle option in exposeBinding
1 parent 6c3fc49 commit 1368bca

File tree

3 files changed

+2
-211
lines changed

3 files changed

+2
-211
lines changed

docs/src/api/class-browsercontext.md

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -748,83 +748,6 @@ await page.SetContentAsync("<script>\n" +
748748
await page.GetByRole(AriaRole.Button).ClickAsync();
749749
```
750750

751-
An example of passing an element handle:
752-
753-
```js
754-
await context.exposeBinding('clicked', async (source, element) => {
755-
console.log(await element.textContent());
756-
}, { handle: true });
757-
await page.setContent(`
758-
<script>
759-
document.addEventListener('click', event => window.clicked(event.target));
760-
</script>
761-
<div>Click me</div>
762-
<div>Or click me</div>
763-
`);
764-
```
765-
766-
```java
767-
context.exposeBinding("clicked", (source, args) -> {
768-
ElementHandle element = (ElementHandle) args[0];
769-
System.out.println(element.textContent());
770-
return null;
771-
}, new BrowserContext.ExposeBindingOptions().setHandle(true));
772-
page.setContent("" +
773-
"<script>\n" +
774-
" document.addEventListener('click', event => window.clicked(event.target));\n" +
775-
"</script>\n" +
776-
"<div>Click me</div>\n" +
777-
"<div>Or click me</div>\n");
778-
```
779-
780-
```python async
781-
async def print(source, element):
782-
print(await element.text_content())
783-
784-
await context.expose_binding("clicked", print, handle=true)
785-
await page.set_content("""
786-
<script>
787-
document.addEventListener('click', event => window.clicked(event.target));
788-
</script>
789-
<div>Click me</div>
790-
<div>Or click me</div>
791-
""")
792-
```
793-
794-
```python sync
795-
def print(source, element):
796-
print(element.text_content())
797-
798-
context.expose_binding("clicked", print, handle=true)
799-
page.set_content("""
800-
<script>
801-
document.addEventListener('click', event => window.clicked(event.target));
802-
</script>
803-
<div>Click me</div>
804-
<div>Or click me</div>
805-
""")
806-
```
807-
808-
```csharp
809-
var result = new TaskCompletionSource<string>();
810-
var page = await Context.NewPageAsync();
811-
await Context.ExposeBindingAsync("clicked", async (BindingSource _, IJSHandle t) =>
812-
{
813-
return result.TrySetResult(await t.AsElement().TextContentAsync());
814-
});
815-
816-
await page.SetContentAsync("<script>\n" +
817-
" document.addEventListener('click', event => window.clicked(event.target));\n" +
818-
"</script>\n" +
819-
"<div>Click me</div>\n" +
820-
"<div>Or click me</div>\n");
821-
822-
await page.ClickAsync("div");
823-
// Note: it makes sense to await the result here, because otherwise, the context
824-
// gets closed and the binding function will throw an exception.
825-
Assert.AreEqual("Click me", await result.Task);
826-
```
827-
828751
### param: BrowserContext.exposeBinding.name
829752
* since: v1.8
830753
- `name` <[string]>
@@ -839,6 +762,7 @@ Callback function that will be called in the Playwright's context.
839762

840763
### option: BrowserContext.exposeBinding.handle
841764
* since: v1.8
765+
* deprecated: This option will be removed in the future.
842766
- `handle` <[boolean]>
843767

844768
Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument is

docs/src/api/class-page.md

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,80 +1817,6 @@ class PageExamples
18171817
}
18181818
```
18191819

1820-
An example of passing an element handle:
1821-
1822-
```js
1823-
await page.exposeBinding('clicked', async (source, element) => {
1824-
console.log(await element.textContent());
1825-
}, { handle: true });
1826-
await page.setContent(`
1827-
<script>
1828-
document.addEventListener('click', event => window.clicked(event.target));
1829-
</script>
1830-
<div>Click me</div>
1831-
<div>Or click me</div>
1832-
`);
1833-
```
1834-
1835-
```java
1836-
page.exposeBinding("clicked", (source, args) -> {
1837-
ElementHandle element = (ElementHandle) args[0];
1838-
System.out.println(element.textContent());
1839-
return null;
1840-
}, new Page.ExposeBindingOptions().setHandle(true));
1841-
page.setContent("" +
1842-
"<script>\n" +
1843-
" document.addEventListener('click', event => window.clicked(event.target));\n" +
1844-
"</script>\n" +
1845-
"<div>Click me</div>\n" +
1846-
"<div>Or click me</div>\n");
1847-
```
1848-
1849-
```python async
1850-
async def print(source, element):
1851-
print(await element.text_content())
1852-
1853-
await page.expose_binding("clicked", print, handle=true)
1854-
await page.set_content("""
1855-
<script>
1856-
document.addEventListener('click', event => window.clicked(event.target));
1857-
</script>
1858-
<div>Click me</div>
1859-
<div>Or click me</div>
1860-
""")
1861-
```
1862-
1863-
```python sync
1864-
def print(source, element):
1865-
print(element.text_content())
1866-
1867-
page.expose_binding("clicked", print, handle=true)
1868-
page.set_content("""
1869-
<script>
1870-
document.addEventListener('click', event => window.clicked(event.target));
1871-
</script>
1872-
<div>Click me</div>
1873-
<div>Or click me</div>
1874-
""")
1875-
```
1876-
1877-
```csharp
1878-
var result = new TaskCompletionSource<string>();
1879-
await page.ExposeBindingAsync("clicked", async (BindingSource _, IJSHandle t) =>
1880-
{
1881-
return result.TrySetResult(await t.AsElement().TextContentAsync());
1882-
});
1883-
1884-
await page.SetContentAsync("<script>\n" +
1885-
" document.addEventListener('click', event => window.clicked(event.target));\n" +
1886-
"</script>\n" +
1887-
"<div>Click me</div>\n" +
1888-
"<div>Or click me</div>\n");
1889-
1890-
await page.ClickAsync("div");
1891-
Console.WriteLine(await result.Task);
1892-
```
1893-
18941820
### param: Page.exposeBinding.name
18951821
* since: v1.8
18961822
- `name` <[string]>
@@ -1905,6 +1831,7 @@ Callback function that will be called in the Playwright's context.
19051831

19061832
### option: Page.exposeBinding.handle
19071833
* since: v1.8
1834+
* deprecated: This option will be removed in the future.
19081835
- `handle` <[boolean]>
19091836

19101837
Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument is

packages/playwright-core/types/types.d.ts

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -814,21 +814,6 @@ export interface Page {
814814
* })();
815815
* ```
816816
*
817-
* An example of passing an element handle:
818-
*
819-
* ```js
820-
* await page.exposeBinding('clicked', async (source, element) => {
821-
* console.log(await element.textContent());
822-
* }, { handle: true });
823-
* await page.setContent(`
824-
* <script>
825-
* document.addEventListener('click', event => window.clicked(event.target));
826-
* </script>
827-
* <div>Click me</div>
828-
* <div>Or click me</div>
829-
* `);
830-
* ```
831-
*
832817
* @param name Name of the function on the window object.
833818
* @param callback Callback function that will be called in the Playwright's context.
834819
* @param options
@@ -875,21 +860,6 @@ export interface Page {
875860
* })();
876861
* ```
877862
*
878-
* An example of passing an element handle:
879-
*
880-
* ```js
881-
* await page.exposeBinding('clicked', async (source, element) => {
882-
* console.log(await element.textContent());
883-
* }, { handle: true });
884-
* await page.setContent(`
885-
* <script>
886-
* document.addEventListener('click', event => window.clicked(event.target));
887-
* </script>
888-
* <div>Click me</div>
889-
* <div>Or click me</div>
890-
* `);
891-
* ```
892-
*
893863
* @param name Name of the function on the window object.
894864
* @param callback Callback function that will be called in the Playwright's context.
895865
* @param options
@@ -7637,21 +7607,6 @@ export interface BrowserContext {
76377607
* })();
76387608
* ```
76397609
*
7640-
* An example of passing an element handle:
7641-
*
7642-
* ```js
7643-
* await context.exposeBinding('clicked', async (source, element) => {
7644-
* console.log(await element.textContent());
7645-
* }, { handle: true });
7646-
* await page.setContent(`
7647-
* <script>
7648-
* document.addEventListener('click', event => window.clicked(event.target));
7649-
* </script>
7650-
* <div>Click me</div>
7651-
* <div>Or click me</div>
7652-
* `);
7653-
* ```
7654-
*
76557610
* @param name Name of the function on the window object.
76567611
* @param callback Callback function that will be called in the Playwright's context.
76577612
* @param options
@@ -7693,21 +7648,6 @@ export interface BrowserContext {
76937648
* })();
76947649
* ```
76957650
*
7696-
* An example of passing an element handle:
7697-
*
7698-
* ```js
7699-
* await context.exposeBinding('clicked', async (source, element) => {
7700-
* console.log(await element.textContent());
7701-
* }, { handle: true });
7702-
* await page.setContent(`
7703-
* <script>
7704-
* document.addEventListener('click', event => window.clicked(event.target));
7705-
* </script>
7706-
* <div>Click me</div>
7707-
* <div>Or click me</div>
7708-
* `);
7709-
* ```
7710-
*
77117651
* @param name Name of the function on the window object.
77127652
* @param callback Callback function that will be called in the Playwright's context.
77137653
* @param options

0 commit comments

Comments
 (0)