QWebView - dealing with javascript infinite loop
web_view_crash.py
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtWebKit import *
app = QApplication(sys.argv)
view = QWebView()
view.settings().setAttribute(QWebSettings.JavascriptEnabled, True)
view.load(QUrl('infinite_loop.html'))
view.show()
app.exec_()
infinite_loop.html
<script>
while(true) {
document.write('infinite loop...')}
</script>
I want to fix this from my python code, without touching the javascript. Can I kill the javascript somehow?
Edit: 开发者_开发技巧Both files are local.
sip.delete(page)
will kill the page object, stopping the execution, then all you have to do after that is delete the reference to the page in Python: del page
You might also want to check out subclassing WebPage and re-implementing shouldInterruptJavaScript()
, perhaps killing your page when it executes.
??? This really makes no sense at all. The Javascript file is an infinite loop. You cannot "kill" the page code from the server. It's just impossible - especially when the browser is stuck running CPU-bound Javascript.
Maybe that Javascript file was just supplied as an example, but it doesn't really matter. If you know that you've got a page that's broken in that way, you have to fix the page.
精彩评论