DEV Community

Cover image for Automating Chrome with a Node.js API and Browser Extension
Mohsin Ali
Mohsin Ali

Posted on • Edited on

Automating Chrome with a Node.js API and Browser Extension

Introduction

While many developers today focus on integrating AI into automation, this project takes a different approach. Instead of using AI to execute tasks, I leverage it to generate workflows, defining task sequences while leaving execution to a Node.js API and Chrome Extension.

This system enables programmatic control of Chrome, allowing users to open and close tabs, execute JavaScript, and maintain synchronization. Unlike Playwright or Puppeteer, which operate in isolated environments, this solution works directly with your personal browser, preserving sessions, authentication, and logins.


Why Automate Chrome?

✅ Automate repetitive web tasks like form-filling and clicking buttons.

Manage tabs efficiently—open, close, switch, and find tabs instantly.

Run JavaScript inside browser tabs for real-time automation.

Sync browser state with a backend, ensuring accurate session tracking.

Real-time synchronization is achieved with Socket.IO, providing immediate task updates and reliable connection management.


How It Works

1️⃣ The Node.js API queues tasks, tracks browser state, and now broadcasts tasks in real time using Socket.IO.

2️⃣ The Chrome Extension listens for incoming tasks, executes them using a CSP-friendly JavaScript injection (with support for file uploads), and reports back the results.

⚠️ Current Issue: JavaScript execution was blocked due to Content Security Policy (CSP) restrictions in Chrome, preventing unsafe-eval. A fix was in progress.

Resolved: I have implemented a robust CSP JS workaround that executes scripts in the tab's main context using Blob URL injection, with the added flexibility of processing file uploads.


Why Not Playwright or Puppeteer?

Unlike Playwright or Puppeteer, which create isolated browser instances, this system works within your personal browser:

  • Preserves login sessions – No need to re-authenticate.
  • Works with real browsing data – Automates everyday workflows.
  • No separate headless instance – Uses your existing Chrome profile.
  • Real-time communication – With Socket.IO, tasks are delivered instantly, even if queued before the extension is activated.

Takeaways

🚀 Personal browser automation unlocks new possibilities, from monitoring dashboards to auto-refreshing web apps.

🔄 Synchronization is key—ensuring browser and backend states remain in sync prevents task failures.

My new Socket.IO integration guarantees immediate task delivery and robust reconnection if the Node API goes down.

🛠 Strategic automation improves productivity while maintaining security and performance.

Enhanced with a CSP-friendly JS execution workaround (supporting file uploads) and real-time task management, my system now offers greater flexibility and reliability.


Conclusion

This Node.js-powered automation system provides full control over Chrome, preserving sessions and real-world data. If you need automation that integrates with your personal browsing, this approach is for you.

🔗 Check out the full source code here: GitHub Repository

What would you automate? Let’s discuss! 🚀

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (1)

Collapse
 
mateoio profile image
Mateo Eidson

Very cool. Thanks for sharing

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more