Catching JavaScript error messages.
-
Hi,
To catch JavaScript alert message boxes I reimplemented
javaScriptAlert(QWebFrame * frame, const QString & msg)
to catch alert messages - works as supposed.Do I need to reimplement some other function to catch ALL message boxes?
I need to catch the follwoing message as well that seem to occur from time to time but I can not simulate it here in the lab:
The script on this page appears to have a problem. Do you want to stop the script.
The tite of the Message box says JavaScript Problem - IP ....
Is this covered by reimplementingjavaScriptAlert(QWebFrame * frame, const QString & msg)
I see there a some other like:
javaScriptConfirm(QWebFrame * frame, const QString & msg) javaScriptPrompt(QWebFrame * frame, const QString & msg, const QString & defaultValue, QString * result) shouldInterruptJavaScript()
Do I need to reimplement these too?
Thanks
McL -
@McLion Each of listed methods implements its own kind of dialog box, so e.g. to have customized dialogs with your own style you have to implement them all.
Message box you see now ("The script on this page appears to have a problem....") is provided by default implementation of QWebPage::shouldInterruptJavaScript
-
Follow up:
- Any idea how I can simulate this case?
I have a local web server I can use and where I can manipulate existing JS ... problem is I have no clue of JS. - Does the webView load() return loadFinished() with a fail or a success after the timeout script has been stopped by returning true in shouldInterruptJavaScript() (stop the JS execution)?
- Any idea how I can simulate this case?
-
@McLion said in Catching JavaScript error messages.:
- Any idea how I can simulate this case?
I have a local web server I can use and where I can manipulate existing JS ... problem is I have no clue of JS.
You don't need any server as QtWebKit can load files from file system or qrc resources. To reproduce just put infinite cycle into some event hanler, e.g. into onclick handler of button
- Does the webView load() return loadFinished() with a fail or a success after the timeout script has been stopped by returning true in shouldInterruptJavaScript() (stop the JS execution)?
load() has nothing to do with JS execution, in fact all JS execution starts after loadFinished
- Any idea how I can simulate this case?
-
@Konstantin-Tokarev said in Catching JavaScript error messages.:
load() has nothing to do with JS execution, in fact all JS execution starts after loadFinished
OK ... on second thought that's actually clear.
This means I'll have to take care and initiate a reload for instance.Thanks, McL
-
@McLion said in Catching JavaScript error messages.:
This means I'll have to take care and initiate a reload for instance.
No need to reload page, you can just stop running script
-
@Konstantin-Tokarev
For normal web browsing that would be sufficient, yes.
In my case we use a web-driven GUI. If I stop the script that needed too long (due to some network error or whatever) the GUI is missing on the device.