docs: explain that the Selectors.register script is executed in the page context (#16917)
This commit is contained in:
parent
d56b279622
commit
bcf2a06e53
|
|
@ -45,7 +45,7 @@ const { selectors, firefox } = require('playwright'); // Or 'chromium' or 'webk
|
||||||
```
|
```
|
||||||
|
|
||||||
```java
|
```java
|
||||||
// Script that evaluates to a selector engine instance.
|
// Script that evaluates to a selector engine instance. The script is evaluated in the page context.
|
||||||
String createTagNameEngine = "{\n" +
|
String createTagNameEngine = "{\n" +
|
||||||
" // Returns the first element matching given selector in the root's subtree.\n" +
|
" // Returns the first element matching given selector in the root's subtree.\n" +
|
||||||
" query(root, selector) {\n" +
|
" query(root, selector) {\n" +
|
||||||
|
|
@ -146,7 +146,7 @@ with sync_playwright() as playwright:
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
using var playwright = await Playwright.CreateAsync();
|
using var playwright = await Playwright.CreateAsync();
|
||||||
// Script that evaluates to a selector engine instance.
|
// Script that evaluates to a selector engine instance. The script is evaluated in the page context.
|
||||||
await playwright.Selectors.RegisterAsync("tag", @"{
|
await playwright.Selectors.RegisterAsync("tag", @"{
|
||||||
// Returns the first element matching given selector in the root's subtree.
|
// Returns the first element matching given selector in the root's subtree.
|
||||||
query(root, selector) {
|
query(root, selector) {
|
||||||
|
|
@ -184,28 +184,28 @@ contain `[a-zA-Z0-9_]` characters.
|
||||||
current working directory. Optional.
|
current working directory. Optional.
|
||||||
- `content` ?<[string]> Raw script content. Optional.
|
- `content` ?<[string]> Raw script content. Optional.
|
||||||
|
|
||||||
Script that evaluates to a selector engine instance.
|
Script that evaluates to a selector engine instance. The script is evaluated in the page context.
|
||||||
|
|
||||||
### param: Selectors.register.script
|
### param: Selectors.register.script
|
||||||
* since: v1.8
|
* since: v1.8
|
||||||
* langs: java
|
* langs: java
|
||||||
- `script` <[string]|[path]>
|
- `script` <[string]|[path]>
|
||||||
|
|
||||||
Script that evaluates to a selector engine instance.
|
Script that evaluates to a selector engine instance. The script is evaluated in the page context.
|
||||||
|
|
||||||
### option: Selectors.register.script
|
### option: Selectors.register.script
|
||||||
* since: v1.8
|
* since: v1.8
|
||||||
* langs: csharp
|
* langs: csharp
|
||||||
- `script` <[string]>
|
- `script` <[string]>
|
||||||
|
|
||||||
Script that evaluates to a selector engine instance.
|
Script that evaluates to a selector engine instance. The script is evaluated in the page context.
|
||||||
|
|
||||||
### option: Selectors.register.path
|
### option: Selectors.register.path
|
||||||
* since: v1.8
|
* since: v1.8
|
||||||
* langs: csharp
|
* langs: csharp
|
||||||
- `path` <[path]>
|
- `path` <[path]>
|
||||||
|
|
||||||
Script that evaluates to a selector engine instance.
|
Script that evaluates to a selector engine instance. The script is evaluated in the page context.
|
||||||
|
|
||||||
### option: Selectors.register.contentScript
|
### option: Selectors.register.contentScript
|
||||||
* since: v1.8
|
* since: v1.8
|
||||||
|
|
@ -213,4 +213,4 @@ Script that evaluates to a selector engine instance.
|
||||||
|
|
||||||
Whether to run this selector engine in isolated JavaScript environment. This environment has access to the same DOM, but
|
Whether to run this selector engine in isolated JavaScript environment. This environment has access to the same DOM, but
|
||||||
not any JavaScript objects from the frame's scripts. Defaults to `false`. Note that running as a content script is not
|
not any JavaScript objects from the frame's scripts. Defaults to `false`. Note that running as a content script is not
|
||||||
guaranteed when this engine is used together with other registered engines.
|
guaranteed when this engine is used together with other registered engines.
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ const buttonCount = await page.locator('tag=button').count();
|
||||||
```
|
```
|
||||||
|
|
||||||
```java
|
```java
|
||||||
// Must be a script that evaluates to a selector engine instance.
|
// Must be a script that evaluates to a selector engine instance. The script is evaluated in the page context.
|
||||||
String createTagNameEngine = "{\n" +
|
String createTagNameEngine = "{\n" +
|
||||||
" // Returns the first element matching given selector in the root's subtree.\n" +
|
" // Returns the first element matching given selector in the root's subtree.\n" +
|
||||||
" query(root, selector) {\n" +
|
" query(root, selector) {\n" +
|
||||||
|
|
|
||||||
2
packages/playwright-core/types/types.d.ts
vendored
2
packages/playwright-core/types/types.d.ts
vendored
|
|
@ -15532,7 +15532,7 @@ export interface Selectors {
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @param name Name that is used in selectors as a prefix, e.g. `{name: 'foo'}` enables `foo=myselectorbody` selectors. May only contain `[a-zA-Z0-9_]` characters.
|
* @param name Name that is used in selectors as a prefix, e.g. `{name: 'foo'}` enables `foo=myselectorbody` selectors. May only contain `[a-zA-Z0-9_]` characters.
|
||||||
* @param script Script that evaluates to a selector engine instance.
|
* @param script Script that evaluates to a selector engine instance. The script is evaluated in the page context.
|
||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
register(name: string, script: Function|string|{
|
register(name: string, script: Function|string|{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue