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. How to disable web security policy? I tried many ways but failed. I use qt5.9.2

How to disable web security policy? I tried many ways but failed. I use qt5.9.2

Scheduled Pinned Locked Moved Unsolved QtWebEngine
9 Posts 3 Posters 7.5k 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.
  • K Offline
    K Offline
    kingstying
    wrote on last edited by kingstying
    #1
    This post is deleted!
    1 Reply Last reply
    0
    • K Offline
      K Offline
      kingstying
      wrote on last edited by
      #2

      I run QWebEngineView browser on my arm board. The browser page can not display normally. I think it is "Same Origin Policy" stop the browser loading some files. I have tried three ways, but it seems to useless.
      First way,
      webView->page()->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
      webView->page()->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, true);

      Second way,
      Pass argument "--disable-web-security" or "--disable-web-security --user-data-dir='mydir' " to QApplication object.
      Third way,
      Pass argument "--allow-file-access-from-files" to QApplication object, useless. But i tried command "chrome.exe --allow-file-access-from-files" on Windows, it success.

      Anyone can give me some suggestions?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ambershark
        wrote on last edited by
        #3

        Removed duplicate https://forum.qt.io/topic/88930/qwebengine-browser-can-not-disable-web-security.

        Please don't post the same question multiple times. I am erasing the other one.

        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

        K 1 Reply Last reply
        0
        • A ambershark

          Removed duplicate https://forum.qt.io/topic/88930/qwebengine-browser-can-not-disable-web-security.

          Please don't post the same question multiple times. I am erasing the other one.

          K Offline
          K Offline
          kingstying
          wrote on last edited by
          #4

          @ambershark Could you tell me how to solve this problem?

          A 1 Reply Last reply
          0
          • K kingstying

            @ambershark Could you tell me how to solve this problem?

            A Offline
            A Offline
            ambershark
            wrote on last edited by
            #5

            @kingstying Sorry I haven't used QWebEngine components enough to offer much advice there. And in the little I have used them I've never had to mix remote/local files that require security overrides.

            Hopefully someone else who has done it can chime in here.

            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kingstying
              wrote on last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • D Offline
                D Offline
                DeeeZ
                wrote on last edited by
                #7

                I'm using the flag "--disable-web-security" with QWebEngineView with success on Qt 5.9.X and Qt 5.10

                I don't use "--allow-file-access-from-files" flag since I don't need to access local files ...

                K 1 Reply Last reply
                0
                • D DeeeZ

                  I'm using the flag "--disable-web-security" with QWebEngineView with success on Qt 5.9.X and Qt 5.10

                  I don't use "--allow-file-access-from-files" flag since I don't need to access local files ...

                  K Offline
                  K Offline
                  kingstying
                  wrote on last edited by
                  #8

                  @DeeeZ Thanks you very much. Could you please tell me how do you pass the "--disable-web-security" argument to QWebEngineView? Do you pass it to QApplication object?

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    DeeeZ
                    wrote on last edited by
                    #9

                    Like this:
                    QStringList argumentsAdded;
                    ...
                    argumentsAdded.append("--disable-web-security");
                    ...
                    int i = 0;
                    int new_argc = argc + argumentsAdded.size();
                    char** new_argv = (char **) malloc((new_argc + 1) * sizeof (char *));

                    // Store previous arguments
                    for(i = 0; i < argc; i++)
                    {
                        size_t length = strlen(argv[i])+1;
                        new_argv[i] = (char *) malloc(length);
                        memcpy(new_argv[i], argv[i], length);
                    }
                    
                    // Store new arguments
                    i=0;
                    foreach(QString s, argumentsAdded)
                    {
                        new_argv[argc + i]  = new char[s.toLocal8Bit().size()+1];
                        strcpy( new_argv[argc + i], s.toLocal8Bit().constData());
                        i++;
                    }
                    // Finish array with NULL value
                    new_argv[new_argc] = NULL;
                    
                    // Create a single application to avoid to have several instance
                    QtSingleApplication singleApp(new_argc, new_argv);
                    
                    1 Reply Last reply
                    1

                    • Login

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