Git Product home page Git Product logo

Comments (8)

s1hofmann avatar s1hofmann commented on May 28, 2024

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.

nickthorp1 avatar nickthorp1 commented on May 28, 2024

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.

nickthorp1 avatar nickthorp1 commented on May 28, 2024

Screenshot 2024-04-16 at 08 21 41

from nut.js.

s1hofmann avatar s1hofmann commented on May 28, 2024

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.

nickthorp1 avatar nickthorp1 commented on May 28, 2024

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.

s1hofmann avatar s1hofmann commented on May 28, 2024

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.

nickthorp1 avatar nickthorp1 commented on May 28, 2024

Great thank you for the help with this!

from nut.js.

s1hofmann avatar s1hofmann commented on May 28, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.