From b81b0190831d66eb0de1b0bb06bc5341923e2174 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Tue, 6 Jun 2023 11:51:34 +0200 Subject: [PATCH] chore: mark Locator constructor as private (#10322) --- docs/api/puppeteer.locator._constructor_.md | 27 --------------------- docs/api/puppeteer.locator.md | 6 ----- packages/puppeteer-core/src/api/Frame.ts | 2 +- packages/puppeteer-core/src/api/Locator.ts | 22 ++++++++++++++++- packages/puppeteer-core/src/api/Page.ts | 2 +- 5 files changed, 23 insertions(+), 36 deletions(-) delete mode 100644 docs/api/puppeteer.locator._constructor_.md diff --git a/docs/api/puppeteer.locator._constructor_.md b/docs/api/puppeteer.locator._constructor_.md deleted file mode 100644 index 59fec1903b9..00000000000 --- a/docs/api/puppeteer.locator._constructor_.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -sidebar_label: Locator.(constructor) ---- - -# Locator.(constructor) - -Constructs a new instance of the `Locator` class - -#### Signature: - -```typescript -class Locator { - constructor( - pageOrFrame: Page | Frame, - selector: string, - options?: LocatorOptions - ); -} -``` - -## Parameters - -| Parameter | Type | Description | -| ----------- | ------------------------------------------------------------ | ------------ | -| pageOrFrame | [Page](./puppeteer.page.md) \| [Frame](./puppeteer.frame.md) | | -| selector | string | | -| options | [LocatorOptions](./puppeteer.locatoroptions.md) | _(Optional)_ | diff --git a/docs/api/puppeteer.locator.md b/docs/api/puppeteer.locator.md index 5fa22e27c7e..5cbefe473d1 100644 --- a/docs/api/puppeteer.locator.md +++ b/docs/api/puppeteer.locator.md @@ -14,12 +14,6 @@ export declare class Locator extends EventEmitter **Extends:** [EventEmitter](./puppeteer.eventemitter.md) -## Constructors - -| Constructor | Modifiers | Description | -| ------------------------------------------------------------------------------------- | --------- | ----------------------------------------------------------- | -| [(constructor)(pageOrFrame, selector, options)](./puppeteer.locator._constructor_.md) | | Constructs a new instance of the Locator class | - ## Methods | Method | Modifiers | Description | diff --git a/packages/puppeteer-core/src/api/Frame.ts b/packages/puppeteer-core/src/api/Frame.ts index 2567d733239..85d6f919c9f 100644 --- a/packages/puppeteer-core/src/api/Frame.ts +++ b/packages/puppeteer-core/src/api/Frame.ts @@ -356,7 +356,7 @@ export class Frame { * change in the Locators API. */ locator(selector: string): Locator { - return new Locator(this, selector); + return Locator.create(this, selector); } /** diff --git a/packages/puppeteer-core/src/api/Locator.ts b/packages/puppeteer-core/src/api/Locator.ts index 97cfaefe820..1ce8315da7d 100644 --- a/packages/puppeteer-core/src/api/Locator.ts +++ b/packages/puppeteer-core/src/api/Locator.ts @@ -117,11 +117,31 @@ export interface LocatorEventObject { * @public */ export class Locator extends EventEmitter { + /** + * @internal + */ + static create( + pageOrFrame: Page | Frame, + selector: string, + options: LocatorOptions = { + visibility: 'visible', + timeout: + 'getDefaultTimeout' in pageOrFrame + ? pageOrFrame.getDefaultTimeout() + : pageOrFrame.page().getDefaultTimeout(), + ensureElementIsInTheViewport: true, + waitForEnabled: true, + waitForStableBoundingBox: true, + } + ): Locator { + return new Locator(pageOrFrame, selector, options); + } + #pageOrFrame: Page | Frame; #selector: string; #options: LocatorOptions; - constructor( + private constructor( pageOrFrame: Page | Frame, selector: string, options: LocatorOptions = { diff --git a/packages/puppeteer-core/src/api/Page.ts b/packages/puppeteer-core/src/api/Page.ts index 3abd2f732c0..cc166c58cd8 100644 --- a/packages/puppeteer-core/src/api/Page.ts +++ b/packages/puppeteer-core/src/api/Page.ts @@ -827,7 +827,7 @@ export class Page extends EventEmitter { * change in the Locators API. */ locator(selector: string): Locator { - return new Locator(this, selector); + return Locator.create(this, selector); } /**