@nut-tree/nut-js@3.0.0 has been released!
It's live! @nut-tree/nut-js@3.0.0
! 🚀
A little over a year after the last major release I'm happy to announce the release of nut.js v3.0.0 🎉
Release v3.0.0 brings a lot of new features and improvements to nut.js, but here are two things I want to highlight:
Often times nut.js is incorporated in an existing application and naturally, one would love to know what's going on under the hood.
Logging is a diverse topic and there are multitudes of different logging frameworks out there.
Frameworks that ship their own logging which is fully decoupled from your application's logging strategy are a bit cumbersome, so nut.js chose a different approach.
Instead of shipping a logging framework, nut.js now ships with a logging provider interface, which allows you to plug in your own logging framework of choice.
By default, nut.js ships a ConsoleLogger
, but by implementing the LogProviderInterface
you can register your own provider that wraps your already in place logging framework to include nut.js log output in your existing logging strategy.
Here's an example of how to use the ConsoleLogger
:
1const { 2 useConsoleLogger, 3 ConsoleLogLevel, 4} = require("@nut-tree/nut-js"); 5 6useConsoleLogger({ logLevel: ConsoleLogLevel.DEBUG }); 7 8(async () => { 9 // ... 10})();
and what the log output looks like:
12023-01-17T00:47:21.748Z - DEBUG - [nut.js] - Search region is valid 22023-01-17T00:47:23.652Z - DEBUG - [nut.js] - Language data for eng already exists in data path /private/tmp/d/node_modules/@nut-tree/ocr/language_data/tessdata, skipping 32023-01-17T00:47:26.305Z - INFO - [nut.js] - Using ocrConfidence override: 0.8 42023-01-17T00:47:26.306Z - DEBUG - [nut.js] - Found match! { 5 location: Region { left: 328, top: 500, width: 141.5, height: 18 }, 6 confidence: 90.44261169433594 7} 82023-01-17T00:47:26.306Z - DEBUG - [nut.js] - 0 hooks triggered for match 92023-01-17T00:47:26.306Z - INFO - [nut.js] - Match is located at (328, 500, 141.5, 18) 102023-01-17T00:47:26.306Z - DEBUG - [nut.js] - Autohighlight is enabled 112023-01-17T00:47:26.307Z - INFO - [nut.js] - Highlighting (328, 500, 141.5, 18) for 0.5 with 25% opacity 122023-01-17T00:47:26.958Z - INFO - [nut.js] - Moving mouse to target point (398, 509)
The approach of connecting your own log provider is similar:
1import { useLogger, LogLevel, LogProviderInterface } from "@nut-tree/nut-js"; 2 3class Logger implements LogProviderInterface { 4 debug(message: string, data: {} | undefined): void { 5 // ... 6 } 7 8 error(error: Error, data: {} | undefined): void { 9 // ... 10 } 11 12 info(message: string, data: {} | undefined): void { 13 // ... 14 } 15 16 trace(message: string, data: {} | undefined): void { 17 // ... 18 } 19 20 warn(message: string, data: {} | undefined): void { 21 // ... 22 } 23} 24 25useLogger(new Logger());
screen.find
got a lot of love in this release.
It now supports additional types of Finders
, so now you can not just find images on screen, but also text and/or windows.
These new types of Finders
seamlessly integrate into the existing screen.find
API, so you can use them in the same way as you would use the ImageFinder
:
1const { 2 mouse, 3 screen, 4 singleWord, 5 sleep, 6 useConsoleLogger, 7 ConsoleLogLevel, 8 straightTo, 9 centerOf, 10 Button, 11 getActiveWindow, 12} = require("@nut-tree/nut-js"); 13const { 14 preloadLanguages, 15 Language, 16 LanguageModelType, 17 configure, 18} = require("@nut-tree/plugin-ocr"); 19 20configure({ languageModelType: LanguageModelType.BEST }); 21 22useConsoleLogger({ logLevel: ConsoleLogLevel.DEBUG }); 23 24screen.config.autoHighlight = true; 25screen.config.ocrConfidence = 0.8; 26 27function activeWindowRegion() { 28 return getActiveWindow().then((activeWindow) => activeWindow.region); 29} 30 31(async () => { 32 await preloadLanguages([Language.English], [LanguageModelType.BEST]); 33 await sleep(5000); 34 const result = await screen.find(singleWord("nut-tree")); 35 await mouse.move(straightTo(centerOf(result))); 36 await mouse.click(Button.LEFT); 37 await screen.waitFor(singleWord("Native"), 15000, 1000, { 38 providerData: { partialMatch: true }, 39 }); 40 const content = await screen.read({ searchRegion: activeWindowRegion() }); 41 console.log(content); 42})();
This way it's now possible to waitFor
a window to appear, findAll
occurrences of text on screen, or, just like it was already possible, find
an image.
But wait, there's even more! 🤯
Not only did I release nut.js v3.0.0, but I also updated/built plugins!
ImageFinder
plugins to comply with the new OptionalSearchParameters
interface.All of these packages are only available to sponsors of nut.js, so if you want to get your hands on them, you can do so by becoming a sponsor.
See the FAQ for additional information and the plugins section for available plugins.
Get it on npm
Please share your feedback on Twitter/GitHub/Discord!
All the best
Simon
© 2023