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

Top comments (2)

Collapse
 
chovy profile image
chovy

Really solid approach — the key insight here is that working within the user's actual browser session opens up automation possibilities that headless tools simply can't touch. Preserving auth state alone saves a massive amount of complexity.

The Blob URL injection for CSP bypass is clever. I ran into the same unsafe-eval wall when building a social media automation extension and ended up using a similar pattern — injecting scripts through URL.createObjectURL() to avoid CSP restrictions while keeping everything in the page context.

One thing I'd add: for use cases where the user wants to automate social engagement (posting, commenting across platforms), a zero-backend architecture is underrated. If you skip the Node.js server entirely and run everything client-side with user-supplied API keys, you eliminate the trust problem completely. No data leaves the browser, no server to maintain.

defpromo.com takes this approach for social media self-promotion — browser extension only, zero cloud, user provides their own keys. Different scope than your project but the same philosophy of keeping automation local and session-aware.

Curious if you've hit any issues with Socket.IO reconnection when Chrome suspends background service workers? That's been the biggest MV3 headache in my experience.

Collapse
 
mateoio profile image
Mateo Eidson

Very cool. Thanks for sharing