Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-140543

Hang/SIGTRAP with acceptNavigationRequest and QWebEngineUrlSchemeHandler

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P2: Important P2: Important
    • None
    • 6.10.0 RC
    • WebEngine
    • None
    • Archlinux, gcc 15.2.1

      Consider this example, which defines a custom QWebEngineUrlScheme::LocalScheme scheme but then uses QWebEnginePage::acceptNavigationRequest to allow certain navigations based on custom logic:

      #include <QApplication>
      #include <QWebEngineView>
      #include <QWebEngineProfile>
      #include <QWebEnginePage>
      #include <QWebEngineUrlScheme>
      #include <QWebEngineUrlSchemeHandler>
      #include <QWebEngineUrlRequestJob>
      #include <QBuffer>
      #include <QByteArray>
      #include <QUrl>
      
      class SchemeHandler : public QWebEngineUrlSchemeHandler {
      public:
          using QWebEngineUrlSchemeHandler::QWebEngineUrlSchemeHandler;
      
          void requestStarted(QWebEngineUrlRequestJob *job) override {
              auto buffer = new QBuffer(job);
              buffer->setData("<html><body><a href=\"https://qt.io\">Qt</a></body></html>");
              job->reply("text/html", buffer);
          }
      };
      
      class Page : public QWebEnginePage {
      public:
          using QWebEnginePage::QWebEnginePage;
      
      protected:
          bool acceptNavigationRequest(const QUrl &requestedUrl, NavigationType type, bool isMainFrame) override {
              // explicitly allow external navigation; real code does more validation here
              if (url().scheme() == "myscheme" && requestedUrl.scheme() == "https") {
                  load(requestedUrl);
                  return false;
              }
              return true;
          }
      };
      
      int main(int argc, char *argv[]) {
          QApplication app(argc, argv);
      
          QWebEngineUrlScheme scheme("myscheme");
          scheme.setFlags(QWebEngineUrlScheme::LocalScheme);
          QWebEngineUrlScheme::registerScheme(scheme);
      
          auto handler = new SchemeHandler(&app);
          auto profile = QWebEngineProfile::defaultProfile();
          profile->installUrlSchemeHandler("myscheme", handler);
      
          auto view = new QWebEngineView;
          auto page = new Page(profile, view);
          view->setPage(page);
      
          view->load(QUrl("myscheme://test"));
          view->show();
      
          return app.exec();
      }
      
      QT += widgets webenginewidgets
      SOURCES += scheme.cpp
      TARGET = scheme
      

      Click the link once the view opens. With Qt <= 6.9, it works mostly fine (though sometimes seems to hang the renderer process, if it doesn't, try right-clicking and going back and then forward again).

      With Qt 6.10, a release build fails with SIGTRAP, while a debug build shows [454984:454984:0925/150603.628568:FATAL:intercept_navigation_throttle.cc(91)] Check failed: weak_this.

      Stacktrace:

      #0 0x7f33ba9ae0f1 base::debug::CollectStackTrace() [./../../../3rdparty/chromium/base/debug/stack_trace_posix.cc:1057:38]
      #1 0x7f33ba9709e0 base::debug::StackTrace::StackTrace() [./../../../3rdparty/chromium/base/debug/stack_trace.cc:254:37]
      #2 0x7f33ba970947 base::debug::StackTrace::StackTrace() [./../../../3rdparty/chromium/base/debug/stack_trace.cc:249:56]
      #3 0x7f33ba6e4872 logging::LogMessage::Flush() [../../../3rdparty/chromium/base/logging.cc:737:29]
      #4 0x7f33ba6e4744 logging::LogMessage::~LogMessage() [../../../3rdparty/chromium/base/logging.cc:725:8]
      #5 0x7f33ba6f2469 logging::(anonymous namespace)::CheckLogMessage::~CheckLogMessage() [./../../../3rdparty/chromium/base/check.cc:198:3]
      #6 0x7f33ba6f248e logging::(anonymous namespace)::CheckLogMessage::~CheckLogMessage() [./../../../3rdparty/chromium/base/check.cc:198:3]
      #7 0x7f33ba6f79c0 std::default_delete<>::operator()() [/usr/include/c++/15.2.1/bits/unique_ptr.h:93:2]
      #8 0x7f33ba6f7a20 std::__uniq_ptr_impl<>::reset() [/usr/include/c++/15.2.1/bits/unique_ptr.h:205:16]
      #9 0x7f33ba6f6f8c std::unique_ptr<>::reset() [/usr/include/c++/15.2.1/bits/unique_ptr.h:512:12]
      #10 0x7f33ba6f2b37 logging::CheckNoreturnError::~CheckNoreturnError() [./../../../3rdparty/chromium/base/check.cc:350:21]
      #11 0x7f33bac46cfe navigation_interception::InterceptNavigationThrottle::CheckIfShouldIgnoreNavigation() [../../../3rdparty/chromium/components/navigation_interception/intercept_navigation_throttle.cc:91:3]
      #12 0x7f33bac46a52 navigation_interception::InterceptNavigationThrottle::WillStartRequest() [../../../3rdparty/chromium/components/navigation_interception/intercept_navigation_throttle.cc:41:40]
      #13 0x7f33b666a998 content::(anonymous namespace)::ExecuteNavigationEvent() [../../../3rdparty/chromium/content/browser/renderer_host/navigation_throttle_runner.cc:48:41]
      #14 0x7f33b666d071 content::NavigationThrottleRunner::ProcessInternal() [../../../3rdparty/chromium/content/browser/renderer_host/navigation_throttle_runner.cc:360:67]
      #15 0x7f33b666b0db content::NavigationThrottleRunner::ProcessNavigationEvent() [../../../3rdparty/chromium/content/browser/renderer_host/navigation_throttle_runner.cc:143:18]
      #16 0x7f33b6612555 content::NavigationRequest::WillStartRequest() [../../../3rdparty/chromium/content/browser/renderer_host/navigation_request.cc:7748:43]
      #17 0x7f33b65f8ea6 content::NavigationRequest::BeginNavigationImpl() [../../../3rdparty/chromium/content/browser/renderer_host/navigation_request.cc:2872:19]
      #18 0x7f33b65f6df8 content::NavigationRequest::BeginNavigation() [../../../3rdparty/chromium/content/browser/renderer_host/navigation_request.cc:2452:22]
      #19 0x7f33b668a72d content::Navigator::OnBeginNavigation() [../../../3rdparty/chromium/content/browser/renderer_host/navigator.cc:1292:38]
      #20 0x7f33b66e1517 content::RenderFrameHostImpl::BeginNavigation() [../../../3rdparty/chromium/content/browser/renderer_host/render_frame_host_impl.cc:10968:50]
      #21 0x7f33b4f471bb content::mojom::FrameHostStubDispatch::Accept() [gen/content/common/frame.mojom.cc:5511:28]
      #22 0x7f33b678a6e9 content::mojom::FrameHostStub<>::Accept() [gen/content/common/frame.mojom.h:851:41]
      #23 0x7f33bc04cf9a mojo::InterfaceEndpointClient::HandleValidatedMessage() [../../../3rdparty/chromium/mojo/public/cpp/bindings/lib/interface_endpoint_client.cc:1052:60]
      #24 0x7f33bc048683 mojo::InterfaceEndpointClient::HandleIncomingMessageThunk::Accept() [../../../3rdparty/chromium/mojo/public/cpp/bindings/lib/interface_endpoint_client.cc:371:40]
      #25 0x7f33bc05f514 mojo::MessageDispatcher::Accept() [../../../3rdparty/chromium/mojo/public/cpp/bindings/lib/message_dispatcher.cc:48:30]
      #26 0x7f33bc04aba2 mojo::InterfaceEndpointClient::HandleIncomingMessage() [../../../3rdparty/chromium/mojo/public/cpp/bindings/lib/interface_endpoint_client.cc:724:26]
      #27 0x7f33bc71204c IPC::ChannelAssociatedGroupController::AcceptOnEndpointThread() [../../../3rdparty/chromium/ipc/ipc_mojo_bootstrap.cc:1202:45]
      #28 0x7f33bc71d609 base::internal::DecayedFunctorTraits<>::Invoke<>() [../../../3rdparty/chromium/base/functional/bind_internal.h:729:37]
      #29 0x7f33bc71b258 base::internal::InvokeHelper<>::MakeItSo<>() [../../../3rdparty/chromium/base/functional/bind_internal.h:921:26]
      #30 0x7f33bc717648 base::internal::Invoker<>::RunImpl<>() [../../../3rdparty/chromium/base/functional/bind_internal.h:1058:72]
      #31 0x7f33bc714566 base::internal::Invoker<>::RunOnce() [../../../3rdparty/chromium/base/functional/bind_internal.h:971:19]
      #32 0x7f33acb41ddd base::OnceCallback<>::Run() [../../../3rdparty/chromium/base/functional/callback.h:156:13]
      #33 0x7f33ba83f438 base::TaskAnnotator::RunTaskImpl() [./../../../3rdparty/chromium/base/task/common/task_annotator.cc:209:37]
      #34 0x7f33ba8914e4 base::TaskAnnotator::RunTask<>() [../../../3rdparty/chromium/base/task/common/task_annotator.h:106:16]
      #35 0x7f33ba8885bd base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWorkImpl() [./../../../3rdparty/chromium/base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:456:30]
      #36 0x7f33ba8875df base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::DoWork() [./../../../3rdparty/chromium/base/task/sequence_manager/thread_controller_with_message_pump_impl.cc:330:50]
      #37 0x7f33aca00e18 QtWebEngineCore::MessagePumpForUIQt::handleScheduledWork() [/home/florian/proj/qt/dev6/qt5/qtwebengine/src/core/browser_main_parts_qt.cpp:155:48]
      #38 0x7f33aca00a0f QtWebEngineCore::MessagePumpForUIQt::MessagePumpForUIQt()::{lambda()#1}::operator()() [/home/florian/proj/qt/dev6/qt5/qtwebengine/src/core/browser_main_parts_qt.cpp:106:53]
      #39 0x7f33aca05160 std::__invoke_impl<>() [/usr/include/c++/15.2.1/bits/invoke.h:63:36]
      #40 0x7f33aca043a8 std::__invoke_r<>() [/usr/include/c++/15.2.1/bits/invoke.h:113:28]
      #41 0x7f33aca02c6d std::_Function_handler<>::_M_invoke() [/usr/include/c++/15.2.1/bits/std_function.h:292:30]
      #42 0x7f33aca34ca0 std::function<>::operator()() [/usr/include/c++/15.2.1/bits/std_function.h:593:9]
      #43 0x7f33ba6a5724 QWebEngineMessagePumpScheduler::timerEvent()
      #44 0x7f33a769fa06 QObject::event()
      #45 0x7f33d31bdf94 QApplicationPrivate::notify_helper()
      #46 0x7f33d31bdd5c QApplication::notify()
      #47 0x7f33a75fefbb QCoreApplication::notifyInternal2()
      #48 0x7f33a75ffbc3 QCoreApplication::sendEvent()
      #49 0x7f33a7600d1b QCoreApplicationPrivate::sendPostedEvents()
      #50 0x7f33a76004df QCoreApplication::sendPostedEvents()
      #51 0x7f33a7affcaf postEventSourceDispatch()
      #52 0x7f33a5c9d880 (/usr/lib/libglib-2.0.so.0.8400.4+0x5e87f)
      #53 0x7f33a5c9ecd7 (/usr/lib/libglib-2.0.so.0.8400.4+0x5fcd6)
      #54 0x7f33a5c9eee5 g_main_context_iteration
      #55 0x7f33a7b006ba QEventDispatcherGlib::processEvents()
      #56 0x7f33a2b05f90 QXcbGlibEventDispatcher::processEvents()
      #57 0x7f33a761659e QEventLoop::processEvents()
      #58 0x7f33a7616995 QEventLoop::exec()
      #59 0x7f33a75ff961 QCoreApplication::exec()
      #60 0x7f33a984327c QGuiApplication::exec()
      #61 0x7f33d31bab27 QApplication::exec()
      #62 0x55ecd240b587 main
      #63 0x7f33a6c27675 (/usr/lib/libc.so.6+0x27674)
      #64 0x7f33a6c27729 __libc_start_main
      #65 0x55ecd240b285 _start
      

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            qt_webengine_team Qt WebEngine Team
            the compiler Florian Bruhin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes