Skip to content
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

[Bug] hsWindow:snapshot(true) gives error #2742

Closed
dasmurphy opened this issue Mar 8, 2021 · 3 comments
Closed

[Bug] hsWindow:snapshot(true) gives error #2742

dasmurphy opened this issue Mar 8, 2021 · 3 comments
Assignees
Labels
Milestone

Comments

@dasmurphy
Copy link

dasmurphy commented Mar 8, 2021

I made some tests with the webview and tried to save a screenshot to a file.

The Bug

When i try this it works.

webview:hswindow():snapshot():saveToFile('~/test.png',false,'png')

When i try this to save the transparency in the file, it gives an error.

webview:hswindow():snapshot(true):saveToFile('~/test.png',false,'png')

The error is:

[string "return webview:hswindow():snapshot(true):save..."]:1: ERROR: incorrect number of arguments. Expected 1, got 2
stack traceback:
	[C]: in method 'snapshot'
	[string "return webview:hswindow():snapshot(true):save..."]:1: in main chunk
	[C]: in function 'xpcall'
	...app/Contents/Resources/extensions/hs/_coresetup/init.lua:514: in function <...app/Contents/Resources/extensions/hs/_coresetup/init.lua:494>

The documentation states:

hs.window:snapshot([keepTransparency]) -> hs.image-object

keepTransparency is optional. In the current state it give an error.


Code internals

I think this line is not correct
https://github.com/Hammerspoon/hammerspoon/blob/master/extensions/window/internal.m#L621

[skin checkArgs:LS_TUSERDATA, USERDATA_TAG, LS_TBREAK];

I think it must be something like

[skin checkArgs:LS_TUSERDATA, USERDATA_TAG, LS_TBOOLEAN|LS_TOPTIONAL, LS_TBREAK];

The second parameter check seemed to be wrong, but my Macos development skills are a little bit limited currently and i did not test it out.


Workaround for others

After looking around i found a workaround, which works fine.

hs.window.snapshotForID(webview:hswindow():id(),true):saveToFile('~/test.png',false,'png')

Question

Would it be possible to fix this? In theory you can't save any transparency currently. Look fairly easy to fix and release it.

@cmsj cmsj self-assigned this Mar 8, 2021
@cmsj cmsj added the bug label Mar 8, 2021
@cmsj cmsj added this to the 0.9.85 milestone Mar 8, 2021
@cmsj
Copy link
Member

cmsj commented Mar 8, 2021

Thanks for the great bug report - you nailed it with where the mistake is. I'll fix it momentarily.

@cmsj cmsj closed this as completed in 8fa8528 Mar 8, 2021
cmsj added a commit that referenced this issue Mar 8, 2021
Fix hs.window:snapshot() transparency option. Closes #2742
@luckman212
Copy link
Contributor

@dasmurphy nice, I ran into this too and was going to report it- you nailed it 👍

@dasmurphy
Copy link
Author

@cmsj Thanks for the fix!

@luckman212 Hope my workaround helped you a little bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants