Skip to content

Instantly share code, notes, and snippets.

@wwj718
Created April 14, 2018 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wwj718/e00ff12ef84a8171a5537ee0a4c0e1fd to your computer and use it in GitHub Desktop.
Save wwj718/e00ff12ef84a8171a5537ee0a4c0e1fd to your computer and use it in GitHub Desktop.
# https://stackoverflow.com/questions/48676566/grant-access-to-cam-mic-using-python-for-pyqt-webengine
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage
from PyQt5.QtCore import QUrl
class WebEnginePage(QWebEnginePage):
def __init__(self, *args, **kwargs):
QWebEnginePage.__init__(self, *args, **kwargs)
self.featurePermissionRequested.connect(self.onFeaturePermissionRequested)
def onFeaturePermissionRequested(self, url, feature):
if feature in (QWebEnginePage.MediaAudioCapture,
QWebEnginePage.MediaVideoCapture,
QWebEnginePage.MediaAudioVideoCapture):
self.setFeaturePermission(url, feature, QWebEnginePage.PermissionGrantedByUser)
else:
self.setFeaturePermission(url, feature, QWebEnginePage.PermissionDeniedByUser)
app = QApplication([])
view = QWebEngineView()
page = WebEnginePage()
view.setPage(page)
view.load(QUrl("https://test.webrtc.org/"))
view.show()
app.exec_()
@wwj718
Copy link
Author

wwj718 commented Apr 14, 2018

@wwj718
Copy link
Author

wwj718 commented Apr 14, 2018

#!/usr/bin/env python
# encoding: utf-8

#from PyQt5.QtWidgets import QApplication
#from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage
#from PyQt5.QtCore import QUrl
import sys
from PySide2.QtCore import QUrl
from PySide2.QtGui import QIcon
from PySide2.QtWidgets import (QApplication, QDesktopWidget, QLineEdit,
    QMainWindow, QPushButton, QToolBar)
from PySide2.QtWebEngineWidgets import QWebEnginePage, QWebEngineView


class WebEnginePage(QWebEnginePage):
    def __init__(self, *args, **kwargs):
        QWebEnginePage.__init__(self, *args, **kwargs)
        self.featurePermissionRequested.connect(self.onFeaturePermissionRequested)

    def onFeaturePermissionRequested(self, url, feature):
        if feature in (QWebEnginePage.MediaAudioCapture,
            QWebEnginePage.MediaVideoCapture,
            QWebEnginePage.MediaAudioVideoCapture):
            self.setFeaturePermission(url, feature, QWebEnginePage.PermissionGrantedByUser)
        else:
            self.setFeaturePermission(url, feature, QWebEnginePage.PermissionDeniedByUser)

app = QApplication([])

view = QWebEngineView()
page = WebEnginePage()
view.setPage(page)
view.load(QUrl("file:///Users/wwj/mylab/changxue/scratch-gui/build/index.html"))
view.show()
app.exec_()

pyqt5 无法使用scratch3 music插件 pyside2正常

@wwj718
Copy link
Author

wwj718 commented Apr 14, 2018

@wwj718
Copy link
Author

wwj718 commented Apr 14, 2018

view.load(QUrl("https://operasoftware.github.io/bb8/")) 无法打开web bluetooth : navigator.bluetooth

http://doc.qt.io/qt-5/qwebenginepage.html 没有看到蓝牙

@wwj718
Copy link
Author

wwj718 commented Apr 14, 2018

@wwj718
Copy link
Author

wwj718 commented Apr 14, 2018

chrome 56之后支持 Blink内核

@wwj718
Copy link
Author

wwj718 commented Apr 14, 2018

@wwj718
Copy link
Author

wwj718 commented Apr 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment