[Qtwebengine] Any way to disable same-origin policy?

Koehne Kai Kai.Koehne at theqtcompany.com
Fri Nov 20 08:55:03 CET 2015



> -----Original Message-----
> From: Kevin Truong [mailto:knt261 at gmail.com]
> [...]
> Kai -- Although my issue is fixed, I'm still curious to try out your method. How do
> I use QWebEngineScript with the QWebEnginePage object that I have? For
> example, I tried to add the following code right after calling m_page-
> >runJavascript(m_script):
> 
> 
> 
> 
>     QWebEngineScriptCollection* scripts = &m_page->scripts();
>     QList<QWebEngineScript> scriptsList = scripts->toList();
>     for (int i = 0; i < scriptsList.size(); i++) {
>         QWebEngineScript script = scriptsList.at(i);
>         script.setRunsOnSubFrames(true);
>     }
> 
> 
> But it doesn't seem to work (maybe the javascript is already finished running
> before I was able to iterate through all the script source and set
> runsOnSubFrames to true). Mind if you point me to the right
> direction/documentation?

You've to replace the runJavaScript() call with a QWebEngineScript.

So

  page.runJavascript(m_script);

becomes e.g.

  QWebEngineScript script; 
  script.setSourceCode(m_script);
  script.setInjectionPoint(QWebEngineScript::DocumentReady);
  script.setRunsOnSubFrames(true);
  page.scripts.insert(script);

Note that you can't set a callback method in this API though.

The relationship with runJavaScript() could be indeed better documented ... I'll have a look.

Regards

Kai


More information about the QtWebEngine mailing list