Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ page.at_css("input").evaluate("this.value")
```

Some scripts written for Ferrum before 0.21 behave differently now, see
[upgrading to 0.21](docs/13-javascript.md#upgrading-to-021).
[upgrading](docs/24-upgrading.md#javascript).

Do any mouse movements you like:

Expand Down
21 changes: 0 additions & 21 deletions docs/13-javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,6 @@ page.at_css("input").evaluate("this.value")
page.at_css("input").execute("this.value = text", text: "hello")
```

#### Upgrading to 0.21

0.21 removes the JavaScript API from before named arguments, along with `evaluate_async`, `evaluate_func` and
`evaluate_on`. Plain expressions and positional arguments, `evaluate("document.title")` or
`evaluate("arguments[0] + 1", 1)`, work as before. Upgrade to 0.20 first and fix what it warns about, or run your
suite on 0.20 with `FERRUM_JS_API=new`, which behaves like 0.21. These scripts behave differently:

| Script | < 0.21 | >= 0.21 | Notes |
|---|---|---|---|
| `evaluate("arguments[0].foo", foo: 1)` | `1` | `nil` | keywords are named parameters now, write `evaluate("foo", foo: 1)` |
| `evaluate("[arguments[0], arguments[1]]", 1, foo: 2)` | `[1, { "foo" => 2 }]` | `ArgumentError` | positional and keyword arguments can't be mixed, pass `{ foo: 2 }` in braces |
| `evaluate("a(); b")` | `a()`'s value, `b` never runs | `b`'s value | every statement runs, the last one's value is returned |
| `evaluate("\n window.ran = true\n")` | `nil`, nothing runs | `true` | the line break no longer ends the `return`, check it's safe to run |
| `evaluate("Promise.resolve(1)")` | `{}` | `1` | promises are awaited, `void` keeps one from being awaited |
| `node.evaluate("this.parentNode")` | `{}` | `Ferrum::Node` | |
| `node.evaluate("new Date(0)")` | `{}` | `"1970-01-01T00:00:00.000Z"` | |
| `evaluate_async("arguments[0](1)", 5)` | `1` | `NoMethodError` | `evaluate("await …", timeout: 5)` |
| `evaluate_func("function(a) { return a }", 1)` | `1` | `NoMethodError` | `evaluate("function(a) { return a }", 1)`, with `on:` use `node.evaluate` |
| `evaluate_on(node: node, expression: "this.id")` | `"main"` | `NoMethodError` | `node.evaluate("this.id")` |
| `evaluate_on(node: link, expression: "this.click()", wait: 0.1)` | waits for the new page | `NoMethodError` | `page.await_navigation!(watch: 0.1) { link.evaluate("this.click()") }` |

#### evaluate_on_new_document(source, \*\*options) : `String`

Runs JavaScript in every new document of the page and its in-process frames, before the document's own scripts.
Expand Down
19 changes: 17 additions & 2 deletions docs/24-upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,23 @@ Then upgrade to 1.0, it removes what 0.22 deprecated.
#### JavaScript

Every script runs the new way: keyword arguments are named parameters, promises are awaited, every statement runs and
the last one's value is returned, `node.evaluate` returns nodes and dates. The table in
[Upgrading to 0.21](/docs/ferrum/javascript#upgrading-to-021) lists the scripts that behave differently.
the last one's value is returned, `node.evaluate` returns nodes and dates. Plain expressions and positional arguments,
`evaluate("document.title")` or `evaluate("arguments[0] + 1", 1)`, work as before. Run your suite on 0.20 with
`FERRUM_JS_API=new` to get 0.21's behavior before you upgrade. These scripts behave differently:

| Script | < 0.21 | >= 0.21 | Notes |
|---|---|---|---|
| `evaluate("arguments[0].foo", foo: 1)` | `1` | `nil` | keywords are named parameters now, write `evaluate("foo", foo: 1)` |
| `evaluate("[arguments[0], arguments[1]]", 1, foo: 2)` | `[1, { "foo" => 2 }]` | `ArgumentError` | positional and keyword arguments can't be mixed, pass `{ foo: 2 }` in braces |
| `evaluate("a(); b")` | `a()`'s value, `b` never runs | `b`'s value | every statement runs, the last one's value is returned |
| `evaluate("\n window.ran = true\n")` | `nil`, nothing runs | `true` | the line break no longer ends the `return`, check it's safe to run |
| `evaluate("Promise.resolve(1)")` | `{}` | `1` | promises are awaited, `void` keeps one from being awaited |
| `node.evaluate("this.parentNode")` | `{}` | `Ferrum::Node` | |
| `node.evaluate("new Date(0)")` | `{}` | `"1970-01-01T00:00:00.000Z"` | |
| `evaluate_async("arguments[0](1)", 5)` | `1` | `NoMethodError` | `evaluate("await …", timeout: 5)` |
| `evaluate_func("function(a) { return a }", 1)` | `1` | `NoMethodError` | `evaluate("function(a) { return a }", 1)`, with `on:` use `node.evaluate` |
| `evaluate_on(node: node, expression: "this.id")` | `"main"` | `NoMethodError` | `node.evaluate("this.id")` |
| `evaluate_on(node: link, expression: "this.click()", wait: 0.1)` | waits for the new page | `NoMethodError` | `page.await_navigation!(watch: 0.1) { link.evaluate("this.click()") }` |

#### Return values

Expand Down
Loading