Hello friends,
We hope everyone is healthy, happy, and ready for winter :)
Our team is back from the break and excited to announce a new Ferret release!
Ferret v0.16.0 is here and now it’s more stable, flexible, and faster!
As always, CLI can be found here and the runtime itself here.
Let’s dive in and see what we’ve got!
What’s new
In this release, besides internal optimizations, we’ve focused on new language syntax and order to
WAITFOR
This is the beginning of our initiative to replace WAIT_
functions by providing a universal interface in the runtime type system. We’ve started with WAITFOR EVENT
statement.
The statement allows developers to declare a pause of the execution until a certain event occurs in a given source or a time is out (by default: 5000 ms).
The syntax is following:
WAITFOR EVENT event_name IN source [OPTIONS options] [FILTER expression] [TIMEOUT timeout]
It also can be used as an expression and assign returned event value to a variable:
LET evt = (WAITFOR EVENT event_name IN source [OPTIONS options] [FILTER expression] [TIMEOUT timeout])
At this moment, 3 events are supported by the cdp
driver:
- navigation
- request
- response
Navigation
navigation
event is intended to replace WAIT_NAVIGATION
function which will be deprecated in the next release and focused to be more flexible.
WAITFOR EVENT "navigation" IN page
While the simple version of the statement provides extra readability, it also provides extra control over navigation using FILTER
statement
WAITFOR EVENT "navigation" IN page FILTER CURREN.url LIKE "MY_DESIRABLE_URL"
You may have noticed CURRENT
keyword inside the filter statement.
This is a pseudo-variable that provides access to the current event object. The event object will depend on the type of an event, in the case of navigation, the object has the following fields:
{
url
frame
mimeType
}
frame
property allows to wait for a navigation event in one of nested frames:
WAITFOR EVENT "navigation" IN page FILTER CURREN.frame == nested_doc
AJAX
request
and response
are the events you can use to subscribe to AJAX request/response operations:
Request object:
{
url
method
headers
body
}
Response object:
{
url
statusCode
status
headers
body
responseTime
}
They can be useful for intercepting data between a client and a server.
Optional chaining
From the early days of Ferret, the runtime has been pretty strict on accessing properties of values that either are null or do not provide any properties by terminating an execution with a type error. But sometimes, the result of the accessing property might not be that important which makes us write long ternary operators that do some checks.
Well, now you do not have to do it anymore! This release is bringing the optional chaining aka Elvis operator to FQL language:
The ?.
operator is like the .
chaining operator, except that instead of returning an error if a reference is null, the expression short-circuits with a return value of NONE
.
Errors suppression
Errors suppression feature is somewhat similar to the optional chaining in allowing to tolerate insignificant errors during query execution and return NONE
in case of occurred error:
If you try to execute the same query, but without ?
operator, it will fail:
The ?
operator is like the ?.
optional chaining operator, but for function calls and inline statements:
XPath selectors
This is one of the long waiting features - universal use of XPath selectors.
With updated interface of HTML driver componenets, it is possible to pass XPath selectors to HTML API functions by using new X
function:
X
function creates an XPath type of query selector which is supported by all HTML API functions now. The function automatically resolves returned value based on its type.
Discard results
Sometimes we need to do some prep work in a FOR
loop but are not interested in the returned result. With this release we can use Go-like _
variable name to discard results.
Like in Go, you cannot access this variable later:
What’s fixed
Here is a list of important bug fixes:
values.Parse
does not parse int64- CPU leakage
- nil pointer exception
- HTTP driver makes multiple requests #642
Summary
That’s it, folks! Full list of changes you you can find here. Thanks everyone who contributed to the project!