Modules@robinpath/screen
screen

@robinpath/screen

0.1.3Node.jsPublic

Screen capture and OCR: screenshots, region capture, window capture, and text extraction

Screen

Screen capture and OCR: take screenshots (full, region, window), extract text from images with tesseract.js, list displays, and compare images

Package: @robinpath/screen | Category: Web | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the screen module when you need to:

  • Take a full screenshot and save to file -- Use screen.capture to perform this operation
  • Capture a specific rectangular region of the screen -- Use screen.captureRegion to perform this operation
  • Capture a specific window by its title (falls back to full screen if not found) -- Use screen.captureWindow to perform this operation
  • Extract text from an image using OCR (tesseract.js) -- Use screen.ocr to perform this operation
  • Extract text from a rectangular region of an image -- Use screen.ocrRegion to perform this operation

Quick Reference

FunctionDescriptionReturns
captureTake a full screenshot and save to file{path, size}
captureRegionCapture a specific rectangular region of the screen{path, size, region: {x, y, width, height}}
captureWindowCapture a specific window by its title (falls back to full screen if not found){path, size, window, fallback}
ocrExtract text from an image using OCR (tesseract.js){text, confidence, language}
ocrRegionExtract text from a rectangular region of an image{text, confidence, region: {x, y, width, height}}
setLanguageSet the default OCR language (eng, rus, deu, fra, spa, chi_sim, jpn, kor, ron, etc.){language, previous}
listDisplaysList all available displays/monitorsArray of {id, name, width, height, primary}
compareCompare two images byte-by-byte to check if they are identical{identical, image1Size, image2Size, sameSize}

Functions

capture

Take a full screenshot and save to file

Module: screen | Returns: object -- {path, size}

screen.capture "./screenshot.png"
ParameterTypeRequiredDescription
filePathstringYesOutput file path
optionsobjectNo{format?: 'png'

captureRegion

Capture a specific rectangular region of the screen

Module: screen | Returns: object -- {path, size, region: {x, y, width, height}}

screen.captureRegion "./region.png" 100 100 400 300
ParameterTypeRequiredDescription
filePathstringYesOutput file path
xnumberYesLeft position in pixels
ynumberYesTop position in pixels
widthnumberYesRegion width in pixels
heightnumberYesRegion height in pixels

captureWindow

Capture a specific window by its title (falls back to full screen if not found)

Module: screen | Returns: object -- {path, size, window, fallback}

screen.captureWindow "./notepad.png" "Untitled - Notepad"
ParameterTypeRequiredDescription
filePathstringYesOutput file path
windowTitlestringYesExact window title to capture

ocr

Extract text from an image using OCR (tesseract.js)

Module: screen | Returns: object -- {text, confidence, language}

screen.ocr "./screenshot.png"
ParameterTypeRequiredDescription
imagePathstringYesPath to the image file
optionsobjectNo{language?: string} e.g. 'eng', 'rus', 'deu'

ocrRegion

Extract text from a rectangular region of an image

Module: screen | Returns: object -- {text, confidence, region: {x, y, width, height}}

screen.ocrRegion "./screenshot.png" 50 50 200 100
ParameterTypeRequiredDescription
imagePathstringYesPath to the image file
xnumberYesLeft position in pixels
ynumberYesTop position in pixels
widthnumberYesRegion width in pixels
heightnumberYesRegion height in pixels
optionsobjectNo{language?: string}

setLanguage

Set the default OCR language (eng, rus, deu, fra, spa, chi_sim, jpn, kor, ron, etc.)

Module: screen | Returns: object -- {language, previous}

screen.setLanguage "deu"
ParameterTypeRequiredDescription
languagestringYesTesseract language code

listDisplays

List all available displays/monitors

Module: screen | Returns: object -- Array of {id, name, width, height, primary}

screen.listDisplays
ParameterTypeRequiredDescription
(none)NoCall with no arguments

compare

Compare two images byte-by-byte to check if they are identical

Module: screen | Returns: object -- {identical, image1Size, image2Size, sameSize}

screen.compare "./before.png" "./after.png"
ParameterTypeRequiredDescription
image1PathstringYesPath to first image
image2PathstringYesPath to second image

Error Handling

All functions throw on failure. Common errors:

ErrorCause
(standard errors)Check function parameters and authentication
@desc "Capture and validate result"
do
  set $result as screen.capture "./screenshot.png"
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. List and iterate Displays

Retrieve all items and loop through them.

@desc "List displays and iterate results"
do
  set $result as screen.listDisplays
  each $item in $result
    print $item
  end
enddo

2. Multi-step Screen workflow

Chain multiple screen operations together.

@desc "Capture, capture region, and more"
do
  set $r_capture as screen.capture "./screenshot.png"
  set $r_captureRegion as screen.captureRegion "./region.png" 100 100 400 300
  set $r_captureWindow as screen.captureWindow "./notepad.png" "Untitled - Notepad"
  print "All operations complete"
enddo

3. Safe capture with validation

Check results before proceeding.

@desc "Capture and validate result"
do
  set $result as screen.capture "./screenshot.png"
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.3latest1 months ago
Install
$ robinpath add @robinpath/screen

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.3
LicenseMIT
Unpacked Size6.3 KB
Versions1
Weekly Downloads21
Total Downloads21
Stars0
Last Publish1 months ago
Created1 months ago

Keywords

Category

web