mirror of
https://github.com/microsoft/playwright.git
synced 2024-09-11 20:37:54 +03:00
docs: deprecate handle
option in exposeBinding
(#31419)
This commit is contained in:
parent
865f0d8221
commit
114b6f0de6
@ -748,83 +748,6 @@ await page.SetContentAsync("<script>\n" +
|
||||
await page.GetByRole(AriaRole.Button).ClickAsync();
|
||||
```
|
||||
|
||||
An example of passing an element handle:
|
||||
|
||||
```js
|
||||
await context.exposeBinding('clicked', async (source, element) => {
|
||||
console.log(await element.textContent());
|
||||
}, { handle: true });
|
||||
await page.setContent(`
|
||||
<script>
|
||||
document.addEventListener('click', event => window.clicked(event.target));
|
||||
</script>
|
||||
<div>Click me</div>
|
||||
<div>Or click me</div>
|
||||
`);
|
||||
```
|
||||
|
||||
```java
|
||||
context.exposeBinding("clicked", (source, args) -> {
|
||||
ElementHandle element = (ElementHandle) args[0];
|
||||
System.out.println(element.textContent());
|
||||
return null;
|
||||
}, new BrowserContext.ExposeBindingOptions().setHandle(true));
|
||||
page.setContent("" +
|
||||
"<script>\n" +
|
||||
" document.addEventListener('click', event => window.clicked(event.target));\n" +
|
||||
"</script>\n" +
|
||||
"<div>Click me</div>\n" +
|
||||
"<div>Or click me</div>\n");
|
||||
```
|
||||
|
||||
```python async
|
||||
async def print(source, element):
|
||||
print(await element.text_content())
|
||||
|
||||
await context.expose_binding("clicked", print, handle=true)
|
||||
await page.set_content("""
|
||||
<script>
|
||||
document.addEventListener('click', event => window.clicked(event.target));
|
||||
</script>
|
||||
<div>Click me</div>
|
||||
<div>Or click me</div>
|
||||
""")
|
||||
```
|
||||
|
||||
```python sync
|
||||
def print(source, element):
|
||||
print(element.text_content())
|
||||
|
||||
context.expose_binding("clicked", print, handle=true)
|
||||
page.set_content("""
|
||||
<script>
|
||||
document.addEventListener('click', event => window.clicked(event.target));
|
||||
</script>
|
||||
<div>Click me</div>
|
||||
<div>Or click me</div>
|
||||
""")
|
||||
```
|
||||
|
||||
```csharp
|
||||
var result = new TaskCompletionSource<string>();
|
||||
var page = await Context.NewPageAsync();
|
||||
await Context.ExposeBindingAsync("clicked", async (BindingSource _, IJSHandle t) =>
|
||||
{
|
||||
return result.TrySetResult(await t.AsElement().TextContentAsync());
|
||||
});
|
||||
|
||||
await page.SetContentAsync("<script>\n" +
|
||||
" document.addEventListener('click', event => window.clicked(event.target));\n" +
|
||||
"</script>\n" +
|
||||
"<div>Click me</div>\n" +
|
||||
"<div>Or click me</div>\n");
|
||||
|
||||
await page.ClickAsync("div");
|
||||
// Note: it makes sense to await the result here, because otherwise, the context
|
||||
// gets closed and the binding function will throw an exception.
|
||||
Assert.AreEqual("Click me", await result.Task);
|
||||
```
|
||||
|
||||
### param: BrowserContext.exposeBinding.name
|
||||
* since: v1.8
|
||||
- `name` <[string]>
|
||||
@ -839,6 +762,7 @@ Callback function that will be called in the Playwright's context.
|
||||
|
||||
### option: BrowserContext.exposeBinding.handle
|
||||
* since: v1.8
|
||||
* deprecated: This option will be removed in the future.
|
||||
- `handle` <[boolean]>
|
||||
|
||||
Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument is
|
||||
|
@ -1817,80 +1817,6 @@ class PageExamples
|
||||
}
|
||||
```
|
||||
|
||||
An example of passing an element handle:
|
||||
|
||||
```js
|
||||
await page.exposeBinding('clicked', async (source, element) => {
|
||||
console.log(await element.textContent());
|
||||
}, { handle: true });
|
||||
await page.setContent(`
|
||||
<script>
|
||||
document.addEventListener('click', event => window.clicked(event.target));
|
||||
</script>
|
||||
<div>Click me</div>
|
||||
<div>Or click me</div>
|
||||
`);
|
||||
```
|
||||
|
||||
```java
|
||||
page.exposeBinding("clicked", (source, args) -> {
|
||||
ElementHandle element = (ElementHandle) args[0];
|
||||
System.out.println(element.textContent());
|
||||
return null;
|
||||
}, new Page.ExposeBindingOptions().setHandle(true));
|
||||
page.setContent("" +
|
||||
"<script>\n" +
|
||||
" document.addEventListener('click', event => window.clicked(event.target));\n" +
|
||||
"</script>\n" +
|
||||
"<div>Click me</div>\n" +
|
||||
"<div>Or click me</div>\n");
|
||||
```
|
||||
|
||||
```python async
|
||||
async def print(source, element):
|
||||
print(await element.text_content())
|
||||
|
||||
await page.expose_binding("clicked", print, handle=true)
|
||||
await page.set_content("""
|
||||
<script>
|
||||
document.addEventListener('click', event => window.clicked(event.target));
|
||||
</script>
|
||||
<div>Click me</div>
|
||||
<div>Or click me</div>
|
||||
""")
|
||||
```
|
||||
|
||||
```python sync
|
||||
def print(source, element):
|
||||
print(element.text_content())
|
||||
|
||||
page.expose_binding("clicked", print, handle=true)
|
||||
page.set_content("""
|
||||
<script>
|
||||
document.addEventListener('click', event => window.clicked(event.target));
|
||||
</script>
|
||||
<div>Click me</div>
|
||||
<div>Or click me</div>
|
||||
""")
|
||||
```
|
||||
|
||||
```csharp
|
||||
var result = new TaskCompletionSource<string>();
|
||||
await page.ExposeBindingAsync("clicked", async (BindingSource _, IJSHandle t) =>
|
||||
{
|
||||
return result.TrySetResult(await t.AsElement().TextContentAsync());
|
||||
});
|
||||
|
||||
await page.SetContentAsync("<script>\n" +
|
||||
" document.addEventListener('click', event => window.clicked(event.target));\n" +
|
||||
"</script>\n" +
|
||||
"<div>Click me</div>\n" +
|
||||
"<div>Or click me</div>\n");
|
||||
|
||||
await page.ClickAsync("div");
|
||||
Console.WriteLine(await result.Task);
|
||||
```
|
||||
|
||||
### param: Page.exposeBinding.name
|
||||
* since: v1.8
|
||||
- `name` <[string]>
|
||||
@ -1905,6 +1831,7 @@ Callback function that will be called in the Playwright's context.
|
||||
|
||||
### option: Page.exposeBinding.handle
|
||||
* since: v1.8
|
||||
* deprecated: This option will be removed in the future.
|
||||
- `handle` <[boolean]>
|
||||
|
||||
Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument is
|
||||
|
60
packages/playwright-core/types/types.d.ts
vendored
60
packages/playwright-core/types/types.d.ts
vendored
@ -814,21 +814,6 @@ export interface Page {
|
||||
* })();
|
||||
* ```
|
||||
*
|
||||
* An example of passing an element handle:
|
||||
*
|
||||
* ```js
|
||||
* await page.exposeBinding('clicked', async (source, element) => {
|
||||
* console.log(await element.textContent());
|
||||
* }, { handle: true });
|
||||
* await page.setContent(`
|
||||
* <script>
|
||||
* document.addEventListener('click', event => window.clicked(event.target));
|
||||
* </script>
|
||||
* <div>Click me</div>
|
||||
* <div>Or click me</div>
|
||||
* `);
|
||||
* ```
|
||||
*
|
||||
* @param name Name of the function on the window object.
|
||||
* @param callback Callback function that will be called in the Playwright's context.
|
||||
* @param options
|
||||
@ -875,21 +860,6 @@ export interface Page {
|
||||
* })();
|
||||
* ```
|
||||
*
|
||||
* An example of passing an element handle:
|
||||
*
|
||||
* ```js
|
||||
* await page.exposeBinding('clicked', async (source, element) => {
|
||||
* console.log(await element.textContent());
|
||||
* }, { handle: true });
|
||||
* await page.setContent(`
|
||||
* <script>
|
||||
* document.addEventListener('click', event => window.clicked(event.target));
|
||||
* </script>
|
||||
* <div>Click me</div>
|
||||
* <div>Or click me</div>
|
||||
* `);
|
||||
* ```
|
||||
*
|
||||
* @param name Name of the function on the window object.
|
||||
* @param callback Callback function that will be called in the Playwright's context.
|
||||
* @param options
|
||||
@ -7637,21 +7607,6 @@ export interface BrowserContext {
|
||||
* })();
|
||||
* ```
|
||||
*
|
||||
* An example of passing an element handle:
|
||||
*
|
||||
* ```js
|
||||
* await context.exposeBinding('clicked', async (source, element) => {
|
||||
* console.log(await element.textContent());
|
||||
* }, { handle: true });
|
||||
* await page.setContent(`
|
||||
* <script>
|
||||
* document.addEventListener('click', event => window.clicked(event.target));
|
||||
* </script>
|
||||
* <div>Click me</div>
|
||||
* <div>Or click me</div>
|
||||
* `);
|
||||
* ```
|
||||
*
|
||||
* @param name Name of the function on the window object.
|
||||
* @param callback Callback function that will be called in the Playwright's context.
|
||||
* @param options
|
||||
@ -7693,21 +7648,6 @@ export interface BrowserContext {
|
||||
* })();
|
||||
* ```
|
||||
*
|
||||
* An example of passing an element handle:
|
||||
*
|
||||
* ```js
|
||||
* await context.exposeBinding('clicked', async (source, element) => {
|
||||
* console.log(await element.textContent());
|
||||
* }, { handle: true });
|
||||
* await page.setContent(`
|
||||
* <script>
|
||||
* document.addEventListener('click', event => window.clicked(event.target));
|
||||
* </script>
|
||||
* <div>Click me</div>
|
||||
* <div>Or click me</div>
|
||||
* `);
|
||||
* ```
|
||||
*
|
||||
* @param name Name of the function on the window object.
|
||||
* @param callback Callback function that will be called in the Playwright's context.
|
||||
* @param options
|
||||
|
Loading…
Reference in New Issue
Block a user