# Browser Cookie & Session Health Monitor (`produkdigitalali/browser-cookie-session-health-monitor`) Actor

Check whether browser cookies still produce an authenticated session, detect expiry risk, and capture failure evidence without storing passwords.

- **URL**: https://apify.com/produkdigitalali/browser-cookie-session-health-monitor.md
- **Developed by:** [ProdukDigitalAli](https://apify.com/produkdigitalali) (community)
- **Categories:** Automation, Developer tools
- **Stats:** 2 total users, 1 monthly users, 80.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.02 / completed session check

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Browser Cookie & Session Health Monitor

Validate whether an existing browser session still reaches authenticated content. The Actor loads one permitted public page with encrypted cookie input, evaluates explicit active and logged-out signals, reports cookie expiry risk, and optionally saves one failure screenshot.

### Why use it

Scheduled scrapers and automations fail when sessions expire. This Actor gives a small, repeatable health check before an expensive workflow runs. It never asks for a password, never returns cookie names or values, and does not attempt CAPTCHA or access-control bypass.

### Input

Provide exactly one encrypted cookie source:

- **Cookie header**: `name=value; name2=value2`
- **Cookies JSON**: an array exported from Playwright or a browser cookie tool

Then configure one or more active-session signals:

- a CSS selector visible only when logged in;
- visible page text;
- a substring in the final URL.

Optional logged-out signals make the result more precise.

```json
{
  "checkName": "Customer portal session",
  "url": "https://example.com/account",
  "cookieHeader": "session=REPLACE_WITH_YOUR_COOKIE",
  "successSelector": "[data-testid='account-menu']",
  "loggedOutUrlIncludes": "/login",
  "expiryWarningHours": 72,
  "screenshotOnFailure": true,
  "proxyConfiguration": { "useApifyProxy": false }
}
```

The Console encrypts `cookieHeader` and `cookiesJson` because both fields use `isSecret: true`.

### Results

Each run writes one sanitized dataset row and an `OUTPUT` record:

- `ACTIVE`: at least one configured active signal matched;
- `LOGGED_OUT`: no active signal matched and a logged-out signal matched;
- `INDETERMINATE`: neither set of signals matched;
- `ERROR`: navigation or browser evaluation failed.

Cookie values and names are excluded. Persistent-cookie expiry is summarized as counts and an earliest expiry timestamp. A failure screenshot is optional and may contain private page content.

### Pricing

Recommended Store pricing: **$0.02 per completed session check** ($20 per 1,000). Invalid input, unsafe destinations, navigation errors, and checks blocked by the customer's maximum charge are not billed. A completed `ACTIVE`, `LOGGED_OUT`, or `INDETERMINATE` result is billable after its dataset row is saved.

### Safety and limits

- One session check per run.
- Up to 100 cookies.
- Public HTTP(S) destinations on ports 80 and 443 only.
- DNS, redirects, browser resources, and proxy traffic are checked against local, private, metadata, link-local, multicast, and reserved networks.
- 48 MiB browser transfer limit and 250 proxied connection limit.
- Downloads and service workers are disabled; popups are closed.
- No password collection, automated login, CAPTCHA solving, or access-control bypass.
- Use only sessions and websites you are authorized to access.
- Review failure screenshots before long retention because they can contain authenticated content.

### Scheduling

Create an Apify Task with encrypted cookie input and run it before a dependent scraper or on a regular schedule. Route `LOGGED_OUT`, `INDETERMINATE`, and `ERROR` results to a webhook or notification integration.

### Local development

```text
npm install
npm test
apify actor:start
```

Local test input belongs in `storage/key_value_stores/default/INPUT.json`. Never commit real cookies.

# Changelog

This Actor's version history is a separate document: https://apify.com/produkdigitalali/browser-cookie-session-health-monitor/changelog.md

# Actor input Schema

## `checkName` (type: `string`):

A safe label for this session check. Do not place account identifiers here.

## `url` (type: `string`):

Public HTTP(S) page that should be accessible when the supplied session is active. Private and local network destinations are blocked.

## `cookieHeader` (type: `string`):

Encrypted secret in name=value; name2=value2 format. Provide this or Cookies JSON, not both.

## `cookiesJson` (type: `string`):

Encrypted JSON array exported from Playwright or a browser cookie tool. Supports name, value, domain, path, expires, httpOnly, secure, and sameSite.

## `successSelector` (type: `string`):

A CSS selector visible only when the user is logged in, such as \[data-testid='account-menu'].

## `successText` (type: `string`):

Exact substring expected in the visible page text when logged in.

## `successUrlIncludes` (type: `string`):

Substring expected in the final URL when the session is active.

## `loggedOutSelector` (type: `string`):

Optional selector that indicates the login page or logged-out state.

## `loggedOutText` (type: `string`):

Optional visible text that indicates the session is no longer authenticated.

## `loggedOutUrlIncludes` (type: `string`):

Optional final-URL substring such as /login or /sign-in.

## `timeoutSeconds` (type: `integer`):

Maximum browser navigation time.

## `expiryWarningHours` (type: `integer`):

Warn when a persistent cookie expires within this many hours.

## `screenshotOnFailure` (type: `boolean`):

Save one viewport screenshot for LOGGED_OUT, INDETERMINATE, or ERROR results. Screenshots can contain private page content.

## `proxyConfiguration` (type: `object`):

Optional Apify or custom HTTP(S) proxy. Public-destination checks remain enabled.

## Actor input object example

```json
{
  "checkName": "Production dashboard session",
  "url": "https://example.com",
  "cookieHeader": "demo=fake-cookie",
  "successText": "Example Domain",
  "timeoutSeconds": 30,
  "expiryWarningHours": 72,
  "screenshotOnFailure": true,
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}
```

# Actor output Schema

## `result` (type: `string`):

Final sanitized result without cookie names or values.

## `dataset` (type: `string`):

Dataset row for integrations and scheduled monitoring.

## `screenshots` (type: `string`):

Optional screenshot evidence for non-active results.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "url": "https://example.com",
    "cookieHeader": "demo=fake-cookie",
    "successText": "Example Domain",
    "proxyConfiguration": {
        "useApifyProxy": false
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("produkdigitalali/browser-cookie-session-health-monitor").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "url": "https://example.com",
    "cookieHeader": "demo=fake-cookie",
    "successText": "Example Domain",
    "proxyConfiguration": { "useApifyProxy": False },
}

# Run the Actor and wait for it to finish
run = client.actor("produkdigitalali/browser-cookie-session-health-monitor").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "url": "https://example.com",
  "cookieHeader": "demo=fake-cookie",
  "successText": "Example Domain",
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}' |
apify call produkdigitalali/browser-cookie-session-health-monitor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,produkdigitalali/browser-cookie-session-health-monitor"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/ejLFcn38ff1PJN0jI/builds/IAAv9gGjeG8oppnJR/openapi.json
