平臺(tái):mac
在項(xiàng)目打包后,訪問(wèn)某一頁(yè)面,調(diào)用了攝像頭麥克風(fēng),devTool disconnected from the page ...,然后就白屏,想到可能是權(quán)限的問(wèn)題
步驟如下:
- 在項(xiàng)目根目錄下創(chuàng)建一個(gè)entitlements.mac.plist文件,并寫(xiě)入下面的代碼;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
<true/>
<key>com.apple.security.device.audio-input</key>
<true/>
<key>com.apple.security.device.camera</key>
<true/>
</dict>
</plist>
- 在package.json中配置plist。
"entitlements": "entitlements.mac.plist",
"hardenedRuntime": true,
"extendInfo": {
"NSMicrophoneUsageDescription": "請(qǐng)?jiān)试S本程序訪問(wèn)您的麥克風(fēng)",
"NSCameraUsageDescription": "請(qǐng)?jiān)试S本程序訪問(wèn)您的攝像頭"
},

image.png
hardenedRuntime 這個(gè)屬性,在 electron-builder 的 21.1.3 版本已經(jīng)默認(rèn)為 true ,而在 21.1.2 ~ 20.41.0 版本里,這個(gè)屬性的默認(rèn)值是 false。再往后的版本里沒(méi)有這個(gè)屬性。
打包之后在某些電腦出現(xiàn)白屏devTool disconnected from the page ...,后來(lái)查詢得知
在 macOS 10.13 High Sierra 或更低版本上不需要用戶授權(quán),因此此方法總是返回 granted。 macOS 10.14 Mojave 或更高版本需要授權(quán)訪問(wèn) 麥克風(fēng) 和 攝像頭。 macOS 10.15 Catalina 或更高版本需要授權(quán)訪問(wèn) 屏幕。原文
高版本必須主動(dòng)去詢問(wèn)