Skip to content

Crazy region based screenshot behavior on macOS #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 3 tasks
svettwer opened this issue Dec 9, 2020 · 8 comments
Closed
1 of 3 tasks

Crazy region based screenshot behavior on macOS #194

svettwer opened this issue Dec 9, 2020 · 8 comments
Labels
wontfix This will not be worked on

Comments

@svettwer
Copy link
Contributor

svettwer commented Dec 9, 2020

Version
next

Short overview
Screenshots based on Regions on macOS are do not reflect screen content.

Issue occurs on

  • Virtual machine
  • Docker container
  • Dev/Host system

Detailed error description
I'm using the following workaround from #154 to create a screenshot of a region

  const regionCapture = async (
    selectedRegion: NutRegion,
    outputFilename: string
  ) => {
    const regionImage = await (<any>screen).vision.grabScreenRegion(
      selectedRegion
    );
    await (<any>screen).vision.saveImage(regionImage, outputFilename);
  };

Based on the provided region, I receive various errors or incorrect images.
I'm working on a 1920x1080 build agent and configured it as described here.

with new NutRegion(0, 100, 650, 200) I get:
ocr-screenshot

with new NutRegion(0, 50, 325, 100) I get:
ocr-screenshot
Just thought a reduction of the resolution could help.

with new NutRegion(0, 0, 1900, 1000) I get:

[Wed Dec 09 2020 13:04:35 GMT+0000 (Coordinated Universal Time)] ERROR: Error in testcase getTextFromRegion: Error: Given width exceeds display dimensions
Error: Error: Given width exceeds display dimensions
    at Object.module.exports.screen.capture (/Users/runner/work/sakuli-ocr/sakuli-ocr/packages/sakuli-ocr/node_modules/@nut-tree/libnut-darwin/index.js:32:16)
    at /Users/runner/work/sakuli-ocr/sakuli-ocr/packages/sakuli-ocr/node_modules/@nut-tree/nut-js/dist/lib/provider/native/libnut-screen-action.class.js:30:46
    at new Promise (<anonymous>)
    at ScreenAction.grabScreenRegion (/Users/runner/work/sakuli-ocr/sakuli-ocr/packages/sakuli-ocr/node_modules/@nut-tree/nut-js/dist/lib/provider/native/libnut-screen-action.class.js:29:16)
    at VisionAdapter.grabScreenRegion (/Users/runner/work/sakuli-ocr/sakuli-ocr/packages/sakuli-ocr/node_modules/@nut-tree/nut-js/dist/lib/adapter/vision.adapter.class.js:43:28)

Whole screen
Funny enough, when I take a screenshot with grabScreen, it looks as expected.
2020-12-09T13-22-21_error_e2e-suite_getTextFromRegion

Steps to reproduce error
As this happens on a build agent and because I've no mac myself, I cannot provide any information, unfortunately.

@svettwer
Copy link
Contributor Author

svettwer commented Jan 8, 2021

We were able to reproduce the error during travis to GH Action migration of https://github.com/sakuli/sakuli as well. But this time, the issue also occurred with grabScreen. As nut.js is already on GH actions, it would be interesting to get some screenshots from within the build runner. 🤔

@s1hofmann Do you have an Idea what could cause this issue? We're currently a little confused about the root cause to be honest. 🙈

@s1hofmann
Copy link
Member

@svettwer I'm currently debugging this issue to analyse the root cause.

@svettwer
Copy link
Contributor Author

Awesome! Let me know if I can help. 👍

@s1hofmann
Copy link
Member

Will continue later this evening. Might hit you up for a little session, depending on how late my later will be.

@s1hofmann
Copy link
Member

s1hofmann commented Jan 14, 2021

@svettwer When capturing the whole screen via libnut.screen.capture(); and libnut.screen.capture(0, 0, libnut.screen.width, libnut.screen.height); it gives comparable data.
Once stored, there are offsets present within the region based data, resulting in an image tilt.

Overall, the issue seems not to be related to the capturing mechanism in libnut, will investigate further.

@s1hofmann
Copy link
Member

@svettwer More details on why this happens can be found here: nut-tree/libnut-core#44

Looks like a platform problem.

@s1hofmann
Copy link
Member

And it seems like it’s no longer a problem on Big Sur: https://github.com/nut-tree/libnut/actions/runs/500905237

@s1hofmann s1hofmann added the wontfix This will not be worked on label Jan 22, 2021
@s1hofmann
Copy link
Member

To sum things up: Broken screenshots are caused by and only happen on macOS Catalina. As it is no problem on Big Sur I guess we’ll live with it until explicitly required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants