Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

320
Views
How does colorZilla manage to pick color on webpages?

I'd like to know how colorZilla(the browser extension) does to get the color of every pixel within web pages. It even succeeded to get the color of a character within a TEXT_NODE.

Colorzilla picking the color of a character within the purple link a the bottom of the page

How does it know that the mouse pointer is hovering a TEXT_NODE with an ELEMENT_NODE?

I already tried the browser EyeDropper API but it doesn't work and always returns RGB(0,0,0). Maybe because it's still an experimental technology.

PS: I don't think colorZilla uses the EyeDropper API anyway.

Here are links to the extension for those who don't know it:

  • Firefox ColorZilla extension
  • Chrome ColorZilla extension
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

ColorZilla has 2 pieces of code working together, ContentScript and BackgroundScript.

ContentScript has access to current page's DOM context. It can add event listeners, can create DOM element (the toolbar UI), and it can also talk to the BackgroundScript via message passing using Port.postMessage API.

BackgroundScript, on the other hand doesn't have access to page's DOM, but it can use special privileged API provided by Chrome for extensions. chrome.tabs.captureVisibleTab is the key here.

Upon color picking request, the BackgroundScript just captures the current page as image, and send the raw image data back to ContentScript via postMessage. Then ContentScript inject mousemove event listeners to the page, thus has your cursor position. Combining these 2 pieces of information, et voilà, now you can pick color at high precision.


If you're interested in finding out more details, go to this directory and look for 2 files:

# Extensions folder on macOS (don't know about Windows, sorry)
~/Library/Application Support/Google/Chrome/Default/Extensions/bhlhnicpbhignbdhedgjhgdocnmhomnp/2.0_0/js/

- content-script-combo.js  # ContentScript
- background.js            # BackgroundScript

Use prettier to format the code a bit, then search for keyword "take-screenshot", it should take you to the relevant part of code. From there on, have fun digging!

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!