Today I just noticed using evaluateJavaScript()
on a QWebElement
works even with javascript disabled.
This means at least I can do something like:
webview.page().mainFrame().documentElement().evaluateJavaScript("...")
and that works fine.
题
I'm currently writing a small browser, and would like to interact with pages via Javascript (for example for GreaseMonkey-like userscripts).
However I'd like to disable loading of javascript of webpages via QWebSettings
. Now when I do something like:
settings = QWebSettings.globalSettings()
settings.setAttribute(QWebSettings.JavascriptEnabled, False)
javascript from the web doesn't work, but things like evaluateJavaScript
or addToJavaScriptWindowObject
of QWebFrame
don't work anymore either.
I believe dwb which is based on WebKitGTK circumvents this by using the JavaScriptCore library directly.
Can I do something similiar, like maybe use QtScript to evaluate the userscripts myself and bridge them to the webview somehow? Though this doesn't seem exactly like an easy solution to me.
解决方案
Today I just noticed using evaluateJavaScript()
on a QWebElement
works even with javascript disabled.
This means at least I can do something like:
webview.page().mainFrame().documentElement().evaluateJavaScript("...")
and that works fine.