mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix!: refactor custom query handler API (#9078)
This PR removes the deprecated query selector API from the `puppeteer` instance. Direct imports of the query selector API have also been deprecated and users are now expected to use the static methods defined on `Puppeteer`.
This commit is contained in:
parent
acbc59999b
commit
1847704789
@ -52,10 +52,10 @@ sidebar_label: API
|
|||||||
## Functions
|
## Functions
|
||||||
|
|
||||||
| Function | Description |
|
| Function | Description |
|
||||||
| -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
|
| -------------------------------------------------------------------------------------- | ----------- |
|
||||||
| [clearCustomQueryHandlers()](./puppeteer.clearcustomqueryhandlers.md) | Clears all registered handlers. |
|
| [clearCustomQueryHandlers()](./puppeteer.clearcustomqueryhandlers.md) | |
|
||||||
| [customQueryHandlerNames()](./puppeteer.customqueryhandlernames.md) | |
|
| [customQueryHandlerNames()](./puppeteer.customqueryhandlernames.md) | |
|
||||||
| [registerCustomQueryHandler(name, handler)](./puppeteer.registercustomqueryhandler.md) | Registers a [custom query handler](./puppeteer.customqueryhandler.md). |
|
| [registerCustomQueryHandler(name, handler)](./puppeteer.registercustomqueryhandler.md) | |
|
||||||
| [unregisterCustomQueryHandler(name)](./puppeteer.unregistercustomqueryhandler.md) | |
|
| [unregisterCustomQueryHandler(name)](./puppeteer.unregistercustomqueryhandler.md) | |
|
||||||
|
|
||||||
## Interfaces
|
## Interfaces
|
||||||
|
@ -4,7 +4,9 @@ sidebar_label: clearCustomQueryHandlers
|
|||||||
|
|
||||||
# clearCustomQueryHandlers() function
|
# clearCustomQueryHandlers() function
|
||||||
|
|
||||||
Clears all registered handlers.
|
> Warning: This API is now obsolete.
|
||||||
|
>
|
||||||
|
> Import [Puppeteer](./puppeteer.puppeteer.md) and use the static method [Puppeteer.clearCustomQueryHandlers()](./puppeteer.puppeteer.clearcustomqueryhandlers.md)
|
||||||
|
|
||||||
**Signature:**
|
**Signature:**
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ sidebar_label: connect
|
|||||||
**Signature:**
|
**Signature:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
connect: (options: import('./types').ConnectOptions) =>
|
connect: (
|
||||||
Promise<import('./types').Browser>;
|
options: import('puppeteer-core/internal/common/Puppeteer.js').ConnectOptions
|
||||||
|
) => Promise<import('./types').Browser>;
|
||||||
```
|
```
|
||||||
|
@ -4,6 +4,10 @@ sidebar_label: customQueryHandlerNames
|
|||||||
|
|
||||||
# customQueryHandlerNames() function
|
# customQueryHandlerNames() function
|
||||||
|
|
||||||
|
> Warning: This API is now obsolete.
|
||||||
|
>
|
||||||
|
> Import [Puppeteer](./puppeteer.puppeteer.md) and use the static method [Puppeteer.customQueryHandlerNames()](./puppeteer.puppeteer.customqueryhandlernames.md)
|
||||||
|
|
||||||
**Signature:**
|
**Signature:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
@ -13,5 +17,3 @@ export declare function customQueryHandlerNames(): string[];
|
|||||||
**Returns:**
|
**Returns:**
|
||||||
|
|
||||||
string\[\]
|
string\[\]
|
||||||
|
|
||||||
a list with the names of all registered custom query handlers.
|
|
||||||
|
@ -4,24 +4,16 @@ sidebar_label: Puppeteer.clearCustomQueryHandlers
|
|||||||
|
|
||||||
# Puppeteer.clearCustomQueryHandlers() method
|
# Puppeteer.clearCustomQueryHandlers() method
|
||||||
|
|
||||||
> Warning: This API is now obsolete.
|
Unregisters all custom query handlers.
|
||||||
>
|
|
||||||
> Import directly puppeteer.
|
|
||||||
|
|
||||||
**Signature:**
|
**Signature:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
class Puppeteer {
|
class Puppeteer {
|
||||||
clearCustomQueryHandlers(): void;
|
static clearCustomQueryHandlers(): void;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**Returns:**
|
**Returns:**
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {clearCustomQueryHandlers} from 'puppeteer';
|
|
||||||
```
|
|
||||||
|
@ -4,24 +4,16 @@ sidebar_label: Puppeteer.customQueryHandlerNames
|
|||||||
|
|
||||||
# Puppeteer.customQueryHandlerNames() method
|
# Puppeteer.customQueryHandlerNames() method
|
||||||
|
|
||||||
> Warning: This API is now obsolete.
|
Gets the names of all custom query handlers.
|
||||||
>
|
|
||||||
> Import directly puppeteer.
|
|
||||||
|
|
||||||
**Signature:**
|
**Signature:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
class Puppeteer {
|
class Puppeteer {
|
||||||
customQueryHandlerNames(): string[];
|
static customQueryHandlerNames(): string[];
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**Returns:**
|
**Returns:**
|
||||||
|
|
||||||
string\[\]
|
string\[\]
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {customQueryHandlerNames} from 'puppeteer';
|
|
||||||
```
|
|
||||||
|
@ -21,9 +21,9 @@ The constructor for this class is marked as internal. Third-party code should no
|
|||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
| Method | Modifiers | Description |
|
| Method | Modifiers | Description |
|
||||||
| ----------------------------------------------------------------------------------------------------- | --------- | --------------------------------------------------------------- |
|
| ----------------------------------------------------------------------------------------------------- | ------------------- | ---------------------------------------------------------------------- |
|
||||||
| [clearCustomQueryHandlers()](./puppeteer.puppeteer.clearcustomqueryhandlers.md) | | |
|
| [clearCustomQueryHandlers()](./puppeteer.puppeteer.clearcustomqueryhandlers.md) | <code>static</code> | Unregisters all custom query handlers. |
|
||||||
| [connect(options)](./puppeteer.puppeteer.connect.md) | | This method attaches Puppeteer to an existing browser instance. |
|
| [connect(options)](./puppeteer.puppeteer.connect.md) | | This method attaches Puppeteer to an existing browser instance. |
|
||||||
| [customQueryHandlerNames()](./puppeteer.puppeteer.customqueryhandlernames.md) | | |
|
| [customQueryHandlerNames()](./puppeteer.puppeteer.customqueryhandlernames.md) | <code>static</code> | Gets the names of all custom query handlers. |
|
||||||
| [registerCustomQueryHandler(name, queryHandler)](./puppeteer.puppeteer.registercustomqueryhandler.md) | | |
|
| [registerCustomQueryHandler(name, queryHandler)](./puppeteer.puppeteer.registercustomqueryhandler.md) | <code>static</code> | Registers a [custom query handler](./puppeteer.customqueryhandler.md). |
|
||||||
| [unregisterCustomQueryHandler(name)](./puppeteer.puppeteer.unregistercustomqueryhandler.md) | | |
|
| [unregisterCustomQueryHandler(name)](./puppeteer.puppeteer.unregistercustomqueryhandler.md) | <code>static</code> | Unregisters a custom query handler for a given name. |
|
||||||
|
@ -4,15 +4,13 @@ sidebar_label: Puppeteer.registerCustomQueryHandler
|
|||||||
|
|
||||||
# Puppeteer.registerCustomQueryHandler() method
|
# Puppeteer.registerCustomQueryHandler() method
|
||||||
|
|
||||||
> Warning: This API is now obsolete.
|
Registers a [custom query handler](./puppeteer.customqueryhandler.md).
|
||||||
>
|
|
||||||
> Import directly puppeteer.
|
|
||||||
|
|
||||||
**Signature:**
|
**Signature:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
class Puppeteer {
|
class Puppeteer {
|
||||||
registerCustomQueryHandler(
|
static registerCustomQueryHandler(
|
||||||
name: string,
|
name: string,
|
||||||
queryHandler: CustomQueryHandler
|
queryHandler: CustomQueryHandler
|
||||||
): void;
|
): void;
|
||||||
@ -22,16 +20,21 @@ class Puppeteer {
|
|||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
| ------------ | ------------------------------------------------------- | ----------- |
|
| ------------ | ------------------------------------------------------- | -------------------------------------------------------------------------- |
|
||||||
| name | string | |
|
| name | string | The name that the custom query handler will be registered under. |
|
||||||
| queryHandler | [CustomQueryHandler](./puppeteer.customqueryhandler.md) | |
|
| queryHandler | [CustomQueryHandler](./puppeteer.customqueryhandler.md) | The [custom query handler](./puppeteer.customqueryhandler.md) to register. |
|
||||||
|
|
||||||
**Returns:**
|
**Returns:**
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
||||||
|
## Remarks
|
||||||
|
|
||||||
|
After registration, the handler can be used everywhere where a selector is expected by prepending the selection string with `<name>/`. The name is only allowed to consist of lower- and upper case latin letters.
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
```ts
|
```
|
||||||
import {registerCustomQueryHandler} from 'puppeteer';
|
puppeteer.registerCustomQueryHandler('text', { … });
|
||||||
|
const aHandle = await page.$('text/…');
|
||||||
```
|
```
|
||||||
|
@ -4,15 +4,13 @@ sidebar_label: Puppeteer.unregisterCustomQueryHandler
|
|||||||
|
|
||||||
# Puppeteer.unregisterCustomQueryHandler() method
|
# Puppeteer.unregisterCustomQueryHandler() method
|
||||||
|
|
||||||
> Warning: This API is now obsolete.
|
Unregisters a custom query handler for a given name.
|
||||||
>
|
|
||||||
> Import directly puppeteer.
|
|
||||||
|
|
||||||
**Signature:**
|
**Signature:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
class Puppeteer {
|
class Puppeteer {
|
||||||
unregisterCustomQueryHandler(name: string): void;
|
static unregisterCustomQueryHandler(name: string): void;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -25,9 +23,3 @@ class Puppeteer {
|
|||||||
**Returns:**
|
**Returns:**
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {unregisterCustomQueryHandler} from 'puppeteer';
|
|
||||||
```
|
|
||||||
|
@ -4,7 +4,9 @@ sidebar_label: registerCustomQueryHandler
|
|||||||
|
|
||||||
# registerCustomQueryHandler() function
|
# registerCustomQueryHandler() function
|
||||||
|
|
||||||
Registers a [custom query handler](./puppeteer.customqueryhandler.md).
|
> Warning: This API is now obsolete.
|
||||||
|
>
|
||||||
|
> Import [Puppeteer](./puppeteer.puppeteer.md) and use the static method [Puppeteer.registerCustomQueryHandler()](./puppeteer.puppeteer.registercustomqueryhandler.md)
|
||||||
|
|
||||||
**Signature:**
|
**Signature:**
|
||||||
|
|
||||||
@ -18,21 +20,10 @@ export declare function registerCustomQueryHandler(
|
|||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
| --------- | ------------------------------------------------------- | ---------------------------------------------------------------- |
|
| --------- | ------------------------------------------------------- | ----------- |
|
||||||
| name | string | The name that the custom query handler will be registered under. |
|
| name | string | |
|
||||||
| handler | [CustomQueryHandler](./puppeteer.customqueryhandler.md) | |
|
| handler | [CustomQueryHandler](./puppeteer.customqueryhandler.md) | |
|
||||||
|
|
||||||
**Returns:**
|
**Returns:**
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
||||||
## Remarks
|
|
||||||
|
|
||||||
After registration, the handler can be used everywhere where a selector is expected by prepending the selection string with `<name>/`. The name is only allowed to consist of lower- and upper case latin letters.
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```
|
|
||||||
puppeteer.registerCustomQueryHandler('text', { … });
|
|
||||||
const aHandle = await page.$('text/…');
|
|
||||||
```
|
|
||||||
|
@ -4,6 +4,10 @@ sidebar_label: unregisterCustomQueryHandler
|
|||||||
|
|
||||||
# unregisterCustomQueryHandler() function
|
# unregisterCustomQueryHandler() function
|
||||||
|
|
||||||
|
> Warning: This API is now obsolete.
|
||||||
|
>
|
||||||
|
> Import [Puppeteer](./puppeteer.puppeteer.md) and use the static method [Puppeteer.unregisterCustomQueryHandler()](./puppeteer.puppeteer.unregistercustomqueryhandler.md)
|
||||||
|
|
||||||
**Signature:**
|
**Signature:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
@ -13,8 +17,8 @@ export declare function unregisterCustomQueryHandler(name: string): void;
|
|||||||
## Parameters
|
## Parameters
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
| Parameter | Type | Description |
|
||||||
| --------- | ------ | ---------------------------------------------- |
|
| --------- | ------ | ----------- |
|
||||||
| name | string | The name of the query handler to unregistered. |
|
| name | string | |
|
||||||
|
|
||||||
**Returns:**
|
**Returns:**
|
||||||
|
|
||||||
|
@ -54,6 +54,56 @@ export interface ConnectOptions extends BrowserConnectOptions {
|
|||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export class Puppeteer {
|
export class Puppeteer {
|
||||||
|
/**
|
||||||
|
* Registers a {@link CustomQueryHandler | custom query handler}.
|
||||||
|
*
|
||||||
|
* @remarks
|
||||||
|
* After registration, the handler can be used everywhere where a selector is
|
||||||
|
* expected by prepending the selection string with `<name>/`. The name is only
|
||||||
|
* allowed to consist of lower- and upper case latin letters.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* ```
|
||||||
|
* puppeteer.registerCustomQueryHandler('text', { … });
|
||||||
|
* const aHandle = await page.$('text/…');
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param name - The name that the custom query handler will be registered
|
||||||
|
* under.
|
||||||
|
* @param queryHandler - The {@link CustomQueryHandler | custom query handler}
|
||||||
|
* to register.
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
static registerCustomQueryHandler(
|
||||||
|
name: string,
|
||||||
|
queryHandler: CustomQueryHandler
|
||||||
|
): void {
|
||||||
|
return registerCustomQueryHandler(name, queryHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregisters a custom query handler for a given name.
|
||||||
|
*/
|
||||||
|
static unregisterCustomQueryHandler(name: string): void {
|
||||||
|
return unregisterCustomQueryHandler(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the names of all custom query handlers.
|
||||||
|
*/
|
||||||
|
static customQueryHandlerNames(): string[] {
|
||||||
|
return customQueryHandlerNames();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregisters all custom query handlers.
|
||||||
|
*/
|
||||||
|
static clearCustomQueryHandlers(): void {
|
||||||
|
return clearCustomQueryHandlers();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
@ -83,55 +133,4 @@ export class Puppeteer {
|
|||||||
connect(options: ConnectOptions): Promise<Browser> {
|
connect(options: ConnectOptions): Promise<Browser> {
|
||||||
return _connectToCDPBrowser(options);
|
return _connectToCDPBrowser(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Import directly puppeteer.
|
|
||||||
* @example
|
|
||||||
*
|
|
||||||
* ```ts
|
|
||||||
* import {registerCustomQueryHandler} from 'puppeteer';
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
registerCustomQueryHandler(
|
|
||||||
name: string,
|
|
||||||
queryHandler: CustomQueryHandler
|
|
||||||
): void {
|
|
||||||
return registerCustomQueryHandler(name, queryHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Import directly puppeteer.
|
|
||||||
* @example
|
|
||||||
*
|
|
||||||
* ```ts
|
|
||||||
* import {unregisterCustomQueryHandler} from 'puppeteer';
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
unregisterCustomQueryHandler(name: string): void {
|
|
||||||
return unregisterCustomQueryHandler(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Import directly puppeteer.
|
|
||||||
* @example
|
|
||||||
*
|
|
||||||
* ```ts
|
|
||||||
* import {customQueryHandlerNames} from 'puppeteer';
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
customQueryHandlerNames(): string[] {
|
|
||||||
return customQueryHandlerNames();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Import directly puppeteer.
|
|
||||||
* @example
|
|
||||||
*
|
|
||||||
* ```ts
|
|
||||||
* import {clearCustomQueryHandlers} from 'puppeteer';
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
clearCustomQueryHandlers(): void {
|
|
||||||
return clearCustomQueryHandlers();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -237,24 +237,8 @@ const INTERNAL_QUERY_HANDLERS = new Map<string, RegisteredQueryHandler>([
|
|||||||
const QUERY_HANDLERS = new Map<string, RegisteredQueryHandler>();
|
const QUERY_HANDLERS = new Map<string, RegisteredQueryHandler>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a {@link CustomQueryHandler | custom query handler}.
|
* @deprecated Import {@link Puppeteer} and use the static method
|
||||||
*
|
* {@link Puppeteer.registerCustomQueryHandler}
|
||||||
* @remarks
|
|
||||||
* After registration, the handler can be used everywhere where a selector is
|
|
||||||
* expected by prepending the selection string with `<name>/`. The name is only
|
|
||||||
* allowed to consist of lower- and upper case latin letters.
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
*
|
|
||||||
* ```
|
|
||||||
* puppeteer.registerCustomQueryHandler('text', { … });
|
|
||||||
* const aHandle = await page.$('text/…');
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @param name - The name that the custom query handler will be registered
|
|
||||||
* under.
|
|
||||||
* @param queryHandler - The {@link CustomQueryHandler | custom query handler}
|
|
||||||
* to register.
|
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
@ -278,7 +262,8 @@ export function registerCustomQueryHandler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param name - The name of the query handler to unregistered.
|
* @deprecated Import {@link Puppeteer} and use the static method
|
||||||
|
* {@link Puppeteer.unregisterCustomQueryHandler}
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
@ -287,7 +272,8 @@ export function unregisterCustomQueryHandler(name: string): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns a list with the names of all registered custom query handlers.
|
* @deprecated Import {@link Puppeteer} and use the static method
|
||||||
|
* {@link Puppeteer.customQueryHandlerNames}
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
@ -296,7 +282,8 @@ export function customQueryHandlerNames(): string[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears all registered handlers.
|
* @deprecated Import {@link Puppeteer} and use the static method
|
||||||
|
* {@link Puppeteer.clearCustomQueryHandlers}
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
|
@ -18,6 +18,11 @@ export {Protocol} from 'devtools-protocol';
|
|||||||
export * from './common/Device.js';
|
export * from './common/Device.js';
|
||||||
export * from './common/Errors.js';
|
export * from './common/Errors.js';
|
||||||
export * from './common/PredefinedNetworkConditions.js';
|
export * from './common/PredefinedNetworkConditions.js';
|
||||||
|
export * from './common/Puppeteer.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use the query handler API defined on {@link Puppeteer}
|
||||||
|
*/
|
||||||
export * from './common/QueryHandler.js';
|
export * from './common/QueryHandler.js';
|
||||||
|
|
||||||
import {rootDirname} from './constants.js';
|
import {rootDirname} from './constants.js';
|
||||||
|
@ -18,6 +18,10 @@ export {Protocol} from 'devtools-protocol';
|
|||||||
export * from 'puppeteer-core/internal/common/Device.js';
|
export * from 'puppeteer-core/internal/common/Device.js';
|
||||||
export * from 'puppeteer-core/internal/common/Errors.js';
|
export * from 'puppeteer-core/internal/common/Errors.js';
|
||||||
export * from 'puppeteer-core/internal/common/PredefinedNetworkConditions.js';
|
export * from 'puppeteer-core/internal/common/PredefinedNetworkConditions.js';
|
||||||
|
export * from 'puppeteer-core/internal/common/Puppeteer.js';
|
||||||
|
/**
|
||||||
|
* @deprecated Use the query handler API defined on {@link Puppeteer}
|
||||||
|
*/
|
||||||
export * from 'puppeteer-core/internal/common/QueryHandler.js';
|
export * from 'puppeteer-core/internal/common/QueryHandler.js';
|
||||||
export {BrowserFetcher} from 'puppeteer-core/internal/node/BrowserFetcher.js';
|
export {BrowserFetcher} from 'puppeteer-core/internal/node/BrowserFetcher.js';
|
||||||
export {LaunchOptions} from 'puppeteer-core/internal/node/LaunchOptions.js';
|
export {LaunchOptions} from 'puppeteer-core/internal/node/LaunchOptions.js';
|
||||||
|
@ -15,14 +15,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import expect from 'expect';
|
import expect from 'expect';
|
||||||
import sinon from 'sinon';
|
|
||||||
import {ElementHandle} from 'puppeteer-core/internal/common/ElementHandle.js';
|
import {ElementHandle} from 'puppeteer-core/internal/common/ElementHandle.js';
|
||||||
|
import sinon from 'sinon';
|
||||||
import {
|
import {
|
||||||
getTestState,
|
getTestState,
|
||||||
setupTestBrowserHooks,
|
setupTestBrowserHooks,
|
||||||
setupTestPageAndContextHooks,
|
setupTestPageAndContextHooks,
|
||||||
} from './mocha-utils.js';
|
} from './mocha-utils.js';
|
||||||
|
|
||||||
|
import {Puppeteer} from 'puppeteer';
|
||||||
import utils from './utils.js';
|
import utils from './utils.js';
|
||||||
|
|
||||||
describe('ElementHandle specs', function () {
|
describe('ElementHandle specs', function () {
|
||||||
@ -390,16 +391,15 @@ describe('ElementHandle specs', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Custom queries', function () {
|
describe('Custom queries', function () {
|
||||||
this.afterEach(() => {
|
afterEach(() => {
|
||||||
const {puppeteer} = getTestState();
|
Puppeteer.clearCustomQueryHandlers();
|
||||||
puppeteer.clearCustomQueryHandlers();
|
|
||||||
});
|
});
|
||||||
it('should register and unregister', async () => {
|
it('should register and unregister', async () => {
|
||||||
const {page, puppeteer} = getTestState();
|
const {page} = getTestState();
|
||||||
await page.setContent('<div id="not-foo"></div><div id="foo"></div>');
|
await page.setContent('<div id="not-foo"></div><div id="foo"></div>');
|
||||||
|
|
||||||
// Register.
|
// Register.
|
||||||
puppeteer.registerCustomQueryHandler('getById', {
|
Puppeteer.registerCustomQueryHandler('getById', {
|
||||||
queryOne: (_element, selector) => {
|
queryOne: (_element, selector) => {
|
||||||
return document.querySelector(`[id="${selector}"]`);
|
return document.querySelector(`[id="${selector}"]`);
|
||||||
},
|
},
|
||||||
@ -412,11 +412,11 @@ describe('ElementHandle specs', function () {
|
|||||||
return element.id;
|
return element.id;
|
||||||
}, element)
|
}, element)
|
||||||
).toBe('foo');
|
).toBe('foo');
|
||||||
const handlerNamesAfterRegistering = puppeteer.customQueryHandlerNames();
|
const handlerNamesAfterRegistering = Puppeteer.customQueryHandlerNames();
|
||||||
expect(handlerNamesAfterRegistering.includes('getById')).toBeTruthy();
|
expect(handlerNamesAfterRegistering.includes('getById')).toBeTruthy();
|
||||||
|
|
||||||
// Unregister.
|
// Unregister.
|
||||||
puppeteer.unregisterCustomQueryHandler('getById');
|
Puppeteer.unregisterCustomQueryHandler('getById');
|
||||||
try {
|
try {
|
||||||
await page.$('getById/foo');
|
await page.$('getById/foo');
|
||||||
throw new Error('Custom query handler name not set - throw expected');
|
throw new Error('Custom query handler name not set - throw expected');
|
||||||
@ -426,13 +426,12 @@ describe('ElementHandle specs', function () {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
const handlerNamesAfterUnregistering =
|
const handlerNamesAfterUnregistering =
|
||||||
puppeteer.customQueryHandlerNames();
|
Puppeteer.customQueryHandlerNames();
|
||||||
expect(handlerNamesAfterUnregistering.includes('getById')).toBeFalsy();
|
expect(handlerNamesAfterUnregistering.includes('getById')).toBeFalsy();
|
||||||
});
|
});
|
||||||
it('should throw with invalid query names', () => {
|
it('should throw with invalid query names', () => {
|
||||||
try {
|
try {
|
||||||
const {puppeteer} = getTestState();
|
Puppeteer.registerCustomQueryHandler('1/2/3', {
|
||||||
puppeteer.registerCustomQueryHandler('1/2/3', {
|
|
||||||
queryOne: () => {
|
queryOne: () => {
|
||||||
return document.querySelector('foo');
|
return document.querySelector('foo');
|
||||||
},
|
},
|
||||||
@ -447,11 +446,11 @@ describe('ElementHandle specs', function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
it('should work for multiple elements', async () => {
|
it('should work for multiple elements', async () => {
|
||||||
const {page, puppeteer} = getTestState();
|
const {page} = getTestState();
|
||||||
await page.setContent(
|
await page.setContent(
|
||||||
'<div id="not-foo"></div><div class="foo">Foo1</div><div class="foo baz">Foo2</div>'
|
'<div id="not-foo"></div><div class="foo">Foo1</div><div class="foo baz">Foo2</div>'
|
||||||
);
|
);
|
||||||
puppeteer.registerCustomQueryHandler('getByClass', {
|
Puppeteer.registerCustomQueryHandler('getByClass', {
|
||||||
queryAll: (_element, selector) => {
|
queryAll: (_element, selector) => {
|
||||||
return [...document.querySelectorAll(`.${selector}`)];
|
return [...document.querySelectorAll(`.${selector}`)];
|
||||||
},
|
},
|
||||||
@ -470,11 +469,11 @@ describe('ElementHandle specs', function () {
|
|||||||
expect(classNames).toStrictEqual(['foo', 'foo baz']);
|
expect(classNames).toStrictEqual(['foo', 'foo baz']);
|
||||||
});
|
});
|
||||||
it('should eval correctly', async () => {
|
it('should eval correctly', async () => {
|
||||||
const {page, puppeteer} = getTestState();
|
const {page} = getTestState();
|
||||||
await page.setContent(
|
await page.setContent(
|
||||||
'<div id="not-foo"></div><div class="foo">Foo1</div><div class="foo baz">Foo2</div>'
|
'<div id="not-foo"></div><div class="foo">Foo1</div><div class="foo baz">Foo2</div>'
|
||||||
);
|
);
|
||||||
puppeteer.registerCustomQueryHandler('getByClass', {
|
Puppeteer.registerCustomQueryHandler('getByClass', {
|
||||||
queryAll: (_element, selector) => {
|
queryAll: (_element, selector) => {
|
||||||
return [...document.querySelectorAll(`.${selector}`)];
|
return [...document.querySelectorAll(`.${selector}`)];
|
||||||
},
|
},
|
||||||
@ -486,8 +485,8 @@ describe('ElementHandle specs', function () {
|
|||||||
expect(elements).toBe(2);
|
expect(elements).toBe(2);
|
||||||
});
|
});
|
||||||
it('should wait correctly with waitForSelector', async () => {
|
it('should wait correctly with waitForSelector', async () => {
|
||||||
const {page, puppeteer} = getTestState();
|
const {page} = getTestState();
|
||||||
puppeteer.registerCustomQueryHandler('getByClass', {
|
Puppeteer.registerCustomQueryHandler('getByClass', {
|
||||||
queryOne: (element, selector) => {
|
queryOne: (element, selector) => {
|
||||||
return (element as Element).querySelector(`.${selector}`);
|
return (element as Element).querySelector(`.${selector}`);
|
||||||
},
|
},
|
||||||
@ -504,8 +503,8 @@ describe('ElementHandle specs', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should wait correctly with waitForSelector on an element', async () => {
|
it('should wait correctly with waitForSelector on an element', async () => {
|
||||||
const {page, puppeteer} = getTestState();
|
const {page} = getTestState();
|
||||||
puppeteer.registerCustomQueryHandler('getByClass', {
|
Puppeteer.registerCustomQueryHandler('getByClass', {
|
||||||
queryOne: (element, selector) => {
|
queryOne: (element, selector) => {
|
||||||
return (element as Element).querySelector(`.${selector}`);
|
return (element as Element).querySelector(`.${selector}`);
|
||||||
},
|
},
|
||||||
@ -541,8 +540,8 @@ describe('ElementHandle specs', function () {
|
|||||||
it('should wait correctly with waitFor', async () => {
|
it('should wait correctly with waitFor', async () => {
|
||||||
/* page.waitFor is deprecated so we silence the warning to avoid test noise */
|
/* page.waitFor is deprecated so we silence the warning to avoid test noise */
|
||||||
sinon.stub(console, 'warn').callsFake(() => {});
|
sinon.stub(console, 'warn').callsFake(() => {});
|
||||||
const {page, puppeteer} = getTestState();
|
const {page} = getTestState();
|
||||||
puppeteer.registerCustomQueryHandler('getByClass', {
|
Puppeteer.registerCustomQueryHandler('getByClass', {
|
||||||
queryOne: (element, selector) => {
|
queryOne: (element, selector) => {
|
||||||
return (element as Element).querySelector(`.${selector}`);
|
return (element as Element).querySelector(`.${selector}`);
|
||||||
},
|
},
|
||||||
@ -558,11 +557,11 @@ describe('ElementHandle specs', function () {
|
|||||||
expect(element).toBeDefined();
|
expect(element).toBeDefined();
|
||||||
});
|
});
|
||||||
it('should work when both queryOne and queryAll are registered', async () => {
|
it('should work when both queryOne and queryAll are registered', async () => {
|
||||||
const {page, puppeteer} = getTestState();
|
const {page} = getTestState();
|
||||||
await page.setContent(
|
await page.setContent(
|
||||||
'<div id="not-foo"></div><div class="foo"><div id="nested-foo" class="foo"/></div><div class="foo baz">Foo2</div>'
|
'<div id="not-foo"></div><div class="foo"><div id="nested-foo" class="foo"/></div><div class="foo baz">Foo2</div>'
|
||||||
);
|
);
|
||||||
puppeteer.registerCustomQueryHandler('getByClass', {
|
Puppeteer.registerCustomQueryHandler('getByClass', {
|
||||||
queryOne: (element, selector) => {
|
queryOne: (element, selector) => {
|
||||||
return (element as Element).querySelector(`.${selector}`);
|
return (element as Element).querySelector(`.${selector}`);
|
||||||
},
|
},
|
||||||
@ -578,11 +577,11 @@ describe('ElementHandle specs', function () {
|
|||||||
expect(elements.length).toBe(3);
|
expect(elements.length).toBe(3);
|
||||||
});
|
});
|
||||||
it('should eval when both queryOne and queryAll are registered', async () => {
|
it('should eval when both queryOne and queryAll are registered', async () => {
|
||||||
const {page, puppeteer} = getTestState();
|
const {page} = getTestState();
|
||||||
await page.setContent(
|
await page.setContent(
|
||||||
'<div id="not-foo"></div><div class="foo">text</div><div class="foo baz">content</div>'
|
'<div id="not-foo"></div><div class="foo">text</div><div class="foo baz">content</div>'
|
||||||
);
|
);
|
||||||
puppeteer.registerCustomQueryHandler('getByClass', {
|
Puppeteer.registerCustomQueryHandler('getByClass', {
|
||||||
queryOne: (element, selector) => {
|
queryOne: (element, selector) => {
|
||||||
return (element as Element).querySelector(`.${selector}`);
|
return (element as Element).querySelector(`.${selector}`);
|
||||||
},
|
},
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import expect from 'expect';
|
import expect from 'expect';
|
||||||
|
import {Puppeteer} from 'puppeteer';
|
||||||
import {CustomQueryHandler} from 'puppeteer-core/internal/common/QueryHandler.js';
|
import {CustomQueryHandler} from 'puppeteer-core/internal/common/QueryHandler.js';
|
||||||
import {
|
import {
|
||||||
getTestState,
|
getTestState,
|
||||||
@ -397,14 +398,12 @@ describe('querySelector', function () {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
before(() => {
|
before(() => {
|
||||||
const {puppeteer} = getTestState();
|
Puppeteer.registerCustomQueryHandler('allArray', handler);
|
||||||
puppeteer.registerCustomQueryHandler('allArray', handler);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have registered handler', async () => {
|
it('should have registered handler', async () => {
|
||||||
const {puppeteer} = getTestState();
|
|
||||||
expect(
|
expect(
|
||||||
puppeteer.customQueryHandlerNames().includes('allArray')
|
Puppeteer.customQueryHandlerNames().includes('allArray')
|
||||||
).toBeTruthy();
|
).toBeTruthy();
|
||||||
});
|
});
|
||||||
it('$$ should query existing elements', async () => {
|
it('$$ should query existing elements', async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user