[Qtwebengine] Execute javascript after QWebEnginePage is finished loading gives an error

Kevin Truong knt261 at gmail.com
Fri Nov 6 00:23:49 CET 2015


I'd like to run some javascript after a page has finished loading, but its
giving a CanExecuteJavascript() error in Chromium. My code is pretty
simple, here is my slot:

void MyProject::myFunction(bool ok) {
  if (ok) {
    m_page.runJavaScript("document.body.innerHTML = 'Success!');
  }
}

And then I simply did:

QObject::connect(&m_page, SIGNAL(loadFinished(bool)), this,
SLOT(myFunction(bool)));
m_page.load(url);


This is the error message I received:

===================
[1105/151113:FATAL:render_frame_host_impl.cc(305)] Check failed:
CanExecuteJavaScript().
#0 0x7f631facc67e <unknown>
#1 0x7f631fae331e <unknown>
#2 0x7f631e9aacb3 <unknown>
#3 0x7f631cee68c0 QtWebEngineCore::WebContentsAdapter::runJavaScript()
#4 0x0000004030a7 Render::finishedLoading()
#5 0x7f632227a36e QMetaObject::activate()
#6 0x7f6322f963d2 QWebEnginePage::loadFinished()
#7 0x7f6322f9780b <unknown>
#8 0x7f631ceeb26c <unknown>
#9 0x7f631ebd8a67 <unknown>
#10 0x7f631ebe1c13 <unknown>
#11 0x7f631e9b2983 <unknown>
#12 0x7f631eb0aa6e <unknown>
#13 0x7f631f6ce8b0 <unknown>
#14 0x7f631facdfd5 <unknown>
#15 0x7f631faea799 <unknown>
#16 0x7f631faeab91 <unknown>
#17 0x7f631faeb36b <unknown>
#18 0x7f631cebc5b3 <unknown>
#19 0x7f632227b3bb QObject::event()
#20 0x7f63228554dc QApplicationPrivate::notify_helper()
#21 0x7f632285a640 QApplication::notify()
#22 0x7f632224c6a3 QCoreApplication::notifyInternal()
#23 0x7f632224e913 QCoreApplicationPrivate::sendPostedEvents()
#24 0x7f63222a16f3 <unknown>
#25 0x7f631ac5dc3d g_main_context_dispatch
#26 0x7f631ac5df20 <unknown>
#27 0x7f631ac5dfcc g_main_context_iteration
#28 0x7f63222a1ae7 QEventDispatcherGlib::processEvents()
#29 0x7f632224a252 QEventLoop::exec()
#30 0x7f6322251d3d QCoreApplication::exec()
#31 0x00000040265d main
#32 0x7f63216eca40 __libc_start_main
#33 0x000000402799 _start

Aborted (core dumped)

===================



Note that I can call m_page.runJavaScript() and it won't throw an error if
its called before the loadFinished() is signaled. Why is it that it throws
an error when I call m_page.runJavaScript() after loadFinished() is
signaled? And is there a way to run JavaScript after the page has finished
loading?

All the best,
Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qtwebengine/attachments/20151105/39f55bee/attachment.html>


More information about the QtWebEngine mailing list