Skip to main content
Version: Next

puppeteerClickElements

Index

References

enqueueLinksByClickingElements

Interfaces

EnqueueLinksByClickingElementsOptions

EnqueueLinksByClickingElementsOptions:

optionalclickOptions

clickOptions?: ClickOptions

Click options for use in Puppeteer's click handler.

optionalexclude

exclude?: readonly UrlPatternInput[]

An array of URL patterns. Matching URLs will not be enqueued.

Accepts glob pattern strings, { glob: string } objects, RegExp instances, or { regexp: RegExp } objects.

Glob matching is always case-insensitive. If you need case-sensitive matching, use a RegExp.

optionalforefront

forefront?: boolean = false

If set to true:

  • while adding the request to the queue: the request will be added to the foremost position in the queue.
  • while reclaiming the request: the request will be placed to the beginning of the queue, so that it's returned in the next call to RequestQueue.fetchNextRequest. By default, it's put to the end of the queue.

optionalinclude

include?: UrlPatternInput[]

An array of URL patterns that URLs must match to be enqueued.

Accepts glob pattern strings, { glob: string } objects, RegExp instances, or { regexp: RegExp } objects.

Glob matching is always case-insensitive. If you need case-sensitive matching, use a RegExp.

If include is an empty array or undefined, then the function enqueues all the intercepted navigation requests produced by the page after clicking on elements matching the provided CSS selector.

optionallabel

label?: string

Sets Request.label for newly enqueued requests.

optionalmaxWaitForPageIdleSecs

maxWaitForPageIdleSecs?: number = 5

This is the maximum period for which the function will keep tracking events, even if more events keep coming. Its purpose is to prevent a deadlock in the page by periodic events, often unrelated to the clicking itself. See waitForPageIdleSecs above for an explanation.

optionalonSkippedRequest

onSkippedRequest?: SkippedRequestCallback

When a request is skipped for some reason, you can use this callback to act on it. This is fired for requests skipped because they don't match enqueueLinks filters or because they were removed by transformRequestFunction.

page

page: Page

Puppeteer Page object.

requestManager

requestManager: IRequestManager
  • A request manager to which the URLs will be enqueued.

selector

selector: string

A CSS selector matching elements to be clicked on. Unlike in enqueueLinks, there is no default value. This is to prevent suboptimal use of this function by using it too broadly.

optionalskipNavigation

skipNavigation?: boolean = false

If set to true, tells the crawler to skip navigation and process the request directly.

optionaltransformRequestFunction

transformRequestFunction?: RequestTransform

After request options are filtered by include/exclude patterns, this function can be used to remove them or modify their contents such as userData, payload or, most importantly uniqueKey. This is useful when you need to enqueue multiple Requests to the queue that share the same URL, but differ in methods or payloads, or to dynamically update or create userData.

Example:

{
transformRequestFunction: (request) => {
request.userData.foo = 'bar';
return request;
}
}

Note that transformRequestFunction has the highest priority and can overwrite the global label option.

The function receives a RequestOptions object and can return either:

  • The modified RequestOptions object
  • 'unchanged' to keep the original options as-is
  • A falsy value or 'skip' to exclude the request from the queue

optionaluserData

userData?: Dictionary

Sets Request.userData for newly enqueued requests.

optionalwaitForPageIdleSecs

waitForPageIdleSecs?: number = 1

Clicking in the page triggers various asynchronous operations that lead to new URLs being shown by the browser. It could be a simple JavaScript redirect or opening of a new tab in the browser. These events often happen only some time after the actual click. Requests typically take milliseconds while new tabs open in hundreds of milliseconds.

To be able to capture all those events, the enqueueLinksByClickingElements() function repeatedly waits for the waitForPageIdleSecs. By repeatedly we mean that whenever a relevant event is triggered, the timer is restarted. As long as new events keep coming, the function will not return, unless the below maxWaitForPageIdleSecs timeout is reached.

You may want to reduce this for example when you're sure that your clicks do not open new tabs, or increase when you're not getting all the expected URLs.

Functions

isTargetRelevant

  • isTargetRelevant(page, target): boolean
  • We're only interested in pages created by the page we're currently clicking in. There will generally be a lot of other targets being created in the browser.


    Parameters

    • page: Page
    • target: Target

    Returns boolean