electron - 在不使用 nodeIntegration true 的情况下在电子中启用屏幕共享
问题描述
我正在电子中创建本机应用程序。为此,我创建了一个 BrowserWindow 并使用 nodeIntegration false 将 url 加载到其中。如果在浏览器中打开,在我的网站上一切正常。但是,如果我在电子中运行相同,则屏幕共享不起作用。我尝试使用一些在线参考来实现它,例如使用“预加载”来加载 js 文件。但没有任何效果
我为此使用最新的电子。
main.js
const {app, BrowserWindow} = require('electron');
const path = require('path');
let mainWindow
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: false,
allowRunningInsecureContent: true,
preload: path.join(__dirname, 'loadScripts.js')
}
});
mainWindow.loadURL("https://abc.xyz.com/dkajd");
mainWindow.webContents.openDevTools();
}
app.on('ready', createWindow);
app.on('activate', function () {
if (mainWindow === null) createWindow()
});
加载脚本.js
const { desktopCapturer } = require('electron');
let mediaSources = null;
desktopCapturer.getSources({ types: ['window', 'screen'] },(err, sources) => {
mediaSources = sources;
});
解决方案
推荐阅读
- r - gtsummary 中具有计算数据集/加权计数的交叉表
- c++ - 如何读取带有 ESP32 中断和全局标志的旋转编码器
- python-3.x - 音乐机器人的音量只会下降,但不会上升
- javascript - 图像滑块到达尽头,无处可去
- typescript - 在 TypeScript 的子类中自动覆盖多个函数的返回类型
- sql-server - SSIS 调用 Powershell - 无法识别该术语
- c - 将c程序编译为mips二进制文件后出现“无法执行二进制文件:执行格式错误”
- javascript - JustSwap智能合约如何完成swap方法
- flutter - Flutter 在标记指针所在的位置获取 lat 和 long 值
- android - 您的动态链接路径前缀未在 firebase.json 中配置