Repository navigation
API Reference
This document provides a comprehensive API reference for the Secure Browser project, including all classes, methods, and their parameters.
- Main Entry Point
- PyQt5 Browser API
- Tkinter Browser API
- WebView Browser API
- Search Operators Tool API
- Developer Tools Integration API
- Module Exports
Location: main.py
Description: Main entry point for the Secure Browser application. Handles command-line argument parsing and browser selection.
Parameters: None
Returns: None
Raises: None
Example:
# Run from command line
python main.py --browser pyqt5
python main.py --browser tkinter
python main.py --browser webview
python main.py --browser searchCommand-Line Arguments:
-
--browser: Browser implementation to launch- Choices:
pyqt5,tkinter,webview,search - Default:
pyqt5
- Choices:
Location: src/browsers/hope.py
Description: Main browser window class with tabbed interface, dark theme, and advanced UI features.
Description: Initialize the browser window with default settings.
Parameters: None
Returns: Browser instance
Example:
from src.browsers.hope import Browser
browser = Browser()
browser.show()Description: Creates the navigation bar with buttons and URL input.
Parameters: None
Returns: QHBoxLayout - Navigation bar layout
Example:
nav_layout = browser.create_navigation_bar()Description: Opens a new tab with the given URL, or default URL if none provided.
Parameters:
-
url(str, optional): URL to load. Defaults to "https://search.brave.com/"
Returns: None
Example:
browser.open_new_tab("https://example.com")
browser.open_new_tab() # Opens default URLDescription: Closes the tab at the given index.
Parameters:
-
index(int): Index of the tab to close
Returns: None
Example:
browser.close_tab(0)Description: Loads a URL typed into the URL bar. Automatically adds https:// prefix if missing.
Parameters: None (reads from URL bar)
Returns: None
Example:
browser.url_bar.setText("example.com")
browser.load_url() # Loads https://example.comDescription: Updates the URL bar when the tab's URL changes.
Parameters:
-
url(QUrl): New URL to display
Returns: None
Example:
browser.update_tab_url(QUrl("https://example.com"))Description: Updates the tab's title based on the webpage title.
Parameters:
-
title(str): New title for the tab
Returns: None
Example:
browser.update_tab_title("Example Page")Description: Navigates back to the previous page in the current tab.
Parameters: None
Returns: None
Example:
browser.go_back()Description: Navigates forward to the next page in the current tab.
Parameters: None
Returns: None
Example:
browser.go_forward()Description: Reloads the current tab's page.
Parameters: None
Returns: None
Example:
browser.reload_page()Description: Navigates to the home page (https://search.brave.com/).
Parameters: None
Returns: None
Example:
browser.go_home()Description: Opens the settings dialog for adjusting configurations.
Parameters: None
Returns: None
Example:
browser.open_settings_panel()Location: src/browsers/hope.py
Description: Settings dialog for configuring browser options.
Description: Initialize the settings dialog.
Parameters:
-
parent(QWidget, optional): Parent widget. Defaults to None.
Returns: SettingsDialog instance
Example:
from src.browsers.hope import SettingsDialog
dialog = SettingsDialog(browser)
dialog.exec_()Attributes:
-
vpn_checkbox(QCheckBox): VPN toggle -
javascript_checkbox(QCheckBox): JavaScript enable/disable -
proxy_input(QLineEdit): Proxy configuration
Location: src/browsers/hope.py
Description: Main function to launch the PyQt5 browser.
Parameters: None
Returns: None
Example:
from src.browsers.hope import main
main()Location: src/browsers/secure_browser.py
Description: Lightweight secure browser with security features, whitelist/blacklist filtering, and bookmark management.
Description: Initialize the browser with Tkinter root window.
Parameters:
-
root(tk.Tk): Tkinter root window
Returns: SimpleBrowser instance
Example:
import tkinter as tk
from src.browsers.secure_browser import SimpleBrowser
root = tk.Tk()
browser = SimpleBrowser(root)
root.mainloop()Attributes:
-
history(list): Navigation history -
current_index(int): Current position in history -
bookmarks(list): Saved bookmarks -
security_headers(dict): Security header configurations -
whitelist(list): Allowed websites -
blacklist(list): Blocked websites
Description: Loads a URL from the address bar. Enforces HTTPS and applies security filters.
Parameters:
-
event(tk.Event, optional): Event object. Defaults to None.
Returns: None
Example:
browser.url_entry.delete(0, tk.END)
browser.url_entry.insert(0, "example.com")
browser.load_url()Description: Adds the current URL to bookmarks.
Parameters: None
Returns: None
Example:
browser.add_bookmark()Description: Performs a web search using the current URL bar content.
Parameters: None
Returns: None
Example:
browser.url_entry.delete(0, tk.END)
browser.url_entry.insert(0, "Python tutorial")
browser.search_web()Description: Applies security headers to the content (placeholder function).
Parameters:
-
content(str): Content to process
Returns: str - Processed content
Example:
secured_content = browser.apply_security_headers(raw_content)Description: Reloads the current page from history.
Parameters: None
Returns: None
Example:
browser.reload_page()Description: Navigates back in history.
Parameters: None
Returns: None
Example:
browser.go_back()Description: Navigates forward in history.
Parameters: None
Returns: None
Example:
browser.go_forward()Description: Navigates to the home page.
Parameters: None
Returns: None
Example:
browser.go_home()Description: Opens the settings window with all configuration options.
Parameters: None
Returns: None
Example:
browser.open_settings()Description: Sets the User-Agent string for requests.
Parameters: None (reads from user_agent_var)
Returns: None
Example:
browser.user_agent_var.set("Mozilla/5.0 (Custom)")
browser.set_user_agent()Description: Configures HTTP and HTTPS proxy settings.
Parameters: None (reads from proxy input fields)
Returns: None
Example:
browser.http_proxy_var.set("http://proxy.example.com:8080")
browser.https_proxy_var.set("https://proxy.example.com:8080")
browser.set_proxy()Description: Enables or disables JavaScript execution.
Parameters: None (reads from javascript_var)
Returns: None
Example:
browser.javascript_var.set(True)
browser.toggle_javascript()Description: Saves whitelist and blacklist settings.
Parameters: None (reads from whitelist_var and blacklist_var)
Returns: None
Example:
browser.whitelist_var.set("example.com, trusted.org")
browser.blacklist_var.set("malicious.com")
browser.set_security_settings()Description: Enables/disables navigation buttons based on history state.
Parameters: None
Returns: None
Example:
browser.update_navigation_controls()Location: src/browsers/modern_browser.py
Description: Modern browser using native webview integration with cross-platform support.
Description: Initialize the browser with Tkinter root window and webview.
Parameters:
-
root(tk.Tk): Tkinter root window
Returns: SimpleBrowser instance
Example:
import tkinter as tk
from src.browsers.modern_browser import SimpleBrowser
root = tk.Tk()
browser = SimpleBrowser(root)
root.mainloop()Attributes:
-
history(list): Navigation history -
current_index(int): Current position in history -
webview_window: Native webview window instance
Description: Initializes the webview window with the given URL.
Parameters:
-
url(str): Initial URL to load
Returns: None
Example:
browser.initialize_webview("https://example.com")Description: Loads a URL into the webview.
Parameters:
-
url(str): URL to load
Returns: None
Example:
browser.load_into_webview("https://example.com")Description: Loads a URL from the address bar.
Parameters:
-
event(tk.Event, optional): Event object. Defaults to None.
Returns: None
Example:
browser.url_entry.delete(0, tk.END)
browser.url_entry.insert(0, "example.com")
browser.load_url()Description: Reloads the current page.
Parameters: None
Returns: None
Example:
browser.reload_page()Description: Navigates back in history.
Parameters: None
Returns: None
Example:
browser.go_back()Description: Navigates forward in history.
Parameters: None
Returns: None
Example:
browser.go_forward()Description: Navigates to the home page.
Parameters: None
Returns: None
Example:
browser.go_home()Description: Loads the URL at the current history index.
Parameters: None
Returns: None
Example:
browser.load_url_from_history()Description: Opens the settings window.
Parameters: None
Returns: None
Example:
browser.open_settings()Description: Attempts to set custom user-agent (not supported in current PyWebView version).
Parameters: None
Returns: None
Example:
browser.set_user_agent() # Prints limitation messageDescription: Configures proxy settings via environment variables.
Parameters: None (reads from proxy input fields)
Returns: None
Example:
browser.http_proxy_var.set("http://proxy.example.com:8080")
browser.set_proxy()Description: Updates navigation button states based on history.
Parameters: None
Returns: None
Example:
browser.update_navigation_controls()Location: src/browsers/modern_browser.py
Description: Main function to launch the WebView browser.
Parameters: None
Returns: None
Example:
from src.browsers.modern_browser import main
main()Location: src/tools/search.py
Description: Advanced search query builder with support for various search operators.
Description: Initialize the search operators tool with dark theme.
Parameters: None
Returns: SearchOperatorsTool instance
Example:
from src.tools.search import SearchOperatorsTool
tool = SearchOperatorsTool()
tool.show()Attributes:
-
query_input(QLineEdit): Base search query input -
site_checkbox(QCheckBox): Site filtering toggle -
site_input(QLineEdit): Site domain input -
title_checkbox(QCheckBox): Title filtering toggle -
title_input(QLineEdit): Title text input -
filetype_checkbox(QCheckBox): Filetype filtering toggle -
filetype_input(QLineEdit): Filetype input -
exclude_checkbox(QCheckBox): Exclusion toggle -
exclude_input(QLineEdit): Words to exclude -
custom_checkbox(QCheckBox): Custom operator toggle -
custom_input(QLineEdit): Custom operator input -
preview_output(QTextEdit): Query preview display
Description: Applies a dark theme with advanced colorization to the application.
Parameters: None
Returns: None
Example:
tool.apply_dark_theme()Description: Adds the search query input section to the UI.
Parameters: None
Returns: None
Example:
tool.add_search_query_section()Description: Adds the search operator options section to the UI.
Parameters: None
Returns: None
Example:
tool.add_operator_options()Description: Adds the query preview and action buttons to the UI.
Parameters: None
Returns: None
Example:
tool.add_preview_and_actions()Description: Generates the search query based on user inputs and selected operators.
Parameters: None
Returns: None (updates preview_output)
Example:
tool.query_input.setText("Python tutorial")
tool.site_checkbox.setChecked(True)
tool.site_input.setText("docs.python.org")
tool.generate_query()
# Result: "Python tutorial site:docs.python.org"Supported Operators:
-
site:- Restrict search to specific domain -
intitle:- Search for words in page title -
filetype:- Search for specific file types -
-- Exclude words from search - Custom operators
Description: Executes the generated search query using the default web browser.
Parameters: None
Returns: None
Example:
tool.generate_query()
tool.execute_search() # Opens search in default browserLocation: src/tools/search.py
Description: Main function to launch the search operators tool.
Parameters: None
Returns: None
Example:
from src.tools.search import main
main()Location: src/tools/dev_tools_integration.py
Description: Web browser with integrated developer tools dock.
Note: This class is designed to be used as a mixin or base class for other browser implementations.
Description: Initialize the browser with developer tools integration.
Parameters:
-
*args: Variable positional arguments -
**kwargs: Variable keyword arguments
Returns: Browser instance
Example:
from src.tools.dev_tools_integration import Browser
from PyQt5.QtWidgets import QMainWindow
class MyBrowser(Browser, QMainWindow):
def __init__(self):
super().__init__()
# Additional initializationAttributes:
-
dev_tools_dock(QDockWidget): Dock widget for developer tools -
dev_tools_area(QWebEngineView): WebEngineView displaying developer tools -
current_tab_page(QWebEnginePage): Current webpage linked with dev tools
Description: Shows the Developer Tools Dock.
Parameters: None
Returns: None
Example:
browser.show_dev_tools()Description: Modifies the navigation bar to add a Developer Tools button.
Parameters: None
Returns: None
Note: This method should be called after the navigation bar is created by the parent class.
Example:
browser.create_navigation_bar()Exports:
-
Browserfromsrc.browsers.hope -
SecureBrowserfromsrc.browsers.secure_browser -
ModernBrowserfromsrc.browsers.modern_browser
Example:
from src import Browser, SecureBrowser, ModernBrowserExports:
-
Browserfromhope.py -
SecureBrowserfromsecure_browser.py -
ModernBrowserfrommodern_browser.py
Example:
from src.browsers import Browser, SecureBrowser, ModernBrowserExports:
-
SearchOperatorsToolfromsearch.py
Example:
from src.tools import SearchOperatorsToolDescription: URL string or QUrl object
Valid Formats:
-
str: "https://example.com" -
QUrl: PyQt5 URL object
Description: List of URLs representing navigation history
Format:
history = [
"https://example.com/page1",
"https://example.com/page2",
"https://example.com/page3"
]Description: Dictionary containing browser settings
Format:
settings = {
"vpn": bool,
"javascript": bool,
"proxy": str,
"user_agent": str,
"whitelist": list,
"blacklist": list
}Description: Invalid URL format
Handling: Browser displays "Invalid URL" in URL bar
Example:
# In PyQt5 browser
if not QUrl(url).isValid():
self.url_bar.setText("Invalid URL")Description: Error loading webpage
Handling: Browser displays error message in HTML frame
Example:
# In Tkinter browser
except Exception as e:
error_message = f"<h1>Error loading {url}</h1><p>{str(e)}</p>"
self.html_frame.set_html(error_message)Description: Error initializing webview
Handling: Prints error message to console
Example:
# In WebView browser
except Exception as e:
print(f"Error initializing WebView: {e}")- Home URL: "https://search.brave.com/"
- Search URL: "https://search.brave.com/search?q="
SECURITY_HEADERS = {
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "DENY",
"Content-Security-Policy": "default-src 'self'; script-src 'self'; object-src 'none';"
}- PyQt5 Browser Window: 1280x720
- PyQt5 Settings Dialog: 400x300
- Search Tool Window: 800x600
- WebView Browser Window: 900x650
- Tkinter Settings Window: 400x600
-
urlChanged.connect(callback): Fired when URL changes -
titleChanged.connect(callback): Fired when page title changes -
tabCloseRequested.connect(callback): Fired when tab close is requested
-
<Return>: URL bar enter key press -
<Double-Button-1>: Bookmark double-click
{
"home_url": "https://search.brave.com/",
"proxy": {
"http": "",
"https": ""
},
"javascript_enabled": true,
"vpn_enabled": false,
"user_agent": "default",
"whitelist": [],
"blacklist": [],
"bookmarks": []
}