Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. "Not allowed to load local resource" for iframe, how to disable web security ?!
QtWS25 Last Chance

"Not allowed to load local resource" for iframe, how to disable web security ?!

Scheduled Pinned Locked Moved Unsolved QtWebEngine
5 Posts 4 Posters 10.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cr.zoidberg
    wrote on 16 Nov 2015, 03:25 last edited by cr.zoidberg
    #1

    Hi folk!
    I'm porting my application from WebKit to WebEngine (seems that one is much better for rendering angular-basad html).
    I faced with problem that i can't enable QtWebEngine to load local iframe, despite the fact that i've setup all possible settings that i found:
    =========== code from mainwindow.cpp =================================

    view->page()->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, true);
     view->page()->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
     view->page()->settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, true);
    
     view->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, true);
     view->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
     view->settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, true);
    

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

    The easiest example is to take WebEngine-based FancyBrowser (\Examples\Qt-5.4\webenginewidgets\fancybrowser) and try to load into it local html file like this:

    ---------------------- index.html ---------------

    <html>
    <head>
        <title>Hi there</title>
    </head>
    <body>
        This is a page
        a simple page
        <iframe id="some_idrame" width="0" height="0" style="border: none" src="some_iframe.html" name="target" sandbox="allow-scripts"></iframe>
    </body>
    </html>
    

    ---------------------- some_iframe.html ---------------

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8">
        <title>La-la-la</title>
    </head>
    <body>
        Lalala 
    </body>
    </html>
    

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

    If you setup env var QTWEBENGINE_REMOTE_DEBUGGING to some port, then you can open 127.0.0.1:port and see in console this error: "Not allowed to load local resource".

    I really have no idea now how to solve this problem now... there should be some way to pass to WebEngine something like "--disable-web-security"...

    Thanks for any help!

    1 Reply Last reply
    0
    • K Offline
      K Offline
      knt261
      wrote on 20 Nov 2015, 00:37 last edited by
      #2

      I had the same problem too, and found a fix from the mailing list. You can pass the "--disable-web-security" argument to the QApplication object in your main.cpp.

      ? 1 Reply Last reply 26 Nov 2015, 17:03
      0
      • K knt261
        20 Nov 2015, 00:37

        I had the same problem too, and found a fix from the mailing list. You can pass the "--disable-web-security" argument to the QApplication object in your main.cpp.

        ? Offline
        ? Offline
        A Former User
        wrote on 26 Nov 2015, 17:03 last edited by
        #3

        @knt261

        You can pass the "--disable-web-security" argument to the QApplication object in your main.cpp.

        Hi – Can you show the code to do that (I'm new at this).

        thanks!

        K 1 Reply Last reply 2 Dec 2015, 11:17
        0
        • ? A Former User
          26 Nov 2015, 17:03

          @knt261

          You can pass the "--disable-web-security" argument to the QApplication object in your main.cpp.

          Hi – Can you show the code to do that (I'm new at this).

          thanks!

          K Offline
          K Offline
          knt261
          wrote on 2 Dec 2015, 11:17 last edited by knt261 12 Feb 2015, 11:20
          #4

          @TOMATO_QT In your main function, you should have initialized a QApplication object, for example:

          QApplication a(argc, argv);
          

          argc is the number of arguments passed into your QApplication, and argv is the array of strings (each one being the actual argument passed into your QApplication). Just make sure one of the strings in your argv is "--disable-web-security" (and make sure argc is the correct count)

          The simplest way to do this, is to start your main function like this:

          int main(int argc, char *argv[])
          {
           QApplication a(argc, argv);
           ...
          }
          

          This passes all of your program's arguments into the QApplication arguments. Then all you have to do is run your program with the argument, e.g. ./myProgram --disable-web-security.

          M 1 Reply Last reply 27 Jan 2016, 13:33
          0
          • K knt261
            2 Dec 2015, 11:17

            @TOMATO_QT In your main function, you should have initialized a QApplication object, for example:

            QApplication a(argc, argv);
            

            argc is the number of arguments passed into your QApplication, and argv is the array of strings (each one being the actual argument passed into your QApplication). Just make sure one of the strings in your argv is "--disable-web-security" (and make sure argc is the correct count)

            The simplest way to do this, is to start your main function like this:

            int main(int argc, char *argv[])
            {
             QApplication a(argc, argv);
             ...
            }
            

            This passes all of your program's arguments into the QApplication arguments. Then all you have to do is run your program with the argument, e.g. ./myProgram --disable-web-security.

            M Offline
            M Offline
            mahdikhani
            wrote on 27 Jan 2016, 13:33 last edited by
            #5

            @knt261
            this solution not work for me;
            I test this solution in Qt5.6

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved