2

I'm making a web browser in Python and PyQt5 and I want to enable allowGeolocationOnInsecureOrigins in my web browser so I can access users location via Google Geo Location API.

Code

self.browser = QWebEngineView()
self.browser.allowGeolocationOnInsecureOrigins(1) 

Error

self.browser.allowGeolocationOnInsecureOrigins(1)
AttributeError: 'QWebEngineView' object has no attribute 'allowGeolocationOnInsecureOrigins'
Muhammad Azeem
  • 309
  • 1
  • 2
  • 9

1 Answers1

3

enum QWebEngineSettings::WebAttribute

QWebEngineSettings::AllowWindowActivationFromJavaScript Since Qt 5.7, only secure origins such as HTTPS have been able to request Geolocation features. This provides an override to allow non secure origins to access Geolocation again. Disabled by default. (Added in Qt 5.9)

import sys
from PyQt5.QtCore    import QUrl
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineSettings

app = QApplication(sys.argv)

browser = QWebEngineView()
browser.page().settings().setAttribute(                            # <---
    QWebEngineSettings.AllowGeolocationOnInsecureOrigins, True)    # <---

browser.load(QUrl("https://doc.qt.io/qt-5/qwebenginesettings.html#WebAttribute-enum"))
browser.show()

sys.exit(app.exec_())

enter image description here

Community
  • 1
  • 1
S. Nick
  • 12,879
  • 8
  • 25
  • 33
  • I'm Facing this error self.browser.page().settings().setAttribute(QWebEngineSettings.AllowGeolocationOnInsecureOrigins, True) AttributeError: type object 'QWebEngineSettings' has no attribute 'AllowGeolocationOnInsecureOrigins' – Muhammad Azeem Feb 28 '19 at 13:30
  • Post an example in the question that you run. – S. Nick Feb 28 '19 at 14:05
  • Thank You so much for reply. You need code for examine? – Muhammad Azeem Feb 28 '19 at 14:59
  • Sorry, I don't need anything. I posted an example to help you. You write that my example gives you an error. So I suggest post an example which gives an error. – S. Nick Feb 28 '19 at 15:15