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! 🚀

Redis image

Short-term memory for faster
AI agents

AI agents struggle with latency and context switching. Redis fixes it with a fast, in-memory layer for short-term context—plus native support for vectors and semi-structured data to keep real-time workflows on track.

Start building

Top comments (1)

Collapse
 
mateoio profile image
Mateo Eidson

Very cool. Thanks for sharing

Tiger Data image

🐯 🚀 Timescale is now TigerData: Building the Modern PostgreSQL for the Analytical and Agentic Era

We’ve quietly evolved from a time-series database into the modern PostgreSQL for today’s and tomorrow’s computing, built for performance, scale, and the agentic future.

So we’re changing our name: from Timescale to TigerData. Not to change who we are, but to reflect who we’ve become. TigerData is bold, fast, and built to power the next era of software.

Read more

👋 Kindness is contagious

Explore this insightful piece, celebrated by the caring DEV Community. Programmers from all walks of life are invited to contribute and expand our shared wisdom.

A simple "thank you" can make someone’s day—leave your kudos in the comments below!

On DEV, spreading knowledge paves the way and fortifies our camaraderie. Found this helpful? A brief note of appreciation to the author truly matters.

Let’s Go!