Not Allowed load local resources QtWebEngine disable web security



  • Hi!

    I'm in trouble with WebEngine web security (on windows) and Qt 5.6.2

    Calling this method with runJavascript

    function doCreateVideoPage(sourcePath,config,start,finish,videofile)
    {
        document.getElementById("main-box").innerHTML = "";
    	var flashvars = "subtitles="+config+"&videourl="+sourcePath+"&start="+start+"&finish="+finish;
        var html = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="10%%" height="100%" id="webenginemanager" align="middle">'
        html += '<param name="movie" value="'+videofile+'" />'
        html += '<param name="FlashVars" value='+flashvars+' />'
        html += '<param name="quality" value="high" />'
        html += '<param  name="bgcolor" value="#000" />'
        html += '<param name="play" value="true" />'
        html += '<param name="loop" value="true" />'
        html += '<param name="wmode" value="window" />'
        html += '<param name="menu" value="true" />'
        html += '<param name="devicefont" value="false" />'
        html += '<param name="salign" value="" />'
        html += '<param name="allowScriptAccess" value="always" />'
        html += '<embed play="false" swliveconnect="true" name="webenginemanager" src="'+videofile+'?'+flashvars+'" quality="high" bgcolor="#000" width="100%" height="100%" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"/>'
        html += '</object>'
        document.getElementById("main-box").innerHTML = html;
    }
    

    my VideoPlayer create correctly

    but get this error in console

     Not allowed to load local resource: file:///C:/Program%20Files%20(x86)/myapp/videoswf/videoplayer.swf?subtitles=C:/Users/dev/AppData/Local/myapp/bWVsb25pQGR1ZGF0Lml0/9788808436566/0b22b9e0-085a-406c-a0d0-f4a85867800e/yefe2e/bbbag/h1ay629z/gxan-nh0j9&videourl=C:/Users/dev/AppData/Local/myapp/bWVsb25pQGR1ZGF0Lml0/9788808436566/0b22b9e0-085a-406c-a0d0-f4a85867800e/yefe2e/bbbag/h1a62/gxanbnh0-q&start=&finish=
    

    So i've tried to run my QApplication with --disable-web-security

    int main(int argc, char *argv[])
    {
       // --ppapi-flash-path =/Users/mariomeloni/Develop/build/
    
        QCommandLineParser opts;
        argv[0] = "--disable-web-security"; // same error with argv[0]="disable-web-security"
        if(argc == 0)
            argc = 1;
        QApplication app(argc,argv);
        // more code
       app.exec();
    }
    

    I'm using Window with Qt 5.6.2

    Any suggestion are welcome
    Sorry for my bad english and thanks in advanced
    I'm really desparate
    GG



  • WebEngine uses neither QCoreApplication::arguments() nor argc/argv
    On Windows they actually use GetCommandLineW

    https://bugreports.qt.io/browse/QTBUG-51963
    This approach does not seems to work, as those arguments are not used on Windows. All places calls GetCommandLine Windows API function.

    for quick test(ing) just try it from command line (or set it as run parameter in the IDE) e.g.:

    • from Qt X.X yy-bit for Desktop (MSVC ZZZZ) command prompt - run:
      myapp.exe --disable-web-security

    • or from IDE > Projects (wrench icon) > Build & Run (section) > Run > Command line arguments : <add> --disable-web-security

    A proper way to change main function arguments argc and argv in code:
    http://stackoverflow.com/questions/1519885/defining-own-main-functions-arguments-argc-and-argv
    (for a complete and C standard conforming solution see D.Shawley's answer)

    NB! argv[0] = /path/program.exe, argv[argc] = NULL
    NB! The data referred to by argc and argv must stay valid for the entire lifetime of the QApplication object.
    Note: argc and argv might be changed as Qt removes command line arguments that it recognizes.



  • Hi!
    Thanks for reply
    I "solved" my problem passing localhost://5052/C/Files [...] file path as arguments
    But still do not work.
    When the player are trying to load the video url a shell opens and close with a message that i can't read.
    I'm out of ideas



  • localhost://.... is the same as 127.0.0.1://.... i.e. it will require (simple) web server to serve the content - I personally prefer latest Mongoose binary
    https://github.com/cesanta/mongoose

    Remember - file:///... protocol means the web browser should load the local file itself, while (local)host:port//... means your browser will try to load it from the server running on the designated host (even when it is local host)

    so now you have two options:

    • you could try '--disable-web-security' with file:///...
    • or try it with localhost://... with a running web-server on localhost (or 127.0.0.1) serving files from these folders

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.