Interceptors
Interceptors are used to control what data Smartlook captures, and what data sensitive data Smartlook omits.
Interceptors are functions with two parameter objects: data
and context
. The structure of each interceptor differs based on their type. The return type of the function is void
. For events that can be filtered, the function can also return false
. true
has no effect. You can modify data
. Doing so directly affects what Smartlook records.
Types of interceptors
Currently, there are two types of interceptors:
- URL
- Network
URL
URL interceptors can obscure sensitive data from URLs, such as tokens. For URL interceptors, the URL is the URL of the page the user is visiting.
URL events can't be filtered out of the recording.
URL interceptor example
{
interceptors: {
url: (data) => {
const tokenIndex = data.url.indexOf('tokenId=');
if (tokenIndex > -1) {
data.url = data.url.slice(0, tokenIndex) + 'tokenId=[OBSCURED]';
}
}
}
Parameters
- data—an
object
consisting of- url—
string
URL can be changed
- url—
- context—is not defined
Network
Network interceptors can obscure sensitive data from recorded network calls—bodies, headers, and URLs.
Network events can be completely omitted by returning false
from the interceptor.
Network recording needs to be configured
For more information, see Advanced network recording.
Network interceptor example
{
interceptors: {
network: (data, context) => {
if (context.pageUrl.startsWith('https://my.domain/some-page')) {
// throw away all requests coming from https://my.domain/some-page
return false;
}
const tokenIndex = data.url.indexOf('tokenId=');
if (tokenIndex > -1) {
data.url = data.url.slice(0, tokenIndex) + 'tokenId=[OBSCURED]';
}
}
}
Parameters
- data—
object
- url—
string
- request—
object
- headers—
Record<string, Array<string>>
- body—
string
- headers—
- response—
object
- headers—
Record<string, Array<string>>
- body—
string
- headers—
- url—
- context—
object
- pageUrl—
string
URL of the page where the request was initiated.
- pageUrl—
Updated 24 days ago