Skip to content

Commit e52b47b

Browse files
committed
First commit
1 parent ee4ba03 commit e52b47b

18 files changed

+3344
-486
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/.git* export-ignore
2+
/bin/ export-ignore
23
/docs/ export-ignore
34
/tests/ export-ignore
45
/.php-cs-fixer* export-ignore

.github/workflows/CI.yaml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: "CI"
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
cs:
15+
name: "Code style"
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: "Git: checkout"
19+
uses: actions/checkout@v4
20+
21+
- name: "PHP: setup 8.3"
22+
uses: shivammathur/setup-php@v2
23+
with:
24+
php-version: '8.3'
25+
coverage: none
26+
tools: php-cs-fixer
27+
28+
- name: "Composer: validate"
29+
run: composer validate --strict
30+
31+
- name: "Composer: install"
32+
run: composer install --prefer-dist --no-interaction --no-progress
33+
34+
- name: "Php-CS-Fixer: version"
35+
run: php-cs-fixer -V
36+
37+
- name: "Php-CS-Fixer: check"
38+
run: php-cs-fixer fix --diff --dry-run
39+
40+
sa:
41+
name: "Static Analysis"
42+
runs-on: ubuntu-latest
43+
steps:
44+
- name: "Git: checkout"
45+
uses: actions/checkout@v4
46+
47+
- name: "PHP: setup 8.4"
48+
uses: shivammathur/setup-php@v2
49+
with:
50+
php-version: '8.4'
51+
coverage: pcov
52+
tools: phpstan
53+
54+
- name: "Composer: install"
55+
run: composer install --prefer-dist --no-interaction --no-progress
56+
57+
- name: "PHPStan: version"
58+
run: phpstan --version
59+
60+
- name: "PHPStan: analyze"
61+
run: phpstan analyze --memory-limit=-1
62+
63+
unit-tests:
64+
name: "Unit Tests (PHP ${{ matrix.php-version }})"
65+
runs-on: ubuntu-latest
66+
strategy:
67+
matrix:
68+
php-version: ['8.3', '8.4']
69+
fail-fast: false
70+
steps:
71+
- name: "Git: checkout"
72+
uses: actions/checkout@v4
73+
74+
- name: "PHP: setup ${{ matrix.php-version }}"
75+
uses: shivammathur/setup-php@v2
76+
with:
77+
php-version: ${{ matrix.php-version }}
78+
coverage: pcov
79+
tools: phpunit
80+
81+
- name: "Composer: install"
82+
run: composer install --prefer-dist --no-interaction --no-progress
83+
84+
- name: "PHPUnit: version"
85+
run: phpunit --version
86+
87+
- name: "PHPUnit: unit tests"
88+
run: phpunit --testsuite=unit

.github/workflows/update.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Update descriptors
2+
3+
on:
4+
# schedule:
5+
# - cron: '0 2 * * *' # Every night at 02:00 UTC
6+
workflow_dispatch: {}
7+
8+
jobs:
9+
update:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Setup PHP
17+
uses: shivammathur/setup-php@v2
18+
with:
19+
php-version: '8.4'
20+
coverage: none
21+
tools: composer
22+
23+
- name: Install dependencies
24+
run: composer install --prefer-dist --no-interaction --no-progress
25+
26+
- name: Update device descriptors
27+
run: php bin/update.php
28+
29+
- name: Convert descriptors in PHP
30+
run: php bin/converter.php
31+
32+
- name: Update markdown files
33+
run: php bin/update-docs.php

.php-cs-fixer.dist.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?php
22

33
$license = <<<LICENSE
4-
This file is part of the Playwright PHP community project.
5-
For the full copyright and license information, please view
6-
the LICENSE file that was distributed with this source code.
4+
This file is part of the community-maintained Playwright PHP project.
5+
It is not affiliated with or endorsed by Microsoft.
6+
7+
(c) 2025-Present - Playwright PHP <https://github.com/playwright-php>
8+
9+
For the full copyright and license information, please view the LICENSE
10+
file that was distributed with this source code.
711
LICENSE;
812

913
$finder = (new PhpCsFixer\Finder())

README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<div align="center">
2+
<a href="https://github.com/playwright-php"><img src="https://github.com/playwright-php/.github/raw/main/profile/playwright-php.png" alt="Playwright PHP" /></a>
3+
4+
&nbsp; ![PHP Version](https://img.shields.io/badge/PHP-8.3+-05971B?labelColor=09161E&color=1D8D23&logoColor=FFFFFF)
5+
&nbsp; ![CI](https://img.shields.io/github/actions/workflow/status/playwright-php/devices/CI.yaml?branch=main&label=Tests&color=1D8D23&labelColor=09161E&logoColor=FFFFFF)
6+
&nbsp; ![Release](https://img.shields.io/github/v/release/playwright-php/devices?label=Stable&labelColor=09161E&color=1D8D23&logoColor=FFFFFF)
7+
&nbsp; ![License](https://img.shields.io/github/license/playwright-php/devices?label=License&labelColor=09161E&color=1D8D23&logoColor=FFFFFF)
8+
9+
</div>
10+
11+
# Playwright PHP Device Descriptors
12+
13+
[Microsoft Playwright](https://github.com/microsoft/playwright) ships an official catalogue
14+
of [device descriptors](https://github.com/microsoft/playwright/blob/main/packages/playwright-core/src/server/deviceDescriptorsSource.json).
15+
16+
This package mirrors that list for PHP by exporting the JSON data to `data/devices.php`, and exposes a `DeviceRegistry`
17+
class to retrieve device descriptors by name.
18+
19+
## Installation
20+
21+
```bash
22+
composer require playwright-php/devices
23+
```
24+
25+
## Usage
26+
27+
```php
28+
use Playwright\Device\DeviceRegistry;
29+
30+
$iphone = (new DeviceRegistry())->get('iPhone 15 Pro');
31+
32+
// Pass the device properties to a new browser context:
33+
$browser->newContext([
34+
'userAgent' => $iphone->getUserAgent(),
35+
'viewport' => $iphone->getViewport(),
36+
'isMobile' => $iphone->isMobile(),
37+
'hasTouch' => $iphone->hasTouch(),
38+
]);
39+
40+
// Or more simply:
41+
$browser->newContext($iphone->toArray());
42+
```
43+
44+
## Device descriptors
45+
46+
Explore the full catalogue in [`docs/DEVICES.md`](docs/DEVICES.md).
47+
48+
### Desktop devices
49+
50+
| Device | Browser | Viewport | Scale | Mobile | Touch |
51+
|-----------------------|----------|------------|-------|--------|-------|
52+
| Desktop Chrome | Chromium | 1280 x 720 | 1 | No | No |
53+
| Desktop Chrome HiDPI | Chromium | 1280 x 720 | 2 | No | No |
54+
| Desktop Edge | Chromium | 1280 x 720 | 1 | No | No |
55+
| Desktop Edge HiDPI | Chromium | 1280 x 720 | 2 | No | No |
56+
| Desktop Firefox | Firefox | 1280 x 720 | 1 | No | No |
57+
| Desktop Firefox HiDPI | Firefox | 1280 x 720 | 2 | No | No |
58+
| Desktop Safari | Webkit | 1280 x 720 | 2 | No | No |
59+
60+
### Mobile devices
61+
62+
| Device | Browser | Viewport | Scale | Screen | Viewport |
63+
|---------------------|----------|------------|-------|------------|----------|
64+
| LG Optimus L70 | Chromium | 640 x 384 | 1.25 | 384 x 640 | Yes |
65+
| iPhone 15 Pro Max | Webkit | 814 x 380 | 3 | 430 x 739 | Yes |
66+
| Kindle Fire HDX | Webkit | 1280 x 800 | 2 | 800 x 1280 | Yes |
67+
| Microsoft Lumia 550 | Chromium | 640 x 360 | 2 | 360 x 640 | Yes |
68+
| Pixel 7 | Chromium | 863 x 360 | 2.63 | 412 x 839 | Yes |
69+
70+
## License
71+
72+
This package is released by the [Playwright PHP](https://playwright-php.dev)
73+
project under the MIT License. See the [LICENSE](LICENSE) file for details.

bin/converter.php

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)