Bug 49167 - [Qt] Turning off Javascript in QWebSettings disables QWebFrame::evaluateJavaScript
Summary: [Qt] Turning off Javascript in QWebSettings disables QWebFrame::evaluateJavaS...
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Qt (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P4 Enhancement
Assignee: Nobody
URL:
Keywords: Qt, QtTriaged
Depends on:
Blocks:
 
Reported: 2010-11-08 03:54 PST by Bernhard Rosenkraenzer
Modified: 2014-02-03 03:16 PST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bernhard Rosenkraenzer 2010-11-08 03:54:48 PST
In current Qt 4.7 git builds, this:

QWebPage *something;
something->settings()->setAttribute(QWebSettings::JavascriptEnabled, false);
something->currentFrame()->evaluateJavaScript("alert('test');");

doesn't pop up an alert box.

It's arguable whether or not it should -- one could say disabling Javascript should do just that and disable Javascript, but one could also say that disabling Javascript followed by an explicit request to run Javascript should do it (purpose e.g.: Prevent an untrusted page's Javascript from running, but still use (trusted) JS to manipulate the page's display).

The best solution is probably to have both, a QWebSettings::JavascriptEnabled and a QWebSettings::AppJavascriptEnabled or something.
Comment 1 Benjamin Poulain 2010-11-10 05:42:19 PST
Could you provide good use cases for this feature?

I give the task a low priority since I don't think it is critical, but you can work on it directly. I think that might be as simple as using ScriptController::evaluate() instead of ScriptController::executeScript().
Comment 2 Bernhard Rosenkraenzer 2010-11-10 06:16:57 PST
Use case 1:

User is paranoid about JS bits downloaded from the net and wants them turned off, but we use local JS contained in the application for features like highlighting parts of the document the user is reading.


Use case 2:

Implementing an editor that operates on HTML files with specific addons.
Basically the thing is a QWebView with contentEditable enabled; when the user is done, the content is saved through QWebElement::outerXml().

Some of the addons are done through JavaScript and must not be run while in the editor (because the scripts modify the DOM tree and therefore QWebElement::outerXml would return the script's output instead of the source material plus the invocations of the script), while local JS contained in the application is needed to control adding new elements.
Comment 3 Caio Marcelo de Oliveira Filho 2011-02-23 10:50:56 PST
QWebPage::addToJavaScriptWindowObject() was changed to not work when Javascript is not enabled because it was crashing.

https://bugs.webkit.org/show_bug.cgi?id=26906

In case of having a QWebSettings::AppJavascriptEnabled, I think that if one method (evaluate) works, the other (addTo...) should work as well.
Comment 4 Jocelyn Turcotte 2014-02-03 03:16:56 PST
=== Bulk closing of Qt bugs ===

If you believe that this bug report is still relevant for a non-Qt port of webkit.org, please re-open it and remove [Qt] from the summary.

If you believe that this is still an important QtWebKit bug, please fill a new report at https://bugreports.qt-project.org and add a link to this issue. See http://qt-project.org/wiki/ReportingBugsInQt for additional guidelines.