Skip to content

Commit

Permalink
Merge branch 'puppeteer:main' into infer-element-type-from-complex-se…
Browse files Browse the repository at this point in the history
…lector
  • Loading branch information
gomain committed Nov 11, 2022
2 parents ab25514 + b57b5b3 commit 06d83c6
Show file tree
Hide file tree
Showing 34 changed files with 250 additions and 330 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -255,6 +255,11 @@ jobs:
with:
node-version: ${{ matrix.node }}
- name: Set up ${{ matrix.pkg_manager }}
id: workaround
if: ${{ matrix.node == '14' && matrix.os == 'windows-latest' && matrix.pkg_manager == 'npm' }}
run: npm install -g ${{ matrix.pkg_manager }}@8.3
- name: Set up ${{ matrix.pkg_manager }}
if: ${{ steps.workaround.outcome == 'skipped' }}
run: npm install -g ${{ matrix.pkg_manager }}@latest
- name: Install dependencies
run: ${{ matrix.pkg_manager }} install
Expand Down
1 change: 1 addition & 0 deletions docs/api/index.md
Expand Up @@ -136,6 +136,7 @@ sidebar_label: API
| [launch](./puppeteer.launch.md) | |
| [networkConditions](./puppeteer.networkconditions.md) | |
| [PredefinedNetworkConditions](./puppeteer.predefinednetworkconditions.md) | A list of network conditions to be used with [Page.emulateNetworkConditions()](./puppeteer.page.emulatenetworkconditions.md). |
| [puppeteer](./puppeteer.puppeteer.md) | |

## Type Aliases

Expand Down
4 changes: 2 additions & 2 deletions docs/api/puppeteer.connect.md
Expand Up @@ -8,6 +8,6 @@ sidebar_label: connect

```typescript
connect: (
options: import('puppeteer-core/internal/common/Puppeteer.js').ConnectOptions
) => Promise<import('./types.js').Browser>;
options: import('puppeteer-core/internal/puppeteer-core.js').ConnectOptions
) => Promise<import('puppeteer-core/internal/puppeteer-core.js').Browser>;
```
4 changes: 2 additions & 2 deletions docs/api/puppeteer.createbrowserfetcher.md
Expand Up @@ -9,7 +9,7 @@ sidebar_label: createBrowserFetcher
```typescript
createBrowserFetcher: (
options: Partial<
import('puppeteer-core/internal/node/BrowserFetcher.js').BrowserFetcherOptions
import('puppeteer-core/internal/puppeteer-core.js').BrowserFetcherOptions
>
) => import('puppeteer-core/internal/node/BrowserFetcher.js').BrowserFetcher;
) => import('puppeteer-core/internal/puppeteer-core.js').BrowserFetcher;
```
2 changes: 1 addition & 1 deletion docs/api/puppeteer.defaultargs.md
Expand Up @@ -7,5 +7,5 @@ sidebar_label: defaultArgs
#### Signature:

```typescript
defaultArgs: (options?: import("puppeteer-core/internal/node/LaunchOptions.js").BrowserLaunchArgumentOptions | undefined) => string[]
defaultArgs: (options?: import("puppeteer-core/internal/puppeteer-core.js").BrowserLaunchArgumentOptions | undefined) => string[]
```
2 changes: 1 addition & 1 deletion docs/api/puppeteer.executablepath.md
Expand Up @@ -9,7 +9,7 @@ sidebar_label: executablePath
```typescript
executablePath: (
channel?:
| import('puppeteer-core/internal/node/LaunchOptions.js').ChromeReleaseChannel
| import('puppeteer-core/internal/puppeteer-core.js').ChromeReleaseChannel
| undefined
) => string;
```
4 changes: 2 additions & 2 deletions docs/api/puppeteer.launch.md
Expand Up @@ -9,7 +9,7 @@ sidebar_label: launch
```typescript
launch: (
options?:
| import('puppeteer-core/internal/node/PuppeteerNode.js').PuppeteerLaunchOptions
| import('puppeteer-core/internal/puppeteer-core.js').PuppeteerLaunchOptions
| undefined
) => Promise<import('./types.js').Browser>;
) => Promise<import('puppeteer-core/internal/puppeteer-core.js').Browser>;
```
24 changes: 3 additions & 21 deletions docs/api/puppeteer.puppeteer.md
@@ -1,29 +1,11 @@
---
sidebar_label: Puppeteer
sidebar_label: puppeteer
---

# Puppeteer class

The main Puppeteer class.

IMPORTANT: if you are using Puppeteer in a Node environment, you will get an instance of [PuppeteerNode](./puppeteer.puppeteernode.md) when you import or require `puppeteer`. That class extends `Puppeteer`, so has all the methods documented below as well as all that are defined on [PuppeteerNode](./puppeteer.puppeteernode.md).
# puppeteer variable

#### Signature:

```typescript
export declare class Puppeteer
puppeteer: PuppeteerNode;
```

## Remarks

The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `Puppeteer` class.

## Methods

| Method | Modifiers | Description |
| ----------------------------------------------------------------------------------------------------- | ------------------- | ---------------------------------------------------------------------- |
| [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. |
| [customQueryHandlerNames()](./puppeteer.puppeteer.customqueryhandlernames.md) | <code>static</code> | Gets the names of all custom query handlers. |
| [registerCustomQueryHandler(name, queryHandler)](./puppeteer.puppeteer.registercustomqueryhandler.md) | <code>static</code> | Registers a [custom query handler](./puppeteer.customqueryhandler.md). |
| [unregisterCustomQueryHandler(name)](./puppeteer.puppeteer.unregistercustomqueryhandler.md) | <code>static</code> | Unregisters a custom query handler for a given name. |
8 changes: 4 additions & 4 deletions docs/api/puppeteer.puppeteernode.createbrowserfetcher.md
Expand Up @@ -4,10 +4,6 @@ sidebar_label: PuppeteerNode.createBrowserFetcher

# PuppeteerNode.createBrowserFetcher() method

> Warning: This API is now obsolete.
>
> If you are using `puppeteer-core`, do not use this method. Just construct [BrowserFetcher](./puppeteer.browserfetcher.md) manually.
#### Signature:

```typescript
Expand All @@ -27,3 +23,7 @@ class PuppeteerNode {
[BrowserFetcher](./puppeteer.browserfetcher.md)

A new BrowserFetcher instance.

## Remarks

If you are using `puppeteer-core`, do not use this method. Just construct [BrowserFetcher](./puppeteer.browserfetcher.md) manually.
2 changes: 1 addition & 1 deletion packages/puppeteer-core/api-extractor.json
@@ -1,6 +1,6 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"mainEntryPointFilePath": "<projectFolder>/lib/esm/puppeteer/types.d.ts",
"mainEntryPointFilePath": "<projectFolder>/lib/esm/puppeteer/puppeteer-core.d.ts",
"bundledPackages": [],

"apiReport": {
Expand Down
3 changes: 1 addition & 2 deletions packages/puppeteer-core/package.json
Expand Up @@ -69,8 +69,7 @@
"src/templates/**"
],
"output": [
"src/generated/**",
"src/types.ts"
"src/generated/**"
]
},
"build:third_party": {
Expand Down
19 changes: 19 additions & 0 deletions packages/puppeteer-core/src/api/api.ts
@@ -0,0 +1,19 @@
/**
* Copyright 2022 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export * from './Browser.js';
export * from './BrowserContext.js';
export * from './Page.js';
18 changes: 11 additions & 7 deletions packages/puppeteer-core/src/common/AriaQueryHandler.ts
Expand Up @@ -15,12 +15,14 @@
*/

import {Protocol} from 'devtools-protocol';

import {assert} from '../util/assert.js';
import {CDPSession} from './Connection.js';
import {ElementHandle} from './ElementHandle.js';
import {Frame} from './Frame.js';
import {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorld.js';
import {PuppeteerQueryHandler} from './QueryHandler.js';
import {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorlds.js';

import type {ElementHandle} from './ElementHandle.js';
import type {PuppeteerQueryHandler} from './QueryHandler.js';
import type {Frame} from './Frame.js';

async function queryAXTree(
client: CDPSession,
Expand Down Expand Up @@ -115,7 +117,7 @@ const waitFor: PuppeteerQueryHandler['waitFor'] = async (
) => {
let frame: Frame;
let element: ElementHandle<Node> | undefined;
if (elementOrFrame instanceof Frame) {
if ('isOOPFrame' in elementOrFrame) {
frame = elementOrFrame;
} else {
frame = elementOrFrame.frame;
Expand Down Expand Up @@ -151,11 +153,13 @@ const waitFor: PuppeteerQueryHandler['waitFor'] = async (
if (element) {
await element.dispose();
}
if (!(result instanceof ElementHandle)) {

const handle = result?.asElement();
if (!handle) {
await result?.dispose();
return null;
}
return result.frame.worlds[MAIN_WORLD].transferHandle(result);
return handle.frame.worlds[MAIN_WORLD].transferHandle(handle);
};

const queryAll: PuppeteerQueryHandler['queryAll'] = async (
Expand Down
3 changes: 1 addition & 2 deletions packages/puppeteer-core/src/common/Frame.ts
Expand Up @@ -26,10 +26,9 @@ import {MouseButton} from './Input.js';
import {
IsolatedWorld,
IsolatedWorldChart,
MAIN_WORLD,
PUPPETEER_WORLD,
WaitForSelectorOptions,
} from './IsolatedWorld.js';
import {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorlds.js';
import {LifecycleWatcher, PuppeteerLifeCycleEvent} from './LifecycleWatcher.js';
import {Page} from '../api/Page.js';
import {getQueryHandlerAndSelector} from './QueryHandler.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/puppeteer-core/src/common/FrameManager.ts
Expand Up @@ -22,7 +22,8 @@ import {EventEmitter} from './EventEmitter.js';
import {EVALUATION_SCRIPT_URL, ExecutionContext} from './ExecutionContext.js';
import {Frame} from './Frame.js';
import {FrameTree} from './FrameTree.js';
import {IsolatedWorld, MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorld.js';
import {IsolatedWorld} from './IsolatedWorld.js';
import {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorlds.js';
import {NetworkManager} from './NetworkManager.js';
import {Page} from '../api/Page.js';
import {Target} from './Target.js';
Expand Down
20 changes: 4 additions & 16 deletions packages/puppeteer-core/src/common/IsolatedWorld.ts
Expand Up @@ -16,12 +16,10 @@

import {Protocol} from 'devtools-protocol';
import {source as injectedSource} from '../generated/injected.js';
import type PuppeteerUtil from '../injected/injected.js';
import {assert} from '../util/assert.js';
import {createDeferredPromise} from '../util/DeferredPromise.js';
import {isErrorLike} from '../util/ErrorLike.js';
import {CDPSession} from './Connection.js';
import {ElementHandle} from './ElementHandle.js';
import {ExecutionContext} from './ExecutionContext.js';
import {Frame} from './Frame.js';
import {FrameManager} from './FrameManager.js';
Expand All @@ -33,6 +31,10 @@ import {TimeoutSettings} from './TimeoutSettings.js';
import {EvaluateFunc, HandleFor, InnerLazyParams, NodeFor} from './types.js';
import {createJSHandle, debugError, pageBindingInitString} from './util.js';
import {TaskManager, WaitTask} from './WaitTask.js';
import {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorlds.js';

import type PuppeteerUtil from '../injected/injected.js';
import type {ElementHandle} from './ElementHandle.js';

/**
* @public
Expand Down Expand Up @@ -70,20 +72,6 @@ export interface PageBinding {
pptrFunction: Function;
}

/**
* A unique key for {@link IsolatedWorldChart} to denote the default world.
* Execution contexts are automatically created in the default world.
*
* @internal
*/
export const MAIN_WORLD = Symbol('mainWorld');
/**
* A unique key for {@link IsolatedWorldChart} to denote the puppeteer world.
* This world contains all puppeteer-internal bindings/code.
*
* @internal
*/
export const PUPPETEER_WORLD = Symbol('puppeteerWorld');
/**
* @internal
*/
Expand Down
30 changes: 30 additions & 0 deletions packages/puppeteer-core/src/common/IsolatedWorlds.ts
@@ -0,0 +1,30 @@
/**
* Copyright 2022 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* A unique key for {@link IsolatedWorldChart} to denote the default world.
* Execution contexts are automatically created in the default world.
*
* @internal
*/
export const MAIN_WORLD = Symbol('mainWorld');
/**
* A unique key for {@link IsolatedWorldChart} to denote the puppeteer world.
* This world contains all puppeteer-internal bindings/code.
*
* @internal
*/
export const PUPPETEER_WORLD = Symbol('puppeteerWorld');
3 changes: 2 additions & 1 deletion packages/puppeteer-core/src/common/Page.ts
Expand Up @@ -57,7 +57,8 @@ import {FrameManager, FrameManagerEmittedEvents} from './FrameManager.js';
import {HTTPRequest} from './HTTPRequest.js';
import {HTTPResponse} from './HTTPResponse.js';
import {Keyboard, Mouse, MouseButton, Touchscreen} from './Input.js';
import {MAIN_WORLD, WaitForSelectorOptions} from './IsolatedWorld.js';
import {WaitForSelectorOptions} from './IsolatedWorld.js';
import {MAIN_WORLD} from './IsolatedWorlds.js';
import {JSHandle} from './JSHandle.js';
import {
Credentials,
Expand Down
7 changes: 2 additions & 5 deletions packages/puppeteer-core/src/common/QueryHandler.ts
Expand Up @@ -18,11 +18,8 @@ import PuppeteerUtil from '../injected/injected.js';
import {ariaHandler} from './AriaQueryHandler.js';
import {ElementHandle} from './ElementHandle.js';
import {Frame} from './Frame.js';
import {
MAIN_WORLD,
PUPPETEER_WORLD,
WaitForSelectorOptions,
} from './IsolatedWorld.js';
import {WaitForSelectorOptions} from './IsolatedWorld.js';
import {MAIN_WORLD, PUPPETEER_WORLD} from './IsolatedWorlds.js';

/**
* @public
Expand Down
20 changes: 20 additions & 0 deletions packages/puppeteer-core/src/common/bidi/bidi.ts
@@ -0,0 +1,20 @@
/**
* Copyright 2022 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export * from './Browser.js';
export * from './BrowserContext.js';
export * from './Page.js';
export * from './Connection.js';

0 comments on commit 06d83c6

Please sign in to comment.