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. QWebEnginePage es6 modules
Qt 6.11 is out! See what's new in the release blog

QWebEnginePage es6 modules

Scheduled Pinned Locked Moved Solved QtWebEngine
2 Posts 1 Posters 1.1k 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.
  • S Offline
    S Offline
    steno
    wrote on last edited by
    #1

    Can the QWebEnginePage load es6 Modules? When I try to load a es6 module I get the following error, "Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec".

    I tried to intercept the request via QWebEngineUrlRequestInterceptor::interceptRequest and setting the html header with 'Content-type: application/javascript'

    I'm looking for a solution where I don't have to use a local web server. Any suggestions?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      steno
      wrote on last edited by
      #2

      I figured out a solution. Instead of loading files using the file:/// protocol, I used a custom scheme. I then used QWebEngineUrlSchemeHandler:requestStarted to open the files and attach them to QWebEngineUrlRequestJob.

      void UrlSchemeHandler::requestStarted(QWebEngineUrlRequestJob* request)
      {
      	QByteArray requestMethod = request->requestMethod();
      
      	QUrl requestUrl = request->requestUrl();
      	QString requestPath = requestUrl.path();
      
      	QFile* file = new QFile(requestPath);
      	file->setParent(request);
      	Z_VERIFY(connect(request, &QObject::destroyed, file, &QFile::deleteLater));
      	if (!file->exists() || file->size() == 0)
      	{
      		request->fail(QWebEngineUrlRequestJob::UrlNotFound);
      		return;
      	}
      
      	QFileInfo fileInfo = QFileInfo(*file);
      	QMimeDatabase mimeDatabase;
      	QMimeType mimeType = mimeDatabase.mimeTypeForFile(fileInfo);
      	request->reply(QUrl(mimeType.name()).toEncoded(), file);
      }
      
      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