문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top