Browse Source

Fix issue 315: Allow arbetrery javascript to be run after page loading

Antialize 15 years ago
parent
commit
bc365296fb

+ 3 - 0
include/wkhtmltox/loadsettings.hh

@@ -107,6 +107,9 @@ struct DLL_PUBLIC LoadPage {
 
 	//! Proxy related settings
 	Proxy proxy;
+
+	//! Additional javascript to run on a page once it has loaded
+	QList< QString > runScript;
 };
 
 DLL_PUBLIC LoadPage::LoadErrorHandling strToLoadErrorHandling(const char * s, bool * ok=0);

+ 2 - 2
include/wkhtmltox/pdfsettings.hh

@@ -89,10 +89,10 @@ struct DLL_PUBLIC PdfGlobal {
 
 	//! Be less verbose
 	bool quiet;
-	
+
 	//! Should we use the graphics system
 	bool useGraphics;
-	
+
 	//! Should we orientate in landscape or portrate
 	QPrinter::Orientation orientation;
 

+ 3 - 0
src/lib/loadsettings.hh

@@ -110,6 +110,9 @@ struct DLL_PUBLIC LoadPage {
 
 	//! Proxy related settings
 	Proxy proxy;
+
+	//! Additional javascript to run on a page once it has loaded
+	QList< QString > runScript;
 };
 
 DLL_PUBLIC LoadPage::LoadErrorHandling strToLoadErrorHandling(const char * s, bool * ok=0);

+ 5 - 0
src/lib/multipageloader.cc

@@ -211,6 +211,11 @@ void ResourceObject::loadFinished(bool ok) {
 		} else
 			warning(QString("Failed loading page ") + url.toString() + " (ignored)");
 	}
+
+	// Evaluate extra user supplied javascript
+	foreach (const QString & str, settings.runScript)
+		webPage.mainFrame()->evaluateJavaScript(str);
+
 	if (signalPrint || settings.jsdelay == 0) loadDone();
 	else QTimer::singleShot(settings.jsdelay, this, SLOT(loadDone()));
 }

+ 2 - 1
src/lib/pdf_c_bindings.cc

@@ -83,7 +83,8 @@
  *      - "skip" Do not add the object to the final output
  *      - "ignore" Try to add the object to the final output.
  * - \b load.proxy String describing whact proxy to use when loading the object.
-
+ * - \b load.runScript TODO
+ *
  * \section pageHeaderFooter Header and footer settings
  * The same settings can be applied for headers and footers, here there are explained in
  * terms of the header.

+ 1 - 0
src/lib/reflect.cc

@@ -70,6 +70,7 @@ ReflectImpl<LoadPage>::ReflectImpl(LoadPage & c) {
 	WKHTMLTOPDF_REFLECT(debugJavascript);
 	WKHTMLTOPDF_REFLECT(loadErrorHandling);
 	WKHTMLTOPDF_REFLECT(proxy);
+	WKHTMLTOPDF_REFLECT(runScript);
 }
 
 ReflectImpl<Web>::ReflectImpl(Web & c) {

+ 2 - 0
src/shared/commonarguments.cc

@@ -224,4 +224,6 @@ void CommandLineParserBase::addPageLoadArgs(LoadPage & s) {
 	addarg("stop-slow-scripts", 0, "Stop slow running javascripts", new ConstSetter<bool>(s.stopSlowScripts, true));
 	addarg("no-stop-slow-scripts", 0, "Do not Stop slow running javascripts", new ConstSetter<bool>(s.stopSlowScripts, true));
 #endif
+	addarg("run-script", 0, "Run this additional javascript after the page is done loading (repeatable)", new StringListSetter(s.runScript, "js"));
+
 }