Commit Graph

33 Commits

Author SHA1 Message Date
Andrey Lushnikov
678b8e85ad
fix(page): use secondary DOMWorld to drive page.select() (#3809)
This patch starts creating secondary DOMWorld for every connected
page and switches `page.select()` to run inside the secondary world.

Fix #3327.
2019-01-22 17:55:33 -05:00
Andrey Lushnikov
e8bb26eb95
refactor: split out classes into files (#3773)
New files:
- LifecycleWatcher
- JSHandle
2019-01-14 20:34:50 -08:00
Brian Schiller
7fabf32172 feat(executioncontext): warn on nested js handle (#3591)
ExecutionContext.evaluateHandle accepts arguments that are either
serializable, or JSHandles. A potential confusion is that it *does not*
accept arguments that *contain* JSHandles.

This patch adds a log message warning when it encounters that situation.

Fixes #3562
2019-01-14 14:30:50 -08:00
Joel Einbinder
96adedf54f fix(screenshots): throw on 0x0 screenshots (#3756)
Fix #2672
2019-01-11 15:24:43 -08:00
Joel Einbinder
568734386d fix(types): fix parameters where they disagree with the api (#3525) 2018-11-12 12:59:21 -08:00
Joel Einbinder
79ec7a3fe5 fix(types): fix return types where JSDoc and api.md disagree (#3512) 2018-11-07 22:48:43 -08:00
Andrey Lushnikov
3596c5f7e2
fix(page.evaluate): better function serialization (#3480)
References #1665
2018-11-01 16:43:21 -07:00
Zeev Rosental
81edbbb58e fix(clicking): handle negative area results in computeQuadArea (#3413)
This patch fixes a case in which computeQuadArea calculates the area size correctly, but returns the area as a negative number.
This occurs when DOM.getContentQuads returns quads in a specific order.

E.g. the array: [ { x: 463, y: 68.5 },{ x: 437, y: 68.5 },{ x: 437, y: 94.5 },{ x: 463, y: 94.5 } ] will receive area size of -676.
2018-10-25 11:41:37 -07:00
Joel Einbinder
3d7ae2a259 fix: fix null-type bugs (#3137)
I ran TypeScript against our code with `strictNullChecks` on. Most of the errors generated are noise, because TypeScript doesn't understand how our `assert` method works. But some were legitimate bugs. They are fixed in this patch.
2018-08-24 15:17:36 -07:00
Andrey Lushnikov
d6eb3b4d52
refactor: drop object factory from execution context (#3099)
This patch:
- merges `ElementHandle` into `ExecutionContext` (for simplicity; there's no good reason to have them in separate files).
- removes the necessity to pass handle factory when creating `ExecutionContext`

This makes it easier to create execution contexts out of payloads.

References #1215
2018-08-16 16:16:27 -07:00
Andrey Lushnikov
be7626fa5e
fix: revert ExecutionContext reporting. (#3058)
It turned out that almost any usecase requires helper methods to access
DOM inside the ExecutionContext.

Instead of exposing execution contexts as-is, we should introduce
IsolatedWorld as a first-class citizen that will hold execution contexts
inside.
2018-08-09 18:14:21 -07:00
Andrey Lushnikov
231a2be971
feat: expose frame's execution contexts (#3048)
This patch exposes frame's execution contexts, making it possible
to debug extension's content scripts.

This is a resurrected #2812.
2018-08-09 14:57:08 -07:00
Joel Einbinder
2e0007669d chore: upgrade to TypeScript 3.0.1 (#3024) 2018-08-06 11:31:33 -07:00
Pavel Pomerantsev
12bc1e1a62 feat(coverage): add an option to collect coverage of anonymous scripts (#2796)
This patch adds `reportAnonymousScripts` option to the `coverage.startJSCoverage` method. With this option, anonymous scripts are reported as well.

Fixes #2777
2018-07-11 18:38:34 -07:00
Joel Einbinder
73f9c48081 feat: nicer protocol error messages (#2742)
This patch:
- stops appending `undefined` to our protocol messages unnecessarily.
- rewrites `Cannot find execution context id` to `Execution context was destroyed, most likely because of a navigation.` when it occurs from a Puppeteer ExecutionContext. The error message is left alone if it occurs via a CDPSession.
2018-06-14 15:27:59 -07:00
Andrey Lushnikov
0b94fa70eb
chore: stop using console.assert everywhere (#2646)
Since Node 10, `console.assert` no longer throws an AssertionError.
(This is generally good since it aligns Node.js with Browsers.)

This patch migrates all usages of `console.assert` in our codebase.
- All the `lib/` and testing code is migrated onto a handmade `assert`
function. This is to make Puppeteer transpilation / bundling easier.
- All the tooling is switched to use Node's `assert` module.

Fixes #2547.
2018-05-31 16:53:51 -07:00
Joel Einbinder
93fe2b57d6 feat(Page): introduce workers (#2560)
This adds `page.workers()`, and two events `workercreated` and `workerdestroyed`. It also forwards logs from a worker into the page `console` event.

Only dedicated workers are supported for now, ServiceWorkers will probably work differently because they aren't necessarily associated with a single page.

Fixes #2350.
2018-05-21 14:31:11 -07:00
Joel Einbinder
1d225cfa17 fix: allow user gesture restricted code to be run in page.evaluate (#2503)
Fixes #2502
2018-05-04 21:45:16 +03:00
Andrey Lushnikov
c5902de5d8
fix(Page): fix Page.evaluate with Symbols in arrays (#2340)
Fixes #2295.
2018-04-09 22:02:35 -07:00
JoelEinbinder
294f33b75c chore(types): type check the rest of the protocol (#2328)
This adds events and commands into generated `protocol.d.ts`.
2018-04-07 17:58:52 -07:00
JoelEinbinder
8c54f41552 chore(types): generate a d.ts file for protocol types (#2325)
This uses the `/json/protocol` endpoint to generate type definitions for the protocol.

Currently it is lacking protocol events and commands, but I will add those later.
2018-04-06 18:20:48 -07:00
Andrey Lushnikov
fc2a10440f
fix(evaluate): throw error when page reloads during page.evaluate. (#2073)
Fixes #2021.
2018-02-22 19:10:17 -08:00
Andrey Lushnikov
ae22ef30b3
feat(ExecutionContext): introduce ExecutionContext.frame() (#1972)
This patch introduces ExecutionContext.frame() that returns Frame
associated with this Execution Context.

This allows to associate console messages with the originating frame,
if any.
2018-02-13 14:02:44 -08:00
Andrey Lushnikov
5368051610
feat: expose raw devtools protocol connection (#1770)
feat: expose raw devtools protocol connection

This patch introduces `target.createCDPSession` method that
allows directly communicating with the target over the
Chrome DevTools Protocol.

Fixes #31.
2018-01-10 19:33:22 -08:00
JoelEinbinder
60ba8c3af9 feat: add page.xpath (#1620)
This patch adds xpath support with the following methods:
- page.xpath
- frame.xpath
- elementHandle.xpath

Fixes #537
2017-12-19 16:23:45 -08:00
Andrey Lushnikov
6512ce768d
fix(Frame): postpone evaluations until execution context gets created (#1415)
In Blink, frames don't necesserily have execution context all the time.
DevTools Protocol precisely reports this situation, which results in
Puppeteer's frame.executionContext() being null occasionally.

However, from puppeteer point of view every frame will have at least a
default executions context, sooner or later:

- frame's execution context might be created naturally to run frame's
  javascript
- if frame has no javascript, devtools protocol will issue execution
  context creation

This patch builds up on this assumption and makes frame.executionContext()
to be a promise.
As a result, all the evaluations await for the execution context to be created first.

Fixes #827, #1325

BREAKING CHANGE: this patch changes frame.executionContext() method to return a promise.
To migrate onto a new behavior, await the context first before using it.
2017-11-18 16:27:52 -08: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
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
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
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
JoelEinbinder
a7672acb85 fix: return undefined when Page.evaluate encounters circular JSON (#983) 2017-10-09 12:30:05 -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