Comments (8)
Hi @nickthorp1 π
Does this happen on each an every try to access screen content?
Something like screen.capture
etc?
Can you enable log output using
import { useConsoleLogger, ConsoleLogLevel } from "@nut-tree/nut-js";
useConsoleLogger({ logLevel: ConsoleLogLevel.DEBUG });
Best regards
Simon
from nut.js.
Hi Simon, Thanks for you help.
So I can able to captureRegion successfully, the code below successfully produces 2 screenshots
import {getActiveWindow, screen, useConsoleLogger, ConsoleLogLevel } from "@nut-tree/nut-js";
import {configure, Language, LanguageModelType, TextSplit, preloadLanguages} from "@nut-tree/plugin-ocr";
useConsoleLogger({ logLevel: ConsoleLogLevel.DEBUG });
const activeWindowRegion = async () => {
const activeWindow = await getActiveWindow();
return activeWindow.region;
}
(async () => {
// await preloadLanguages([Language.English]);
const test1 = await screen.capture('test1')
const coor = new Region(245, 190, 750, 790);
const test2 = await screen.captureRegion(
`test2`,
coor,
);
const text = await screen.read({searchRegion: activeWindowRegion(), split: TextSplit.LINE});
console.log(text)
})();
Output
(base) Nicks-MacBook-Pro:fullProfile nicholasthorp$ node screenCapture.js
2024-04-16T07:19:51.445Z - INFO - [nut.js] - Capturing whole screen (0, 0, 3024, 1964)
2024-04-16T07:19:51.446Z - INFO - [nut.js] - Writing image to /Users/nicholasthorp/Documents/code/nutzv4/fullProfile/test1.png
2024-04-16T07:19:51.873Z - DEBUG - [nut.js] - File written
2024-04-16T07:19:51.873Z - INFO - [nut.js] - Capturing screen region (245, 190, 750, 790)
2024-04-16T07:19:51.886Z - INFO - [nut.js] - Writing image to /Users/nicholasthorp/Documents/code/nutzv4/fullProfile/test2.png
2024-04-16T07:19:52.039Z - DEBUG - [nut.js] - File written
2024-04-16T07:19:52.042Z - INFO - [nut.js] - Active window handle { windowHandle: 142 }
2024-04-16T07:19:52.044Z - INFO - [nut.js] - Reading text from screen at location (0, 0, 0, 982)
/Users/nicholasthorp/Documents/code/nutzv4/node_modules/@nut-tree/libnut-darwin/permissionCheck.js:70
libnut[functionName] = (...args) => askForAccessibility(originalFunction, functionName)(...args);
^
Error: Error: Failed to capture screen
at libnut. (/Users/nicholasthorp/Documents/code/nutzv4/node_modules/@nut-tree/libnut-darwin/permissionCheck.js:70:96)
at Object.libnut. [as captureScreen] (/Users/nicholasthorp/Documents/code/nutzv4/node_modules/@nut-tree/libnut-darwin/permissionCheck.js:74:98)
at Object.module.exports.screen.capture (/Users/nicholasthorp/Documents/code/nutzv4/node_modules/@nut-tree/libnut-darwin/index.js:38:20)
at /Users/nicholasthorp/Documents/code/nutzv4/node_modules/@nut-tree/nut-js/node_modules/@nut-tree/libnut/dist/lib/libnut-screen.class.js:29:62
at new Promise ()
at ScreenAction.grabScreenRegion (/Users/nicholasthorp/Documents/code/nutzv4/node_modules/@nut-tree/nut-js/node_modules/@nut-tree/libnut/dist/lib/libnut-screen.class.js:28:16)
at ScreenClass.grabRegion (/Users/nicholasthorp/Documents/code/nutzv4/node_modules/@nut-tree/nut-js/dist/lib/screen.class.js:374:14)
at async ScreenClass.readText [as read] (/Users/nicholasthorp/Documents/code/nutzv4/node_modules/@nut-tree/plugin-ocr/dist/src/readText.function.js:18:50)
at async file:///Users/nicholasthorp/Documents/code/nutzv4/fullProfile/screenCapture.js:17:14
(base) Nicks-MacBook-Pro:fullProfile nicholasthorp$
from nut.js.
from nut.js.
Hi @nickthorp1 π
The log tells us that it's related to the active window region:
Reading text from screen at location (0, 0, 0, 982)
The window dimensions are messed up. Which kind of window are you targeting?
from nut.js.
Hi Simon,
I have a monitor and a 14inch Mac M3, I think it was because I was using a monitor. Is there away to use both so I can have the code on the monitor and my mac as the active window?
from nut.js.
Itβll work as long as your automation runs on the main screen.
nut.js currently only supports a single screen (the main one), so this has to be ensured.
Your code would be on the second screen.
Edit: Since this is actually working as documented Iβd close this issue
from nut.js.
Great thank you for the help with this!
from nut.js.
@nickthorp1 If you want to make sure the window is always located within the main screen area you could simply move the window to position (0,0) which is defined to be the upper left corner of the main screen.
from nut.js.
Related Issues (20)
- TypeError when loading nut.js in Electron main process HOT 6
- Update Window tutorial
- Focus doesn't seem to always focus properly HOT 11
- Nutjs does not output correctly on window when using boardkey.type () to output Chinese HOT 1
- Package no longer supported [email protected] HOT 1
- Hi From CodeVideo - we're interested in writing a "human-like mouse movement" plugin for nut-js! HOT 2
- OCR says it failed to detect text but seemed to detect it with a high confidence best match HOT 4
- Create a custom plugin example
- 32Bit Electron build create some error HOT 1
- 32 bit UnSupported platfrom how to solve this like prob. HOT 1
- libnut.node: cannot open shared object file: No such file or directory HOT 11
- nl-matcher performance low when run on Electron.
- Not Installing on MAc OS HOT 10
- Minimum/Maximum Screen Dimensions Error HOT 1
- Clarification on number of users in subscription. HOT 4
- window.getElements() return type incorrect
- not word install HOT 1
- npm install fails with 404 error not found in registry HOT 6
- NPM install Not working HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nut.js.