pywebview能否使用webrtc远程控制共享桌面和摄像头?
网友回复
windows mac可以,pywebview 只是“壳”:它嵌入系统 WebView 组件,WebRTC 能力取决于底层浏览器引擎。
必须通过 HTTPS 或 localhost:现代浏览器要求安全上下文才能访问摄像头/屏幕。
Linux 限制最大:大多数 Linux 发行版的 WebKit2 不支持 navigator.mediaDevices.getDisplayMedia()(屏幕共享),仅能访问摄像头。
Windows/macOS:在 localhost 下可正常使用 getUserMedia()(摄像头)和 getDisplayMedia()(屏幕共享)。
这是我在win10上测试的

完整代码
main.py
import webview
import threading
from flask import Flask, render_template
import os
# 确保 templates 文件夹存在,并包含 index.html
app = Flask(__name__, template_folder='templates')
@app.route('/') # ← 修正:必须以 / 开头
def index():
return render_template('index.html')
def run_server():
app.run(host='localhost', port=5000, debug=False)
if __name__ == '__main__':
# 可选:自动创建 templates 目录和示例 index.html(方便测试)
if not os.path.exists('templates'):
os.makedirs('templates')
with open('templates/index.html', 'w', encoding='utf-8') as f:
f.write('<h1>WebRTC 桌面共享与摄像头控制</h1><p>Flask + pywebview 已成功加载!</p>')
# 启动 Flask 服务器线程
server_thread = threading.Thread(target=run_server, daemon=True)
server_thread.start()
# 创建 pywebview 窗口,加载本地页面
webview.create_window(
'WebRTC 桌面共享与摄像头控制',
'http://localhost:5000', # ← 修正 URL 格式
width=1200,
height=800
)
webview.start()templates/index.html点击查看全文
阿里云ESA、cloudflare worker、腾讯云EdgeOne网站代理托管哪家更好?
剪映能打开.fcpxml格式的文件吗?
增量式编码器与绝对式编码器的区别是啥?
有没有开源的单张照片或者序列帧图片或视频就能重建4d场景动画项目?
chrome网页突然报错:错误代码:RESULT_CODE_KILLED_BAD_MESSAGE
openai的codex如何全程无需手动确认自动修改文件?
阿里云oss前端上传文件直传如何限制文件类型?
阿里云oss前端获取policy签名直传oss上传文件回调如何传?
如何将根据三维物体通过提示词变成可交互的4d场景动画?
浏览器中实时摄像头离线视觉ai模型有吗?


