diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 09580b92f4c30..314063230ca2e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -320,42 +320,10 @@ jobs: run: 'exit 1' - run: 'exit 0' - installation-test-build: - name: Build installation test - runs-on: ubuntu-latest - needs: check-changes - outputs: - node-version: ${{ steps.node-version.outputs.node }} - if: ${{ !startsWith(github.ref_name, 'release-please') && contains(fromJSON(needs.check-changes.outputs.changes), 'puppeteer') }} - steps: - - name: Checkout - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 - - name: Set up Node.js - uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 - with: - cache: npm - node-version-file: '.nvmrc' - - name: Config Node.JS for installation test run - id: node-version - run: echo "node=$(cat .nvmrc)" >> "$GITHUB_OUTPUT" - - name: Install dependencies - run: npm ci - env: - PUPPETEER_SKIP_DOWNLOAD: true - - name: Build installation test - run: npm run build --workspace @puppeteer-test/installation - - name: Pack installation test - run: npm pack --workspace @puppeteer-test/installation - - name: Upload installation test - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3 - with: - name: installation-test - path: puppeteer-test-installation-latest.tgz - installation-test: name: ${{ matrix.pkg_manager }} installation on ${{ matrix.os }} - needs: installation-test-build - if: ${{ !startsWith(github.ref_name, 'release-please') }} + needs: check-changes + if: ${{ !startsWith(github.ref_name, 'release-please') && contains(fromJSON(needs.check-changes.outputs.changes), 'puppeteer') }} runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -374,22 +342,34 @@ jobs: - linux-only: true os: macos-13 steps: - - name: Download installation test - uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7 - with: - name: installation-test - - name: Unpack installation test - run: tar -xf puppeteer-test-installation-latest.tgz --strip-components 1 -C . + - name: Check out repository + uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 - name: Set up Node.js uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 with: - node-version: ${{ needs.installation-test-build.outputs.node-version }} + cache: npm + node-version-file: '.nvmrc' - name: Install dependencies - run: ${{ matrix.pkg_manager }} install - - name: Test + run: npm ci + env: + PUPPETEER_SKIP_DOWNLOAD: true + # Set up GitHub Actions caching for Wireit. + - uses: google/wireit@4aad131006ea85c1e42af927534ebb13426dd730 # setup-github-actions-caching/v1.0.2 + - name: Build packages + run: npm run build --workspace @puppeteer-test/test + - name: Setup cache for Chrome binary + uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 + with: + path: ~/.cache/puppeteer/chrome + key: Chrome-${{ runner.os }}-${{ hashFiles('packages/puppeteer-core/src/revisions.ts') }}-${{ hashFiles('packages/puppeteer/src/node/install.ts') }} + - name: Install Chrome + run: npm run postinstall + - name: Build installation test + run: npm run build --workspace @puppeteer-test/installation + - name: Test install env: PKG_MANAGER: ${{ matrix.pkg_manager }} - run: ${{ matrix.pkg_manager }} test + run: ${{ matrix.pkg_manager }} run test-install installation-test-required: name: '[Required] Installation tests' diff --git a/docker/Dockerfile b/docker/Dockerfile index 4abecc0d6a4da..5ccd5c7a59043 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,8 @@ FROM node:20@sha256:cb7cd40ba6483f37f791e1aace576df449fc5f75332c19ff59e2c6064797160e +# Configure default locale (important for chrome-headless-shell). +ENV LANG en_US.UTF-8 + # Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others) # Note: this installs the necessary libs to make the bundled version of Chrome that Puppeteer # installs, work. diff --git a/docs/api/index.md b/docs/api/index.md index aa62b2a768885..409fecfe82cc9 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -23,6 +23,16 @@ Description The Accessibility class provides methods for inspecting the browser's accessibility tree. The accessibility tree is used by assistive technology such as [screen readers](https://en.wikipedia.org/wiki/Screen_reader) or [switches](https://en.wikipedia.org/wiki/Switch_access). +**Remarks:** + +Accessibility is a very platform-specific thing. On different platforms, there are different screen readers that might have wildly different output. + +Blink - Chrome's rendering engine - has a concept of "accessibility tree", which is then translated into different platform-specific APIs. Accessibility namespace gives users access to the Blink Accessibility Tree. + +Most of the accessibility tree gets filtered out when converting from Blink AX Tree to Platform-specific AX-Tree or by assistive technologies themselves. By default, Puppeteer tries to approximate this filtering, exposing only the "interesting" nodes of the tree. + +The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `Accessibility` class. + @@ -36,6 +46,10 @@ The Accessibility class provides methods for inspecting the browser's accessibil [Browser](./puppeteer.browser.md) [emits](./puppeteer.eventemitter.emit.md) various events which are documented in the [BrowserEvent](./puppeteer.browserevent.md) enum. +**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 `Browser` class. + @@ -51,6 +65,10 @@ When a [browser](./puppeteer.browser.md) is launched, it has a single [browser c If a [page](./puppeteer.page.md) opens another [page](./puppeteer.page.md), e.g. using `window.open`, the popup will belong to the parent [page's browser context](./puppeteer.page.browsercontext.md). +**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 `BrowserContext` class. + @@ -60,6 +78,14 @@ If a [page](./puppeteer.page.md) opens another [page](./puppeteer.page.md), e.g. The `CDPSession` instances are used to talk raw Chrome Devtools Protocol. +**Remarks:** + +Protocol methods can be called with [CDPSession.send()](./puppeteer.cdpsession.send.md) method and protocol events can be subscribed to with `CDPSession.on` method. + +Useful links: [DevTools Protocol Viewer](https://chromedevtools.github.io/devtools-protocol/) and [Getting Started with DevTools Protocol](https://github.com/aslushnikov/getting-started-with-cdp/blob/HEAD/README.md). + +The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `CDPSession` class. + @@ -85,6 +111,10 @@ ConsoleMessage objects are dispatched by page via the 'console' event. The Coverage class provides methods to gather information about parts of JavaScript and CSS that were used by the page. +**Remarks:** + +To output coverage in a form consumable by [Istanbul](https://github.com/istanbuljs), see [puppeteer-to-istanbul](https://github.com/istanbuljs/puppeteer-to-istanbul). + @@ -101,6 +131,12 @@ The Coverage class provides methods to gather information about parts of JavaScr Device request prompts let you respond to the page requesting for a device through an API like WebBluetooth. +**Remarks:** + +`DeviceRequestPrompt` instances are returned via the [Page.waitForDevicePrompt()](./puppeteer.page.waitfordeviceprompt.md) method. + +The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `DeviceRequestPrompt` class. + @@ -110,6 +146,10 @@ Device request prompts let you respond to the page requesting for a device throu Device in a request prompt. +**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 `DeviceRequestPromptDevice` class. + @@ -119,6 +159,10 @@ Device in a request prompt. Dialog instances are dispatched by the [Page](./puppeteer.page.md) via the `dialog` event. +**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 `Dialog` class. + @@ -128,6 +172,31 @@ Dialog instances are dispatched by the [Page](./puppeteer.page.md) via the `dial ElementHandle represents an in-page DOM element. +**Remarks:** + +ElementHandles can be created with the [Page.$()](./puppeteer.page._.md) method. + +```ts +import puppeteer from 'puppeteer'; + +(async () => { + const browser = await puppeteer.launch(); + const page = await browser.newPage(); + await page.goto('https://example.com'); + const hrefElement = await page.$('a'); + await hrefElement.click(); + // ... +})(); +``` + +ElementHandle prevents the DOM element from being garbage-collected unless the handle is [disposed](./puppeteer.jshandle.dispose.md). ElementHandles are auto-disposed when their origin frame gets navigated. + +ElementHandle instances can be used as arguments in [Page.$eval()](./puppeteer.page._eval.md) and [Page.evaluate()](./puppeteer.page.evaluate.md) methods. + +If you're using TypeScript, ElementHandle takes a generic argument that denotes the type of element the handle is holding within. For example, if you have a handle to a `