Skip to content

Commit 01e2604

Browse files
committed
update changelog and readme
1 parent 3a08fd2 commit 01e2604

File tree

2 files changed

+83
-10
lines changed

2 files changed

+83
-10
lines changed

CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414

1515
## 0.2.2
1616

17-
> *20xx-xx-xx* (not released)
18-
19-
> Added input controls
17+
> *2018-08-28*
2018
2119
* Features:
2220
* Added mouse api (move, click)
21+
* Page info are now in sync with the browser
22+
* Added a shortcut to get current page url: ``Page::getCurrentUrl``
23+
* Added ability to get and set cookies from a page: ``Page.setCookies``, ``Page.readCookies`` , ``Page.readAllCookies``
24+
* improved some error reporting
25+
* fixed a bug with directory creation for screenshots
26+
* added ability to set custom user agent: ``Page::setUserAgent`` or via factory option ``userAgent``
2327
* Bug fixes:
2428
* none
2529

README.md

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,15 @@ API
127127

128128
Here are the options available for the browser factory:
129129

130-
| Option name | Default | Description |
131-
|--------------------|-----------------------|---------------------------------------------------------------------------------|
132-
| connectionDelay | 0 | Delay to apply between each operation for debugging purposes |
130+
| Option name | Default | Description |
131+
|--------------------|-----------------------|-----------------------------------------------------------------------------------|
132+
| connectionDelay | 0 | Delay to apply between each operation for debugging purposes |
133133
| debugLogger | null | A string (e.g "php://stdout"), or resource, or PSR-3 logger instance to print debug messages |
134-
| enableImages | true | Toggles loading of images |
135-
| headless | true | Enable or disable headless mode |
136-
| userDataDir | none | chrome user data dir (default: a new empty dir is generated temporarily) |
137-
| startupTimeout | 30 | Maximum time in seconds to wait for chrome to start |
134+
| enableImages | true | Toggles loading of images |
135+
| headless | true | Enable or disable headless mode |
136+
| userAgent | none | User agent to use for the whole browser (see page api for alternative) |
137+
| userDataDir | none | chrome user data dir (default: a new empty dir is generated temporarily) |
138+
| startupTimeout | 30 | Maximum time in seconds to wait for chrome to start |
138139
| windowSize | - | Size of the window. usage: ``[$width, $height]`` - see also Page::setViewportSize |
139140

140141
### Browser API
@@ -299,6 +300,74 @@ The mouse API is dependent on the page instance and allows you to control the mo
299300
$page->waitForReload();
300301
```
301302

303+
### Cookie API
304+
305+
You can set and get cookies for a page:
306+
307+
#### Set Cookie
308+
309+
```php
310+
use HeadlessChromium\Cookies\Cookie;
311+
312+
$page = $browser->createPage();
313+
314+
// example 1: set cookies for a given domain
315+
316+
$page->setCookies([
317+
Cookie::create('name', 'value', [
318+
'domain' => 'example.com',
319+
'expires' => time() + 3600 // expires in 1 day
320+
])
321+
])->await();
322+
323+
324+
// example 2: set cookies for the current page
325+
326+
$page->navigate('http://example.com')->waitForNavigation();
327+
328+
$page->setCookies([
329+
Cookie::create('name', 'value', ['expires'])
330+
])->await();
331+
332+
```
333+
334+
#### Get Cookies
335+
336+
```php
337+
use HeadlessChromium\Cookies\Cookie;
338+
339+
$page = $browser->createPage();
340+
341+
// example 1: get all cookies for the browser
342+
343+
$cookies = $page->getAllCookies();
344+
345+
// example 2: get cookies for the current page
346+
347+
$page->navigate('http://example.com')->waitForNavigation();
348+
$cookies = $page->getCookies();
349+
350+
// filter cookies with name == 'foo'
351+
$cookiesFoo = $cookies->filterBy('name', 'foo');
352+
353+
// find first cookie with name == 'bar'
354+
$cookieBar = $cookies->findOneBy('name', 'bar');
355+
if ($cookieBar) {
356+
// do something
357+
}
358+
359+
```
360+
361+
### Set user agent
362+
363+
You can set an user agent per page :
364+
365+
```php
366+
$page->setUserAgent('my user agent');
367+
```
368+
369+
See also BrowserFactory option ``userAgent`` to set it for the whole browser.
370+
302371

303372
------------------------------------------------------------------------------------------------------------------------
304373

0 commit comments

Comments
 (0)