To schedule a daily task in Webflow that runs a script without causing CORS issues, you need to use an external automation platform because Webflow does not support native server-side scripting or cron jobs.
1. Use a Serverless Function or External Server
- CORS (Cross-Origin Resource Sharing) issues occur when client-side scripts make unauthorized cross-origin requests.
- To avoid CORS errors, do not run the script directly in the browser from a Webflow project.
- Instead, host your script on an external platform like:
- AWS Lambda, Google Cloud Functions, or Vercel Functions for serverless functions.
- A small Node.js server on Render, Heroku, or Railway.
- Use a scheduling platform to run the script daily:
- Make (Integromat): Allows HTTP requests and scheduling.
- Zapier with Webhooks.
- n8n, a self-hosted automation tool.
- GitHub Actions (if your script is in a repo).
- UptimeRobot or Cron-job.org for triggering a URL on a schedule.
3. Avoid CORS by Switching to Server-to-Server Communication
- Browser-based scripts from Webflow may hit CORS policies when making requests to other domains.
- Make requests server-side (from your external server) to avoid CORS entirely.
- If you're calling Webflow’s API (e.g., CMS updates), place the API logic in the script running on your server.
4. Secure Your API Credentials
- When using Webflow's CMS API, ensure your API key is stored securely (e.g., as environment variables, not in your site’s frontend code).
- Never expose credentials in Webflow’s Embed element or Site Settings > Custom Code.
5. (Optional) Update Webflow CMS Using API
- If your script updates or retrieves data from Webflow:
- Use Webflow’s CMS API v2 endpoints.
- Authenticate with a Bearer token (your Webflow API key) in the
Authorization
header. - Example:
https://api.webflow.com/v2/collections/{collection_id}/items
Summary
To run a daily script for a Webflow site without hitting CORS issues, host the script on an external server or serverless function, and schedule it with platforms like Make or Zapier. By moving your script server-side, you bypass browser-based CORS restrictions and gain more control and security.