How to Schedule Recurring Website Screenshots with PhantomJS
Use a PhantomJS script for capture and cron or Windows Task Scheduler for recurring runs. This legacy workflow needs compatibility checks on your host and target sites.
To schedule recurring website screenshots with PhantomJS, put the capture logic in a JavaScript file, confirm it runs manually, then schedule the PhantomJS command with cron on Linux or Task Scheduler on Windows. The scheduler starts the script; PhantomJS opens the page and renders the image.
Compatibility warning: PhantomJS development is suspended and its upstream repository is archived and read-only. Treat this as a legacy workflow. Verify the installed binary on the actual host and check every target page; do not assume current browser compatibility or that rendering will succeed. See the PhantomJS project site and its archived repository.
1. Create a PhantomJS capture script
The script below follows the official quick-start pattern: create a webpage, open a URL, render on successful load, and exit. Replace the output path with an absolute path writable by the account that will run the scheduled task.
var page = require('webpage').create();
page.open('https://example.com/', function (status) {
if (status === 'success') {
page.render('/opt/captures/example.png');
} else {
console.log('Page failed to load: ' + status);
}
phantom.exit();
});
Save it as /opt/capture/capture.js (or another stable location). The example uses a fixed filename, so each successful run overwrites the prior capture. To keep a history, generate a unique filename per run, such as one containing the date and time, and ensure the destination directory exists.
PhantomJS documents PNG, JPEG, GIF, and PDF output. The output extension determines the requested format. Its capture guide also documents viewport and clip rectangle settings; set page.viewportSize to control the browser viewport or page.clipRect to capture a specific rectangle. A viewport-sized render should not be assumed to include the whole page height. See the PhantomJS screen capture guide.
2. Run it manually before scheduling
Use the same operating-system account that will own the scheduled job. This helps reveal differences in permissions, environment, network access, and working directory before a recurring run is configured.
/usr/local/bin/phantomjs /opt/capture/capture.js
Check that the executable path is correct, the process exits, the output file appears where expected, and the account can write to its directory. If the scheduler starts in a different working directory, absolute paths avoid relying on the interactive shell’s current directory. The documented command form is phantomjs [options] somescript.js [args...]; consult the official command-line documentation for available options.
3. Schedule the command on Linux with cron
Edit the crontab for the account that should run the capture:
crontab -e
For a daily run at 06:30 in the host’s configured local time, add a line like this, adjusting both paths:
30 6 * * * /usr/local/bin/phantomjs /opt/capture/capture.js >> /opt/capture/capture.log 2>&1
The five schedule fields are minute, hour, day of month, month, and day of week. For example, 30 6 * * * means 06:30 every day. Cron implementations and host configuration can differ; check the machine’s crontab(1) and crontab(5) references. The crontab manual describes the schedule format and command entries.
- Use the intended account’s crontab and confirm it can execute PhantomJS and write the capture and log files.
- Confirm the machine’s timezone and daylight-saving behavior match the schedule you need.
- Redirect output to a writable log if you need a record of script messages and errors.
- Keep the machine powered on or hosted when the job is due; a scheduled time cannot run while the host is unavailable.
4. Schedule the command on Windows
In Task Scheduler, create a task with a daily, weekly, or monthly trigger. Set the action to start the PhantomJS executable and pass the script path as an argument. Configure the intended account and, where needed, the task’s working directory in the task properties. Use quoted paths when a directory name contains spaces.
You can also create a recurring daily task from Command Prompt with schtasks. Adapt the executable and script paths for the host:
schtasks /create /tn "Website screenshot" /sc daily /st 06:30 /tr "\"C:\Tools\phantomjs\bin\phantomjs.exe\" \"C:\Capture\capture.js\""
Review the created task in Task Scheduler and confirm its account, trigger, action, and history settings. Microsoft documents recurring schedule types and command syntax in its schtasks create reference. Permissions to create or manage tasks depend on the account and task scope.
5. Choose the schedule and output behavior
| Decision | What to check |
|---|---|
| Run frequency | Set the cron expression or Task Scheduler trigger for the desired recurrence. Avoid overlapping runs if a capture could take longer than the interval. |
| Timezone | Confirm the host’s timezone and how its scheduler handles clock changes. |
| Run account | Use an account with permission to execute PhantomJS, access the target network, and write output and logs. |
| Output naming | Use a stable name to keep only the latest file, or a unique timestamped name to create an archive. Plan storage and cleanup for archives. |
| Host availability | The host must be running and able to reach the page at the scheduled time. Scheduler history or redirected logs help identify missed or failed runs. |
6. Troubleshoot common failures
| Symptom | Likely cause | What to do |
|---|---|---|
| No capture and no log | The scheduled command did not start, or output paths are wrong. | Check scheduler history, use absolute executable and script paths, and verify the task’s account and working directory. |
| “Page failed to load” | The page could not be opened from the host, or the legacy browser could not handle the page’s requirements. | Check network and DNS access, then validate the target in the installed PhantomJS environment. Do not treat a successful open as guaranteed across later runs. |
| File is missing or cannot be written | The destination directory does not exist or the job account lacks write permission. | Create the directory and grant the job account the needed permissions. Use an absolute output path. |
| It works in a terminal but not in the scheduler | The scheduled process may use another account, environment, timezone, or current directory. | Run the command as the scheduled account, specify absolute paths, and check the configured account and timezone. |
| Image is clipped or content is absent | Viewport and clip settings limit the capture; content may load asynchronously or rely on browser features PhantomJS does not support. | Review viewport and clip rectangle values, and validate the page’s rendering behavior on the actual host. PhantomJS is suspended, so modern-page behavior should not be assumed. |
| Task runs too long or overlaps | A page load or scheduled interval may exceed expectations. | Inspect logs and scheduler history, choose an interval that allows runs to finish, and configure the scheduler’s overlap behavior where available. |
A failed load, timeout, or missing asset can depend on the particular host and page. Avoid weakening TLS validation as a general-purpose fix; investigate the certificate, network, or compatibility issue instead.
7. Performance, reliability, and cost
Each scheduled capture starts a browser process and makes requests to the target page. More frequent schedules and more target URLs mean more process launches, network traffic, and storage if you keep every output. Choose a cadence that matches the monitoring or record-keeping need, and decide how long to retain timestamped files.
Reliability depends on the host being available, scheduler configuration, permissions, network access, and the target page remaining renderable by this legacy browser. Logs and scheduler history make diagnosis easier, but they do not make the capture itself reliable. PhantomJS is software; this workflow has no per-screenshot API charge described here, though the machine or hosting used to run it may have its own costs. No hosting provider is recommended here; verify that any host you choose can run your PhantomJS binary before relying on it.
Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server from Yorker Media. One GET request returns a PNG, JPEG, WebP, or PDF. See the ScreenshotNeo API docs.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
Cookie banners, popups, and chat widgets are removed before the shot, and each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are never billed; response headers say which page verdict applied and whether it was billed. Its MCP server gives AI agents tools to take screenshots, get page information, and capture PDFs. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots. Every feature is on every plan.
Create a free ScreenshotNeo account for 1,000 screenshots a month with no card.
FAQ
Does the scheduler take the screenshot?
No. Cron or Task Scheduler launches the command at the chosen time. The PhantomJS script opens the page and renders the file.
Can I capture a selected region instead of the viewport?
PhantomJS documents a clip rectangle for a defined capture area. Set it deliberately and confirm the resulting dimensions on the target page.
Should I use this for a new screenshot system?
PhantomJS development is suspended and its repository is archived. Use this guide to maintain or assess an existing setup; validate compatibility on your host and pages before depending on it.


