-
-
Notifications
You must be signed in to change notification settings - Fork 171
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
Accessibility Access prompt shows every time I use active-win
on Mac OS in electron app
#135
Comments
I'm having the same problem (different app and goal but exact same problem) however it only happens when the app is compiled, during dev mode that doesn't happen. i'm thinking it can be the privilege the app gets when it is opened from terminal, but i'd need to do a bit of research to figure out how to bypass it or fix it at least during build time. |
Same here 😑 In dev it works as described. After building it keeps asking for permission. Also tried option |
I kinda solved the problem by modifying the main.swift file and compiling it. It will prompt a different permission but it'll only appears once, i'm not really into swift so i can know how it exactly works but i'm going to do a bit more research so i can explain it better /*
if !AXIsProcessTrustedWithOptions(["AXTrustedCheckOptionPrompt": true] as CFDictionary) {
print("active-win requires the accessibility permission in “System Preferences › Security & Privacy › Privacy › Accessibility”.")
exit(1)
}
// Show screen recording permission prompt if needed. Required to get the complete window title.
if !disableScreenRecordingPermission && !hasScreenRecordingPermission() {
print("active-win requires the screen recording permission in “System Preferences › Security & Privacy › Privacy › Screen Recording”.")
exit(1)
}*/ |
@JoseMoreville Thx a lot. That helped for the moment 🙏 |
No problem, it looks like a fix for the moment, but surprisingly makes everything work. |
@JoseMoreville so you just uncommented those lines? Link to your forked main.swift Perhaps something is not right in those if statements. if !AXIsProcessTrustedWithOptions(["AXTrustedCheckOptionPrompt": true] as CFDictionary) {
print("active-win requires the accessibility permission in “System Preferences › Security & Privacy › Privacy › Accessibility”.")
exit(1)
}
// Show screen recording permission prompt if needed. Required to get the complete window title.
if !disableScreenRecordingPermission && !hasScreenRecordingPermission() {
print("active-win requires the screen recording permission in “System Preferences › Security & Privacy › Privacy › Screen Recording”.")
exit(1) I would assume what is going on in your case is that the operating system prompts the user with some kind of prompt, since it's a built in security feature that you can't bypass. And that built in prompts seems to work fine in terms of showing up only once? |
@braaar Indeed, it prompts a dialog to ask for permissions but as chrome (the version electron's using) once you accept it, you'll never see it again. This is just one example of my implementation as a experimental feature for my app, i'll make the main to send the data instead of the renderer asking for it every 1000ms (performance reasons) //renderer
if(shouldVideoBeMuted.value === false){
setInterval(()=>{
window.ipcRenderer.invoke('active', 'active').then((active) => {
if(active !== undefined || active?.title !== undefined){
isBackgroundActive.value = false;
}else{
isBackgroundActive.value = true;
}
if(isBackgroundActive.value){
shouldVideoBeMuted.value = false;
document.getElementsByTagName('video')[0].volume = 0.33;
}else{
shouldVideoBeMuted.value = true;
}
});
}, 1000);
} // main
ipcMain.handle('active', async (event, arg) => {
return await activeWindow.sync();
}) |
Thanks a lot, @JoseMoreville, that helped a lot! I don't know this is nessasary for all macos versions though... |
Hello again, I could not let go on that issue, since for me even though I could run the app with active-win, I was not able to get the window titles. Btw, by using this package: https://github.com/karaggeorge/mac-screen-capture-permissions Once the described executable is added into the "Privacy & Security" permissions "Accessability" and "Screen Recording", "active-win" works just fine. |
Interesting. Could this indicate that there is some kind of problem with the configuration of my electron app such that MacOS isn't told exactly where to find the executable file when asking for permissions? Could the solution be some kind of configuration in This doesn't exactly explain why the problem goes away with @JoseMoreville's fix, though. |
Josemorevilles fix removes the check that makes sure, that you do have the permissions needed to read the title. You only need the Screen Recording permissions for recording the title of the window, which indeed doesent work without setting the permissions as I described- at least not for me, did it still work for you? As for the Accessability permissions - it seems to me like they are not needed at all, so that check is kinda unnessasary, since everything else works without any of those two permissions active. I expected that there might be some plist setting or configuration error aswell... but I wasnt able to find anything helpful on that regard yet :/ |
Have same issue, fight was long term...
Also permission UX with this solution looks better |
None of these solutions appear to have worked for me. Has anyone had any luck resolving this? @itrcz @braaar @svenadlung @Akiriki @JoseMoreville |
I am getting same error in electron js |
How you have done this? Can you please guide me |
I have a Mac M1 max with ventura 13.3.1, and i get this error when i Try to compile init(dispatchQueueDisplay:outputWidth:outputHeight:pixelFormat:properties:queue:handler:)' is only available in macOS 13.0 or newer |
It would appear based on the comments, that the accessibility permissions are only needed when requesting the window title so the e.g.: codebycarlos@051df9c Happy to put a PR through @sindresorhus, if you agree that's the right approach? |
This is perhaps related to but not identical to #88. I don't want to opt out of access dialogs altogether, I just want it to show up once and then recognise the access.
The problem
Every time
activeWindow()
(oractiveWindow.sync()
) is called, this prompt shows up, even though I have added the permissions in system preferences:What I'm doing
I am calling
active-win
in asetInterval
in an electron app built for MacOS withelectron-builder
.Here's my app:
This runs fine in the terminal in VSCode (which asked for the permission once, and from there on it was fine).
Attempts to figure it out
I've also tried using electron's
desktopCapturer
, like so:When I run this, the app asks for permission (for screen recording) once and when it has been granted in the system preferences the prompt does not show up again. So it seem to me that macOS is able to identify my app and give it permissions in that case, at least.
I've tried:
electron-builder
build parameters to make sure all the fields such as bundle ID are set up to uniquely ID the app correctly (no effect)I have not tried:
active-win
and modifying the swift-code to bypass the prompt (as seen in Avoid triggering access dialogs on macOS #67)Additional info
Here's my build config:
entitlements.mac.plist:
The text was updated successfully, but these errors were encountered: