Overview
TheZeal::Browser::WebPage class is a customized Qt WebEnginePage that provides security controls for navigation requests and enhanced debugging through JavaScript console message logging. It handles the distinction between local documentation resources and external URLs, implementing configurable policies for external link access.
Header: src/libs/browser/webpage.h
Inherits: QWebEnginePage
Class Definition
Constructor
WebPage()
Browser::Settings.
Parameters:
parent- Parent QObject (optional)
- Uses
Settings::defaultProfile()for the QWebEngineProfile - Inherits profile settings like cache location, persistent storage, and HTTP user agent
Navigation Control
acceptNavigationRequest()
requestUrl- The URL being navigated totype- Type of navigation (link click, form submit, etc.)isMainFrame- Whether this is a main frame navigation
true if navigation is allowed, false otherwise
Navigation Rules:
-
Local URLs: Always allowed (detected via
Core::NetworkAccessManager::isLocalUrl())qrc://resources (bundled documentation files)file://URLs from local docsets
- External Resources on External Pages: Allowed once already on an external page
-
External Resources on Local Pages: Blocked if not in main frame
- Prevents external tracking scripts/images on documentation pages
- Logged with debug message
- External Main Frame Navigation: Controlled by user settings policy
External Link Policy: Ask
When set toAsk, displays a dialog with:
- URL being accessed
- Options: “Open in Desktop Browser”, “Open in Zeal”, “Cancel”
- “Do not ask again” checkbox to save preference
JavaScript Console Logging
javaScriptConsoleMessage()
level- Message severity (Info, Warning, Error)message- Console message textlineNumber- Line number where message originatedsourceId- Source file/script identifier
- Routes to
zeal.browser.webpagelogging category - Format:
[level] [sourceId:lineNumber] message - Useful for debugging documentation rendering issues
Qt WebEngine Integration
WebChannel Support
While WebPage itself doesn’t directly manage the WebChannel, it’s typically configured with a WebBridge instance throughsetWebChannel():
qt.webChannelTransport API.
Profile Configuration
The WebPage uses a shared profile that configures:- Cache Location: For offline documentation access
- Persistent Cookies: For documentation site preferences
- User Agent: Identifies Zeal to documentation servers
Usage Examples
Basic Usage
Handling Navigation Requests
The navigation logic automatically handles different scenarios:Monitoring JavaScript Console
Enable debug logging to see JavaScript console messages:Security Considerations
Protection Against External Resources
TheacceptNavigationRequest() implementation provides important security features:
- Prevents Tracking: Blocks external scripts and images on local documentation
- User Control: Configurable policy for external navigation
- Transparent Logging: Debug logs show all blocked requests
Implementation Details
From webpage.cpp:29:Implementation Files
- Header: src/libs/browser/webpage.h
- Implementation: src/libs/browser/webpage.cpp
See Also
- WebView - Widget that uses WebPage for rendering
- WebBridge - JavaScript to C++ communication bridge
- Qt WebEnginePage Documentation
- Core::NetworkAccessManager - URL validation utilities