Commit Graph

435 Commits

Author SHA1 Message Date
Andrey Lushnikov
90ca007367
fix(Launcher): handle SIGHUP signal (#1405)
The SIGHUP signal is sent whenever the controlling terminal is closed.

On Windows, SIGHUP is emulated by libuv, and will be the only signal we
receive before the application will be terminated.

This patch starts handling SIGHUP in the same way we handle SIGTERM.

Fixes #1367.
2017-11-16 19:28:32 -08:00
Octavian Cioaca
a350e89381 chore(Browser): fix jsdoc in Browser.create method (#1403) 2017-11-16 16:28:52 -08:00
Andrey Lushnikov
cc0c461ea8
fix(Launcher): handle SIGTERM by default (#1402)
SIGTERM signal is widely used to notify application that it will be shut down.

This patch starts listening to SIGTERM event to gracefully retire
chromium instance.

References #1047.
2017-11-16 14:26:32 -08:00
Christopher Dieringer
b0b22199f9 fix(ElementHandle.screenshot): account for scroll (#1323)
Currently, `elementHandle.screenshot` passes bounding box into the `page.captureScreenshot` 
method.
This is wrong since `captureScreenshot` accepts viewport, not bounding box.

This patch uses layout metrics to convert bounding box into viewport.

Fixes #1315.
2017-11-10 16:02:52 -08:00
Andrey Lushnikov
2c8f658815
fix(Navigation): wait for lifecycle events for the frame subtree (#1356)
Currently, we wait only for the main frame to reach the desired
lifecycle state.

This patch starts waiting until all the frames reach the desired
lifecycle state.

Fixes #1173.
2017-11-10 15:44:14 -08:00
JoelEinbinder
f8d19e79e7 fix(Page.waitForSelector): "visible" option should check parent visibility (#1354)
This patch starts checking for boundingClientRect to make sure that the
element is visible.
2017-11-10 15:44:01 -08:00
Andrey Lushnikov
44d1e834a4
fix(Navigation): correctly wait for navigation in Page.goto (#1355)
This patch:
- starts persisting lifecycle state for every frame
- migrates NavigationWatcher to rely on these lifecycle events
- refactors Page.goto to properly return navigation errors

Fixes #1218.
2017-11-10 15:33:14 -08:00
Alix Axel
7d18275fb9 Test: add tests to cover clicking checkbox (#1125)
This patch adds tests to make sure clicking both checkbox and its label
works.

These are regression tests to cover the upstream fix, rolled in #1299.
2017-11-07 20:38:22 -08:00
Andrey Lushnikov
cbe3dc58a2
Revert "feat(Page): teach Page.setContent to wait for resources to load (#1152)" (#1312)
This reverts commit 80ee469429.

Lifecycle events are not ready yet to support the setContent scenario.
The prerequisite for this is
https://chromium-review.googlesource.com/c/chromium/src/+/747805 that
might not land soon due to technical concerns.
2017-11-07 14:18:05 -08:00
JoelEinbinder
b58d319926 fix(Page.click): throw a meaningful message for invisible elements (#1309)
This patch starts throwing a meaningful error message when trying to click the hidden
node.

References #1294
2017-11-07 13:54:40 -08:00
JoelEinbinder
3cb0f1af34 fix: make exposeFunction work for frames (#1295)
This patch fixes page.exposeFunction method so that it
adds exposed binding to all existing frames.

Fixes #690
2017-11-07 13:26:23 -08:00
Schelkun
77f585298f feat(Page): introduce Page bringToFront method (#1252)
This patch introduces Page.bringToFront method to activate tabs.

Fixes #1244
2017-11-07 13:17:36 -08:00
Robert Sköld
cc5e8a9bd4 fix(Page.type): Add assertion to page.type() (#1301)
This patch starts throwing a nice error when `page.type` is called
with non-existent selector.
2017-11-07 03:07:51 -08:00
Xingan Wang
8e445734c6 feat(Frame): reject error for addScriptTag/addStyleTag (#1287)
fix #1221
2017-11-06 22:04:40 -08:00
Andrey Lushnikov
5e154dc835
fix(Page.select): assert all values are of type "string". (#1280)
This patch starts asserting that all values are of type "string".

The alternative approach to cast values to strings
might yield a hard-to-debug errors.

Fixes #1276.
2017-11-03 19:20:12 -07:00
Adi Prasetyo
03fefb53f8 feat(browser): add browser.disconnected event (#960)
This patch adds a 'disconnected' event for the browser. The event is issued
when the "browser" loses connection to the chrome process.

References #952
2017-11-03 18:46:17 -07:00
Andrey Lushnikov
88ba52a363
refactor: use Page.getFrameTree instead of Page.getResourceTree (#1275)
This patch starts using Page.getFrameTree instead of
Page.getResourceTree.

The resource tree is experimental, whereas the frame tree is not.
2017-11-03 18:37:21 -07:00
Xingan Wang
e0f5b93923 feat(Frame): addStyleTag and addScriptTag now return ElementHandles.
This patch teaches `page.addStyleTag` and `page.addScriptTag` to return ElementHandles
to the added tags.

Fixes #1179.
2017-11-03 00:05:38 -07:00
Andrey Lushnikov
ac55e69676
feat(Chromium): roll chromium to r513435. (#1259)
This roll brings in a bunch of important patches:
- crrev.com/512647 Changed headless browser profile dir to use Default profile path
- crrev.com/512760 DevTools: stop idleness detector when pending navigation commits
- crrev.com/512905 DevTools: introduce Page.getFrameTree
- crrev.com/513373 DevTools: report loaderId in the lifecycle events
- crrev.com/513419 DevTools: introduce Page.setLifecycleEventsEnabled
- crrev.com/513422 DevTools: return loaderId from Page.navigate

Fixes #921 

BREAKING CHANGE:

Headless user profile structure is changing. Custom profiles set with --user-data-dir flag will no longer be read in Chrome 63 and will have to be recreated.

Alternatively, you can migrate old headless profile to a new structure. if you stored your profile in `<profile>` folder, you would run the following bash commands:

```bash
cd <profile>
mkdir Default
mv * Default
```

Full headless-dev PSA announcement: https://groups.google.com/a/chromium.org/forum/#!msg/headless-dev/asX8WgktXIE/zTUfmHDcAQAJ
2017-11-02 13:26:21 -07:00
Suvrat Jain
fede2643ac feat(Frame): introduce Frame.select
This patch adds `Frame.select` method that does the same functionality as
former `Page.select`, but on a per-frame level.

The `Page.select` method becomes a shortcut for the ÷main frame's select.

Fixes #1139
2017-11-01 22:06:04 -07:00
Andrey Lushnikov
f5bb333cd0
fix: support PlzNavigate in puppeteer. (#1239)
This patch migrates puppeteer to support PlzNavigate chromium
project.

As a consequence of this patch, we no longer wait for both
requestWillBeSent and requestIntercepted events to happen. This should
resolve a ton of request interception bugs that "hanged" the loading.

Fixes #877.
2017-11-01 14:04:10 -07:00
Andrey Lushnikov
b9266c74f8
feat(Page): rename Page.getMetrics into Page.metrics (#1240)
BREAKING CHANGE: method page.getMetrics() got renamed into
page.metrics().
2017-11-01 13:39:31 -07:00
Andrey Lushnikov
9f071bf411
fix(Navigation): do not race with security error for navigation (#1237)
Currently, NavigationWatcher listens to lifecycle events from Page
domain and security events from Security domain.

However, the events are dispatched from different processes in browser:
- Page's lifecycle events are dispatched from renderer process
- Security events are dispatched from browser process

This makes for the undefined order between events and results in
NavigationWatcher reporting different failuer messages, based on
the event order.

This patch stops relying on security errors in navigation watcher and
instead switches to request failure codes for the main resource.

Fixes #1195
2017-11-01 13:28:00 -07:00
AlexChung1995
e70f98ddb9 feat(Page.select): return selected options from Page.select (#1099)
This patch teaches Page.select to return an array of actually selected options.
If no option is selected, an empty array will be returned.
2017-10-31 21:47:52 -07:00
Manoj Patel
9f19641a3d chore: Fix typo in comment for Events (#1234) 2017-10-31 16:10:18 -07:00
Andrey Lushnikov
c9a26e11f1
fix(ElementHandle): teach ElementHandle to work with shadowdom (#1227)
Elements in shadow dom erroneously considered that they were detached
from document.

This patch starts using `Element.isConnected` instead of
`document.contains()` call.

Fixes #1061.
2017-10-31 12:02:16 -07:00
Adam Stankiewicz
5ffbd0d221 feat(ElementHandle): add ElementHandle.$ and ElementHandle.$$ (#1151)
This patch adds `ElementHandle.$` and `ElementHandle.$$` methods to query nested
elements.

Fixes #508
2017-10-27 02:08:58 -07:00
JoelEinbinder
655b94db47 fix(touch): requestAnimationFrame before sending tap (#1142)
This patch adds a work-around for the upstream bug, issuing double-raf before emulating touch event.

References #673
2017-10-26 14:53:50 -07:00
Andrey Lushnikov
ab9b34cd5d fix(Launcher): force-kill chrome on process exit and interruption (#1155)
This patch starts force-killing chromium regardless of custom userdata
directory when the node process exits.

References #1047
2017-10-24 16:05:12 -07:00
Andrey Lushnikov
b9ab6fe4bb fix(interception): Disable newtork caching when intercepting (#1154)
Request interception might not work properly if caching is enabled.
2017-10-24 15:14:25 -07:00
Andrey Lushnikov
ce005d480c feat(Chromium): Roll chromium to r511134 (#1153)
This roll includes:
- crrev.com/510651 that changes request interception methods in protocol
- s/Page.setRequestInterceptionEnabled/Page.setRequestInterception

BREAKING CHANGE

Page.setRequestInterceptionEnabled is renamed into
Page.setRequestInterception.
2017-10-24 14:45:03 -07:00
Andrey Lushnikov
80ee469429 feat(Page): teach Page.setContent to wait for resources to load (#1152)
This patch adds "options" parameter to the `page.setContent` method. The
parameter is the same as a navigation parameter and allows to specify
maximum timeout to wait for resources to be loaded, as well as to
describe events that should be emitted before the setContent operation
would be considered successful.

Fixes #728.
2017-10-24 13:57:39 -07:00
Andrey Lushnikov
f38c8bb17b feat(Page.goto): support multiple events in waitUntil option (#1147)
This patch adds support to multiple events that could be passed inside
navigation methods:
- Page.goto
- Page.waitForNavigation
- Page.goForward
- Page.goBack
- Page.reload

Fixes #805
2017-10-24 10:05:15 -07:00
Andrey Lushnikov
ef369e5d5d feat(Page.goto): add a 'domcontentloaded' option to the Page.goto (#1145)
This patch adds a new `domcontentloaded` option to a bunch of navigation
methods:
- Page.goto
- Page.waitForNavigation
- Page.goBack
- Page.goForward
- Page.reload

Fixes #946.
2017-10-24 00:35:18 -07:00
Andrey Lushnikov
ce8a952044 refactor: migrate NavigatorWatcher to lifecycle events (#1141)
This patch:
- migrates navigation watcher to use protocol-issued lifecycle events.
- removes `networkIdleTimeout` and `networkIdleInflight` options for
  `page.goto` method
- adds a new `networkidle0` value to the waitUntil option of navigation
  methods

References #728.

BREAKING CHANGE:

As an implication of this new approach, the `networkIdleTimeout` and
`networkIdleInflight` options are no longer supported. Interested
clients should implement the behavior themselves using the `request` and
`response` events.
2017-10-23 18:10:59 -07:00
JoelEinbinder
126ab7b90e feat(keyboard): Accept codes (#1116)
BREAKING CHANGE:

This patch lets key names be code in addition to key. When specifying a code, the proper text is generated assuming a standard US keyboard layout. e.g Digit5 -> "5" or "%" depending on Shift.

* location is now specified. #777

* Using unknown key names now throws an error. #723

* Typing newlines now correctly presses enter. #681
2017-10-23 12:43:45 -07:00
Andrey Lushnikov
bcc969ccc4 feat(interception): Implement request.mockResponse method (#1064)
feat(interception): Implement request.respond method

This patch implements a new Request.respond method. This
allows users to fulfill the intercepted request with a hand-crafted
response if they wish so.

References #1020.
2017-10-20 16:55:15 -07:00
Andrey Lushnikov
5c92ba222a fix(page.evaluate): jsonValue should ignore toJSON property (#1098)
Currently, JSHandle.jsonValue() is implemented as in-page JSON.stringify
call and consequent JSON.parse in node. This approach proved to be
unfortunate for automation purposes: if page author overrode the
Object.prototype.toJSON method, then it's harder for puppeteer to
interact with the page.

This patch switches JSHandle.jsonValue to use protocol serialization
that ignores toJSON property. THis also changes the `page.evaluate`
behavior since it is based on JSHandle.jsonValue().

Fixes #1003.

BREAKING CHANGE:
`page.evaluate` no longer calls toJSON when generating return value.
For the old behavior, do JSON.parse/JSON.stringify manually:

```js
const json = JSON.parse(await page.evaluate(() => JSON.stringify(obj)));
```
2017-10-20 10:45:49 -07:00
Andrey Lushnikov
4f64dfd993 feat(Request): allow aborting intercepted requests with custom reasons (#1080)
This patch adds optional parameter to the `request.abort()` method
that specifies abort reason.

References #1020.
2017-10-18 00:26:48 -07:00
Christian Davis
b3857bd690 fix(page): page.close() assert that connection is not closed (#1038) 2017-10-17 19:24:34 -07:00
JoelEinbinder
32398d11bd feat(Browser): introduce Browser.pages() (#554)
This patch:
- introduces Target class that represents any inspectable target, such as service worker or page
- emits events when targets come and go
- introduces target.page() to instantiate a page from a target

Fixes #386, fixes #443.
2017-10-17 19:14:57 -07:00
Andrey Lushnikov
273c733237 feat(Request): introduce Request.failure() method (#1065)
Similarly to the `request.response()` method, this patch adds
`request.failure()` method that returns error details for the failed
requests.

Fixes #901.
2017-10-17 17:48:04 -07:00
JoelEinbinder
2b7951473d feat(Browser): make browser.close() to always terminate remote browser
This patch:
- changes `browser.close` to terminate browser.
- introduces new `browser.disconnect` to disconnect from a browser without closing it

This patch: fixes #918, fixes #989 

BREAKING CHANGE:
`browser.close()` will always close a browser, even if it was initialized with
`puppeteer.connect`. To disconnect from a remote browser, use `browser.disconnect()` instead.
2017-10-17 15:35:00 -07:00
JoelEinbinder
6a8865cd85 feat(keyboard): make keyboard.down generate input event by default (#1016)
This patch starts generating input events for `keyboard.down`, addressing bullet 2 of
#723. With this patch, there's no longer any difference between `keboard.press('a')` and
`keyboard.press('a', {text: 'a'})`.

BREAKING CHANGE:
`keyboard.down('a')` starts generating input event (wasn't the case before).

References #723
2017-10-13 15:22:55 -07:00
Andrey Lushnikov
a02347e3ef feat(Page): implement page.setOfflineMode (#1032)
This patch implements page.setOfflineMode method.

Fixes #63.
2017-10-13 14:41:39 -07:00
Christian Davis
8511db957f feat(page): waitForSelector hidden option (#967)
This patch adds a 'hidden' option for the `page.waitForSelector` method.
2017-10-13 09:11:11 -07:00
JoelEinbinder
8f430fb23d fix(ElementHandle.boundingBox): account for margin, padding, and border in element.boxModel (#1017)
This patch starts relying on border quad to compute element's bounding box.

Fixes #1010
2017-10-12 17:53:59 -07:00
Sam Verschueren
c310f139a0 feat(Frame): Support options in addScriptTag and addStyleTag (#996)
This patch:
- deprecates injectFile as it was confused with the addScriptTag
- accepts an options object in addScriptTag which supports properties url, path and content.
- accepts an options object in addStyleTag which supports properties url, path and content.

Fixes #949.

BREAKING CHANGE:
- the addStyleTag/addScriptTag have changed;
- the injectFile was removed in favor of (addStyleTag({path:}).
2017-10-12 01:26:44 -07:00
JoelEinbinder
0426e3c068 Roll chromium to 508268 (#1019)
This gets us:

- Plural metrics names https://crrev.com/507885
- TargetInfoChanged on URL changes https://crrev.com/508049
- Sending proper resource types for requests https://crrev.com/667504

Fixes #734
2017-10-12 01:17:06 -07:00
JoelEinbinder
c893bf3684 fix(input) Send .code with keyboard events (#1015)
This patch starts sending proper `.code` field with emulated keyboard events.

References #777.
2017-10-11 18:09:43 -07:00
Andrey Lushnikov
23c0ba0727 feat(Page): introduce Page.queryObjects (#1005)
This patch introduces `Page.queryObjects` and
`ExecutionContext.queryObjects` methods to query JavaScript heap
for objects with a certain prototype.

Fixes #304.
2017-10-11 14:41:20 -07:00
Barry vd. Heuvel
3f9f0f44ff feat(Page.pdf): add 'A6' page format
This patch adds 'A6' page format option to the Page.pdf method.
2017-10-11 13:18:14 -07:00
Gleb Azarov
ff08e45785 fix: Remove synchronous operation with file system. (#879)
This patch:
- introduces `helper.promisify` - a simple polyfill for the `util.promisify`. The 
  `util.promisify` could not be used due to Node6 compatibility issues.
- migrates all sync filesystem operations to the async replicas

Fixes #884.
2017-10-11 00:55:48 -07:00
Andrey Lushnikov
7a8aa73466 feat(Page): introduce Page.$$eval method (#1006)
This patch adds a `Page.$$eval` method that runs `document.querySelectorAll`
and passes resulting array to the page function.

Fixes #625.
2017-10-10 23:23:14 -07:00
Andrey Lushnikov
464b6a9616 fix(Page.getMetrics): do not report a few metrics (#1001)
A few of the reported metrics in the Page.getMetrics are already
reported with lifecycle events.

This patch excludes these metrics for now.
2017-10-10 15:22:14 -07:00
Alexei Filippov
b82d3197ed feat(Page): Support Page.getMetrics and metrics event. (#939)
Provides access to the current page performance metrics.
Allows to push page metrics from the page JavaScript with console.timeStamp()

Fixes #309
2017-10-10 14:50:38 -07:00
Andrey Lushnikov
1fbf2a8a46 feat(Page): kill the page.plainText method (#994)
The page.plainText is confusing: it's unclear what kind of text it
returns, textContent or innerText. It's also easily polyfillable and
doesn't seem to be used.

BREAKING CHANGE: the page.plainText is not existing any more.
Instead, use `page.evaluate(() => document.body.innerText)`.
2017-10-10 10:54:51 -07:00
Andrey Lushnikov
079db90066 fix(JSHandle.toString): clearer description for primitives (#993)
This patch:
- updates JSHandle.toString to make a nicer description for primitives
- excludes JSHandle.toString from documentation to avoid its abuse

References #382
2017-10-10 10:54:20 -07:00
Andrey Lushnikov
c3fb367148 fix(Request): convert resourceType to all small-caps (#990)
This patch moves resourceType to be all small-caps. This aligns
with our convention that all string constants should be smallcaps.

BREAKING CHANGE: this patch changes the constants of the
request.resourceType to be all small-caps.
2017-10-10 10:53:37 -07:00
Eli Sherer
7e28dbafb5 feat(ElementHandle): add EH.boundingBox and EH.screenshot
This patch:
- adds `ElementHandle.boundingBox()` method to get bounding box of element relative
  to the page
- adds `ElementHandle.screenshot()` method to capture a screenshot of an element
2017-10-09 23:14:09 -07:00
JoelEinbinder
e59172de83 chore: Use Typescript to lint JSDoc annotations (#986)
This patch starts using typescript to lint JSDoc annotations.

Note: this uses typescript's bleeding edge. We should migrate to stable once
it has all the necessary bugfixes.

References #65.
2017-10-09 22:31:40 -07:00
Vse Mozhet Byt
f1aa18af4e feat(Launcher): add devtools option (#953)
This patch adds a `devtools` option to the launcher that adds the `--auto-open-devtools-for-tabs`
argument to the launched chrome.

Fixes #864.
2017-10-09 17:25:25 -07:00
Andrey Lushnikov
e6af6e19d6 feat(console): dispatch JSHandles as console arguments (#975)
This patch starts dispatching JSHandle instances as console arguments.

BREAKING CHANGE: this changes the API of the ConsoleMessage.

Fixes #324.
2017-10-09 17:01:01 -07:00
JoelEinbinder
52f92c9891 fix(input): clicking an element should take into account frame position (#971) 2017-10-09 13:23:36 -07:00
JoelEinbinder
a7672acb85 fix: return undefined when Page.evaluate encounters circular JSON (#983) 2017-10-09 12:30:05 -07:00
Christian Davis
3ecd98d634 fix(Page.select): synthesized events should bubble
This patch fixes `Page.select` to synthesize bubbling events.
2017-10-07 10:27:38 -07:00
JoelEinbinder
0af0d7dba5 feat(Input): Add keyboard methods to elementHandle (#801)
This patch:
- adds input methods to ElementHandle, such as ElementHandle.type and ElementHandle.press
- changes `page.type` to accept selector as the first argument
- removes `page.press` method. The `page.press` is rarely used and doesn't operate with selectors; if there's a need to press a button, `page.keyboard.press` should be used.

BREAKING CHANGE: `page.type` is changed, `page.press` is removed.

Fixes #241.
2017-10-07 00:28:24 -07:00
Andrey Lushnikov
0d0f9b7984 feat(JSHandles): introduce JSHandles (#943)
This patch:
- introduces ExecutionContext class that incapsulates javascript
  execution context. An examples of execution contexts are workers and
  frames
- introduces JSHandle that holds a references to the javascript
  object in ExecutionContext
- inherits ElementHandle from JSHandle

Fixes #382.
2017-10-06 15:35:02 -07:00
Benoît Zugmeyer
c225b93037 feat(Launcher): Allow environment variables definition when launching chromium (#912)
This patch adds `env` option to the `puppeteer.launch` method to define custom environment
variables to the launched chrome.
2017-10-05 14:34:35 -07:00
Sam Verschueren
97e40e6823 feat(Frame): Add addStyleTag API to frame - fixes #892 (#947)
This patch adds `Page.addStyleTag` and `Frame.addStyleTag` methods to the API.

Fixes #892.
2017-10-04 13:42:26 -07:00
mizdra
215b3497c7 fix(Page): remove event listeners to avoid MaxListenersExceededWarning
This patch starts to properly clean up event listeners on a failed navigation (Page.goto).
2017-09-30 00:50:13 -07:00
Adi Prasetyo
53531c9a92 feat(page): Allow Page.goto's timeout to be 0 to disable timeout (#887)
This patch allows passing 0 to disable timeout for the following methods:

- page.goto
- page.waitForNavigation
- page.goForward
- page.goBack

Fixes #782.
2017-09-30 00:29:38 -07:00
Pavel Feldman
a6cf8237b8 feat(Launcher): introduce appMode option
The patch introduces a new appMode option to the launcher. This is an experimental
option, thus we don't document it.
2017-09-29 15:16:32 -07:00
Andrey Lushnikov
c46c41d89c fix(Launcher): Launcher should handle chrome process errors (#863)
Fixes #750
2017-09-29 12:21:24 -07:00
Andrey Lushnikov
cb280c526d fix(Launcher): Terminate chrome gracefully on Windows (#876)
This patch starts using taskkill program on windows to gracefully
terminate chrome.

Note: this slows down chrome shutdown on Windows in case of using
custom userDataDir. This is because chrome takes some time to shutdown
its operations and leave profile directory in a consistent state.

Fixes #839.
2017-09-29 11:41:11 -07:00
Andrey Lushnikov
f6255029bd feat(Console): Introduce ConsoleMessage type (#909)
This patch introduces ConsoleMessage type and starts dispatching
it for the 'console' event.

BREAKING CHANGE: this breaks the api of the 'console' event.

Fixes #744.
2017-09-29 11:27:22 -07:00
Andrey Lushnikov
cfece3451d fix(Network): Do not attempt to normalize malformed URLs. (#875)
This patch avoids throwing 'url malformed' error during generating
request hash for request interception.

Fixes #869.
2017-09-29 08:29:19 +09:00
Andrey Lushnikov
72161c475d [roll] Roll chromium to r503964 (#878)
This patch rolls chromium to r503964.

Note: since the plznavigate is not supported by puppeteer right now, the
patch also starts passing the `--disable-browser-side-navigation` flag.
This is a temporary work around for us.

References #877.
2017-09-27 10:37:31 +09:00
Alix Axel
45f264024b [api] Introduce Page.select method (#779)
This patch adds `Page.select` method to select
values in a `select` tag.
2017-09-25 18:23:34 +09:00
JoelEinbinder
e2cad568d6 page.waitFor should send ...args to page.waitForFunction (#775)
This lets the user pass `...args` into `page.waitFor`. It also clarifies that the docs that `options` is not optional if `...args` are specified.

Fixes #770
2017-09-15 14:28:15 -07:00
Andrey Lushnikov
d562db3140 Assert that all extra HTTP header values are strings (#781)
Since protocol ignores all HTTP headers that don't have string
value, this patch starts validating header key-values before
sending them over the protocol.

Fixes #713.
2017-09-14 19:08:48 -07:00
Andrey Lushnikov
86b05dadd5 disable extensions and google translate by default (#774)
This patch teaches `puppeteer.launch` to run chromium with disabled
chrome extensions and google translate services.

References #760
2017-09-14 19:07:22 -07:00
JoelEinbinder
f398e69dbb [api] Launcher: Close gracefully when a userDataDir is specified (#700)
This patch:
- makes `browser.close()` return a promise that resolves when browser gets closed
- starts closing chrome gracefully if a custom `userDataDir` is supplied

Fixes #527
2017-09-13 21:27:14 -07:00
Andrey Lushnikov
d7e673645a [api] add Puppeteer.executablePath() method (#771)
This patch adds Puppeteer.executablePath() method to query the path
of bundled chromium.

Fixes #745
2017-09-13 17:39:18 -07:00
Andrey Lushnikov
9292a56eaf [api] Teach page.evaluate to accept element handles as parameters (#725)
This patch:
- teaches `page.evaluate` to accept ElementHandles as parameters
- removes `ElementHandle.evaluate` method since it's not needed any
  more

References #382
2017-09-11 19:20:02 -07:00
Andrey Lushnikov
a71f287c6b Fix evaluation in case of first "undefind" argument (#732)
It turns out that [undefined, 1].join(',') results in ",1" instead
of "undefined,1". This causes a syntax error when trying to pass undefined
as a first argument to `page.evaluate` method.

Fixes #572.
2017-09-11 16:59:38 -07:00
Andrey Lushnikov
e5c17eecb9 Carefully manage unhandled rejections for navigation (#741)
Currently, navigation watcher throws exception if timeout
is exceeded.

Due to the way it is used in `page.navigate`, the promise
get's rejected before it is awaited, which is considered to
be "unhandled promise rejection".

Fixes #738
2017-09-11 16:43:37 -07:00
Andrey Lushnikov
0db6165d73 [api] Implement page.authenticate method (#729)
This patch implements `page.authenticate` which should cover all
cases of HTTP authentication.

Fixes #426.
2017-09-11 16:32:13 -07:00
Andrey Lushnikov
0bea42bd8c Do not leave dangling promises when sending messages over protocol (#742)
It's very bad to have 'unhandled promise rejection' that can't be
handled in user code. These errors will exit node process in a near
future.

This patch avoids 'unhandled promise rejection' while sending protocol
messages.

This patch:
- introduces `puppeteer:error` debug scope and starts using it for all
  swalloed errors.
- makes sure that every `client.send` method is either awaited or its
  errors are handled.
- starts return promises from Request.continue() and Request.abort().
- starts swallow errors from Request.contine() and Request.abort().

The last is the most important part of the patch. Since
`Request.continue()` might try to continue canceled request, we should
disregard the error.

Fixes #627.
2017-09-11 16:21:51 -07:00
JoelEinbinder
64124df62f [api] add touchScreen.tap (#639)
This patch:
- adds `page.touchscreen` namespace, similar to `page.mouse` and `page.keyboard`.
- adds tapping to multiple layers:
  - `page.touchscreen.tap`
  - `page.tap` - convenience method which accepts selector
  - `elementHandle.tap`

Fixes #568 and #569.
2017-09-01 19:03:51 -07:00
JoelEinbinder
42fa3af659 Remove promise jsdoc (#641)
This patch removes unnecessary "promise" return types in jsdoc for async functions.
2017-08-31 17:58:07 -07:00
Andrey Lushnikov
62ececb1c7 Implement page.$eval (#638)
This patch:
- implements page.$eval and frame.$eval
- drops elementHandle.attribute() method in favor of the page.$eval

References #625
2017-08-31 15:38:01 -07:00
Andrey Lushnikov
66676c0235 Kill child process group (#621) 2017-08-30 14:16:03 -07:00
Andrey Lushnikov
c9b0a6c060 Fix launcher to not leak event listeners (#605)
This patch fixes launcher to not leak event listeners.
2017-08-29 22:49:50 -07:00
Andrey Lushnikov
11ce8b249f Implement Request.resourceType getter (#590)
This patch plumbs `resourceType` parameter of RequestWillBeSent
and requestIntercepted methods.
2017-08-29 16:27:59 -07:00
JoelEinbinder
8f74cc8a90 [api] Add "step" option to mouse.move method (#601)
This patch adds "step" option to the mouse.move method, that optionally tweens mouse movement over multiple steps.

References #423.
2017-08-29 14:13:38 -07:00
Batiste Bieler
77600c6c5e Implement ElementHandle.attribute() method (#543)
This patch implements ElementHandle.attribute() method to fetch a value of
element's attribute.
2017-08-29 11:24:32 -07:00
Andrey Lushnikov
8f66f7339e Fix launcher in case of empty arguments (#582)
The regression was introduced in
d5327e6a0f
2017-08-28 14:59:41 -07:00
JoelEinbinder
d5327e6a0f [api] Allow a custom userDataDir to be specified (#555)
This patch adds a `userDataDir` option to the `puppeteer.launch()` method.

Fixes #411.
2017-08-28 12:14:20 -07:00
Andrey Lushnikov
66912a7277 [api] use object instead of map for headers (#567)
This patch:

- switches to objects instead of maps for headers (in Request, Response and
page.setExtraHTTPHeaders)
- converts all header names to lower case

Fixes #547, fixes #509
2017-08-28 12:09:24 -07:00
Andrey Lushnikov
e921a1cc21 Fix Request Interception (#565)
It turned out that either Network.requestIntercepted or
Network.requestWillBeSent occasionally report encoded URL.

This patch starts decoding URL's when generating request hash.

Fixes #558.
2017-08-27 12:41:09 -07:00
JoelEinbinder
2c4dfbfd88 Fix node6 support for Object.entries and URL object (#548)
This patch introduces a polyfill for Object.entries which is missing in Node 6
2017-08-25 15:13:59 -07:00
JoelEinbinder
0791774faa Cookies (#314)
Introduce cookies API. 

Fixes #53.
2017-08-24 12:21:46 -07:00
JoelEinbinder
a1414de42f Implement page.setJavaScriptEnabled method
Fixes #462.
2017-08-23 14:08:56 -07:00
Dan Schuman
8fe2477850 Enable MutationObserver attributes (#499)
This patch fixes page.waitForSelector to resolve on
attribute changes. 

Fixes #474.
2017-08-23 13:25:40 -07:00
JoelEinbinder
ac109dba6d Kill Chrome quickly on Windows (#488)
This patch start killing chrome on windows with taskkill command.
2017-08-23 11:55:33 -07:00
Andrey Lushnikov
151d512ae2 Implement page.$$ method (#463)
This patch implements page.$$ which runs document.querySelectorAll
in page and returns results as an array of ElementHandle instances.

Fixes #384.
2017-08-22 22:56:55 -07:00
Andrey Lushnikov
ce08fc77b1 Roll chromium to r496140 (#465)
This patch rolls chromium to r496140. This includes the r496130 that
introduces multiple sessions for single target.

With this patch, it is possible to run puppeteer in headful mode
and open devtools over the automated pages without puppeteer losing
connection to the page.
2017-08-22 14:15:02 -07:00
JoelEinbinder
11e3343b3d Put chrome profiles into a temporary directory (#439)
This patch:
- puts chrome profiles into a temporary directory
- starts using `fs.mkdtemp` to create temp profile directories
2017-08-21 20:12:16 -07:00
Eric Bidelman
1f9b4fb4c8 Change let into const (#457)
This patch:
- changes `let` into `const` throughout codebase
- adds eslint check to prefer const over let
2017-08-21 16:39:04 -07:00
Eric Bidelman
5d6d3e0a81 cleanup: Use ES6 default params (#447) 2017-08-21 16:32:39 -07:00
Andrey Lushnikov
271fd09379 Launcher: add timeout to chrome launching (#434)
This patch:
- adds a 'timeout' launcher option that constrains the time for chromium to launch.
- adds a 'handleSIGINT' launcher option that is `true` by default and that closes chrome instance

Fixes #363.
2017-08-21 15:43:36 -07:00
Andrey Lushnikov
afd90123be waitTask should survive cross-process navigation (#435)
In case of cross-process navigation, we receive a context
which is immediately getting destroyed.

Fixes #396.
2017-08-21 13:34:26 -07:00
Andrey Lushnikov
c1731dd5d7 Fail gracefully when chromium failed to download (#430)
Fail gracefully when chromium failed to download

This patch changes both install.js and Launcher.js to inform how
chromium could be downloaded manually.
2017-08-21 13:34:10 -07:00
John Resig
598f439a32 Add Page.content() method. Fixes #406. (#419) 2017-08-21 09:02:30 -07:00
Andrey Lushnikov
fcb8ab9cd7 Add troubleshooting.md (#428)
This patch adds troubleshooting.md and starts referring to it if puppeteer 
fails to launch chromium.
2017-08-20 19:46:13 -07:00
Andrey Lushnikov
6cc274135c Introduce page.emulateMedia method (#383)
Emulating `screen` media would force `page.pdf()` to print with `screen`
media.

Fixes #312
2017-08-18 16:49:02 -07:00
Andrey Lushnikov
d71feb63d0 Determine failed navigation based on Frame.unreachedURL (#365)
This patch starts using frame.unreachedURL property from
frameNavigated event to determine if the page navigation
was successful.
2017-08-17 23:24:16 -07:00
Andrey Lushnikov
ae14c1eee4 Use randomized folder names for user profile directories (#364)
This will make it much harder for puppeteer browsers to collide
on profile directories.

Fixes #360
2017-08-17 23:18:08 -07:00
Pavel Feldman
127f3966d7 Allow capturing transparent screenshots (#354)
This patch adds `omitBackground` option to the `page.screenshot` method.

Fixes #344
2017-08-17 21:11:39 -07:00
JoelEinbinder
1ca7849017 Mute audio in headless, closes #350 (#355)
This patch adds the `--mute-audio` flag if chromium is launched in headless
mode.
2017-08-17 20:54:16 -07:00
JoelEinbinder
5f0afd5547 Move uploadFiles onto ElementHandle (#348)
This patch:
- removes the `page.uploadFile` method
- adds `elementHandle.uploadFile` method.

Motivation: `elementHandle.uploadFile` is rarely used, so it doesn't worth it
to keep it on page.
2017-08-17 14:53:37 -07:00
Andrey Lushnikov
7cef3d7ce7 Teach page.pdf to respect printBackground argument (#307)
References #301
2017-08-16 15:08:31 -07:00
Jonathan Garbee
da53218107 Fix doc on pdf method. Minor addition to PDF path option docs. (#292) 2017-08-16 11:11:40 -07:00
Andrey Lushnikov
0a190ebec9 Rename 'remoteDebuggingURL' into 'browserWSEndpoint' (#272) 2017-08-16 01:10:55 -07:00
Andrey Lushnikov
44c15220f9 Rename ElementHandle.release into ElementHandle.dispose (#284)
The ElementHandle.release feels related to ElementHandle.click.
The dispose is a more clear name.
2017-08-16 00:49:20 -07:00
JoelEinbinder
3c2aaaaeb0 Readme fixup part 1 (#278) 2017-08-15 23:04:16 -07:00
Aleksey
56eab00fa7 Roll chromium to r494365 (#271)
This patch:
- rolls chromium to r494365
- starts using Runtime.evaluate(awaitPromise: true), with new semantic
  we can avoid additional Runtime.awaitPromise call
- stops resolving promises for Console event
2017-08-15 17:35:59 -07:00
Andrey Lushnikov
af89e893e7 Implement basic element handles (#248)
This patch implements basic element handles which a backed with remote objects.

Fixes #111
2017-08-15 14:54:02 -07:00
Andrey Lushnikov
a424f5613a Introduce Puppeteer.connect method (#264)
This patch:
- refactors Connection to use a single remote debugging URL instead of a
  pair of port and browserTargetId
- introduces Puppeteer.connect() method to attach to already running
  browser instance.

Fixes #238.
2017-08-15 14:29:42 -07:00
Andrey Lushnikov
96309a207c Fix request interception corner cases (#261)
This patch:
- teaches request interception to ignore data URLs. Currently protocol
  doesn't send interceptions for data URLs.
- teaches request interception to properly process URLs with hashes.
  Currently `Network.requestIntercepted` sends url with a hash, whereas
  `Network.requestWillBeSent` doesn't report hashes in its urls. @see
  crbug.com/755456
- skips one more header that I spotted during debugging interception on
  the realworld websites.

Fixes #258, #259.
2017-08-15 13:55:48 -07:00
Andrey Lushnikov
24764df4c4 Emit 'error' event when page crashes (#266)
This patch starts emitting 'error' event when page crashes.
'error' events have special treatment in node, so page crashes
become observable for users.

Fixes #262.
2017-08-15 11:13:05 -07:00
Andrey Lushnikov
0a1294c7ee general cleanup (#256)
This patch:
- fixes multimap implementation to work properly in node
- moves ESTreeWalker from third-party into utils/doclint. ESTreeWalker
  license is compliant with Apache2.0.
2017-08-14 21:16:59 -07:00
Andrey Lushnikov
13e8580a34 Use puppeteer.launch instead of browser constructor (#255)
This patch:
- split browser launching logic from Browser into `lib/Launcher.js`
- introduce `puppeteer` namespace which currently has a single `launch`
  method to start a browser

With this patch, the browser is no longer created with the `new
Browser(..)` command. Instead, it should be "launched" via the
`puppeteer.launch` method:

```js
const puppeteer = require('puppeteer');
puppeteer.launch().then(async browser => {
  ...
});
```

With this approach browser instance lifetime matches the lifetime of
actual browser process. This helps us:
- remove proxy streams, e.g. browser.stderr and browser.stdout
- cleanup browser class and make it possible to connect to remote
  browser
- introduce events on the browser instance, e.g. 'page' event. In case
  of lazy-launching browser, we should've launch browser when an event
  listener is added, which is unneded comlpexity.
2017-08-14 18:08:06 -07:00
Andrey Lushnikov
4269f6a1bb Roll chromium to r493985 (#251)
This patch:
- rolls chromium to r493985
- migrates Browser.version() puppeteer method to use newly added
  Browser.getVersion() protocol method

References #227
2017-08-12 22:04:39 -07:00
Andrey Lushnikov
3ee4951506 [DEBUG] add "session" namespace to trace target protocol messages (#249) 2017-08-11 17:47:33 -07:00
Jonathan Garbee
56b0d8722b Default value for property on dialog (#247) 2017-08-11 17:24:46 -07:00
Andrey Lushnikov
4551afc6dc Introduce new interception API (#242)
This patch introduces new interception API, via killing InterceptedRequest and giving the `abort` and `continue` methods to the Request object.
2017-08-11 17:24:31 -07:00
Andrey Lushnikov
dbac6788ae Plumb default prompt value to the dialog (#243)
This patch:
- plumbs default prompt value to the dialog
- enables one more phantom test
2017-08-11 12:17:43 -07:00
JoelEinbinder
497baf0198 Roll chromium to r493673 (#240)
Mouse events are no longer racy. Enabling touch no longer converts all mouse events into touches. Promises in destroyed execution contexts are rejected immediately.
2017-08-11 01:21:02 -07:00
Andrey Lushnikov
b8dbd28b8c Refer to the upstream bug (#239)
The issue #168 is a protocol inconsistency which happens only
in case of HTTPS error. This patch starts refering to the
upstream bug instead of puppeteer issue.

Closes #168.
2017-08-11 01:07:33 -07:00
Andrey Lushnikov
6347a049ba Rename Page.setInPageCallback into Page.addBinding (#236)
This seems to be a much better name which is actually used for a similar
purposes in chromium/v8.
2017-08-10 21:44:49 -07:00
Pavel Feldman
3a7741a172 Introduce page.emulate convenience wrapper (#231)
This patch:
- introduces Page.emulate convenience wrapper
- adds a screenshot-fullPage.js example
2017-08-10 18:42:30 -07:00
Andrey Lushnikov
e1d8a3781e Rename Page.navigate into Page.goto (#232)
Fixes #228.
2017-08-10 00:02:10 -07:00
Andrey Lushnikov
fe06c896eb Roll chromium to 492629 (#230)
This patch
- rolls chromium to 492629
- migrates connection establishing to use browser target. This migration means
  that now we have a single websocket connection to browser (implemented
  in Connection class). A connection to a particular target is
  incapsulated in a new Session class.
2017-08-09 16:14:00 -07:00
Andrey Lushnikov
34b0095c10 Make interception work with redirects (#218)
This patch:
- changes interception API so that it better aligns with what we'd like to see
  in #121
- fixes the issue with redirect interception

Fixes #217.
2017-08-07 17:48:52 -07:00
Andrey Lushnikov
e1c5b8d244 Aborted network requests should use protocol's "Failed" status (#215)
This patch starts using "Failed" command for request interception instead of
"Aborted".

The "Aborted" status also has a side-effect of cancelling the navigation, so
there will be no error on the page and form puppeteer's standpoint, the navigation
will never complete.
2017-08-07 15:13:17 -07:00
Andrey Lushnikov
7888a37a3d Page.pdf should accept case-insensetive page format (#211) 2017-08-04 01:01:10 -07:00
Andrey Lushnikov
00196e6cdc Fix setContent to actually await the inner evaluation (#209) 2017-08-04 00:23:04 -07:00
Pavel Feldman
82fbb268db Do not count inflight requests explicitly - use set. (#202) 2017-08-03 16:30:55 -07:00