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. QWebEngine Cannot read properties of null (reading 'postMessage')
Forum Updated to NodeBB v4.3 + New Features

QWebEngine Cannot read properties of null (reading 'postMessage')

Scheduled Pinned Locked Moved Unsolved QtWebEngine
3 Posts 1 Posters 625 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.
  • R Offline
    R Offline
    Roberrt
    wrote on 14 Nov 2023, 08:14 last edited by
    #1

    I'm embedding a discord widget on a c++ application using QWebEngineView, the widget is working all fine, the problem is the login.

    I'm able to login on my discord account from the widget, but after the login window is closed and returns to widget, i get these errors on console:

    js: Error with Permissions-Policy header: Origin trial controlled feature not enabled: 'interest-cohort'.
    js: Unrecognized Content-Security-Policy directive 'prefetch-src'.
    js: Uncaught (in promise) function(){}
    js: Unrecognized Content-Security-Policy directive 'prefetch-src'.
    js: Unrecognized Content-Security-Policy directive 'prefetch-src'.
    js: Uncaught (in promise) Error: Cannot find module './notosans-400-normalitalic.woff2'
    js: Unrecognized Content-Security-Policy directive 'prefetch-src'.
    js: Unrecognized Content-Security-Policy directive 'prefetch-src'.
    js: Uncaught (in promise) #<Object>
    js: [DEPRECATED] Please use `subscribeWithSelector` middleware
    js: Window state not initialized window-1
    js: Window state not initialized window-1
    js: Window state not initialized window-1
    js: Uncaught TypeError: Cannot read properties of null (reading 'postMessage')
    

    Reproducible example:

    class WebEnginePage : public QWebEnginePage
    {
    	Q_OBJECT
    
    public:
    	WebEnginePage(QObject* parent = nullptr) : QWebEnginePage(parent) {}
    
    	QWebEnginePage* createWindow(QWebEnginePage::WebWindowType type) override
    	{
    		QWebEnginePage* page = new QWebEnginePage(this);
    		// To make the page be opened in the same window.
    		connect(page, &QWebEnginePage::urlChanged, this, [=]
    		{
    			setUrl(page->url());
    			page->deleteLater();
    		});
    		return page;
    	}
    };
    
    int main(int argc, char* argv[])
    {
    	QApplication app(argc, argv);
    	QWebEngineView* view = new QWebEngineView;
    	WebEnginePage* page = new WebEnginePage(view);
    	page->setUrl(QUrl("qrc:/test.html"));
    	view->setPage(page);
    	view->setMinimumSize(800, 600);
    	view->show();
    	return app.exec();
    }
    

    I also tried to install a url request interceptor in the page profile and add the policy header seen in the error log "interest-cohort", but I continued getting the errors:

    RequestsInterceptor* requestsInterceptor = new RequestsInterceptor;
    page->profile->setUrlRequestInterceptor(requestsInterceptor);
    
    
    class RequestsInterceptor : public QWebEngineUrlRequestInterceptor
    {
        Q_OBJECT    
    public:
    	virtual void interceptRequest(QWebEngineUrlRequestInfo& info) override
    	{
    		info.setHttpHeader("Permissions-Policy", "interest-cohort=()");
    		info.setHttpHeader("Access-Control-Allow-Origin", "*");
    		//qDebug() << info.firstPartyUrl();
    		//qDebug() << info.navigationType();
    		//if (info.firstPartyUrl().toString().contains("https://s-e.widgetbot.io/api/auth/discord/cb"))
    		//	info.setHttpHeader("Access-Control-Allow-Origin", "*");
    	}
    };
    

    I've been searching the error Cannot read properties of null (reading 'postMessage')
    and found this issue, i'm confused if the problem is on js side, the widget side or on QWebEngine.

    The widget works fine when tested on a browser and i'm able to login:

       // qrc:/test.html
       <script src='https://cdn.jsdelivr.net/npm/@widgetbot/crate@3' async defer>
       const crate = new Crate({
       	server: '1173813471083761744',
       	channel: '1173813471083761747',
       })
       </script>
    

    Widget example: https://jsfiddle.net/wdzgo31y/

    https://i.imgur.com/ibmyYnO.gif

    R 1 Reply Last reply 19 Nov 2023, 06:40
    0
    • R Roberrt
      14 Nov 2023, 08:14

      I'm embedding a discord widget on a c++ application using QWebEngineView, the widget is working all fine, the problem is the login.

      I'm able to login on my discord account from the widget, but after the login window is closed and returns to widget, i get these errors on console:

      js: Error with Permissions-Policy header: Origin trial controlled feature not enabled: 'interest-cohort'.
      js: Unrecognized Content-Security-Policy directive 'prefetch-src'.
      js: Uncaught (in promise) function(){}
      js: Unrecognized Content-Security-Policy directive 'prefetch-src'.
      js: Unrecognized Content-Security-Policy directive 'prefetch-src'.
      js: Uncaught (in promise) Error: Cannot find module './notosans-400-normalitalic.woff2'
      js: Unrecognized Content-Security-Policy directive 'prefetch-src'.
      js: Unrecognized Content-Security-Policy directive 'prefetch-src'.
      js: Uncaught (in promise) #<Object>
      js: [DEPRECATED] Please use `subscribeWithSelector` middleware
      js: Window state not initialized window-1
      js: Window state not initialized window-1
      js: Window state not initialized window-1
      js: Uncaught TypeError: Cannot read properties of null (reading 'postMessage')
      

      Reproducible example:

      class WebEnginePage : public QWebEnginePage
      {
      	Q_OBJECT
      
      public:
      	WebEnginePage(QObject* parent = nullptr) : QWebEnginePage(parent) {}
      
      	QWebEnginePage* createWindow(QWebEnginePage::WebWindowType type) override
      	{
      		QWebEnginePage* page = new QWebEnginePage(this);
      		// To make the page be opened in the same window.
      		connect(page, &QWebEnginePage::urlChanged, this, [=]
      		{
      			setUrl(page->url());
      			page->deleteLater();
      		});
      		return page;
      	}
      };
      
      int main(int argc, char* argv[])
      {
      	QApplication app(argc, argv);
      	QWebEngineView* view = new QWebEngineView;
      	WebEnginePage* page = new WebEnginePage(view);
      	page->setUrl(QUrl("qrc:/test.html"));
      	view->setPage(page);
      	view->setMinimumSize(800, 600);
      	view->show();
      	return app.exec();
      }
      

      I also tried to install a url request interceptor in the page profile and add the policy header seen in the error log "interest-cohort", but I continued getting the errors:

      RequestsInterceptor* requestsInterceptor = new RequestsInterceptor;
      page->profile->setUrlRequestInterceptor(requestsInterceptor);
      
      
      class RequestsInterceptor : public QWebEngineUrlRequestInterceptor
      {
          Q_OBJECT    
      public:
      	virtual void interceptRequest(QWebEngineUrlRequestInfo& info) override
      	{
      		info.setHttpHeader("Permissions-Policy", "interest-cohort=()");
      		info.setHttpHeader("Access-Control-Allow-Origin", "*");
      		//qDebug() << info.firstPartyUrl();
      		//qDebug() << info.navigationType();
      		//if (info.firstPartyUrl().toString().contains("https://s-e.widgetbot.io/api/auth/discord/cb"))
      		//	info.setHttpHeader("Access-Control-Allow-Origin", "*");
      	}
      };
      

      I've been searching the error Cannot read properties of null (reading 'postMessage')
      and found this issue, i'm confused if the problem is on js side, the widget side or on QWebEngine.

      The widget works fine when tested on a browser and i'm able to login:

         // qrc:/test.html
         <script src='https://cdn.jsdelivr.net/npm/@widgetbot/crate@3' async defer>
         const crate = new Crate({
         	server: '1173813471083761744',
         	channel: '1173813471083761747',
         })
         </script>
      

      Widget example: https://jsfiddle.net/wdzgo31y/

      https://i.imgur.com/ibmyYnO.gif

      R Offline
      R Offline
      Roberrt
      wrote on 19 Nov 2023, 06:40 last edited by Roberrt
      #2

      ~ bump ~

      1 Reply Last reply
      0
      • SGaistS SGaist moved this topic from General and Desktop on 19 Nov 2023, 19:51
      • R Offline
        R Offline
        Roberrt
        wrote on 25 Nov 2023, 09:32 last edited by
        #3

        ~ bump ~

        1 Reply Last reply
        0

        1/3

        14 Nov 2023, 08:14

        • Login

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