CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pyobjc-framework-webkit

Python bindings for Apple's WebKit and JavaScriptCore frameworks on macOS, enabling web browser functionality and JavaScript execution in Python applications

Pending
Overview
Eval results
Files

modern-webkit.mddocs/

Modern WebKit Components

Modern WKWebView-based web browsing components introduced in macOS 10.10, providing improved security, performance, and feature set compared to legacy WebView. The WK-prefixed classes represent Apple's current WebKit implementation with process isolation, enhanced security policies, and better integration with modern web standards.

Capabilities

Core Web View

WKWebView

The primary web view component for displaying web content with modern security and performance characteristics.

class WKWebView:
    def initWithFrame_configuration_(self, frame: CGRect, configuration: WKWebViewConfiguration) -> WKWebView: ...
    def loadRequest_(self, request: NSURLRequest) -> WKNavigation: ...
    def loadHTMLString_baseURL_(self, string: str, baseURL: NSURL) -> WKNavigation: ...
    def loadFileURL_allowingReadAccessToURL_(self, URL: NSURL, readAccessURL: NSURL) -> WKNavigation: ...
    def loadData_MIMEType_characterEncodingName_baseURL_(self, data: NSData, MIMEType: str, characterEncodingName: str, baseURL: NSURL) -> WKNavigation: ...
    
    # Navigation
    def goBack(self) -> WKNavigation: ...
    def goForward(self) -> WKNavigation: ...
    def goToBackForwardListItem_(self, item: WKBackForwardListItem) -> WKNavigation: ...
    def reload(self) -> WKNavigation: ...
    def reloadFromOrigin(self) -> WKNavigation: ...
    def stopLoading(self): ...
    
    # JavaScript execution
    def evaluateJavaScript_completionHandler_(self, javaScriptString: str, completionHandler: callable): ...
    def callAsyncJavaScript_arguments_inFrame_inContentWorld_completionHandler_(self, functionBody: str, arguments: dict, frame: WKFrameInfo, contentWorld: WKContentWorld, completionHandler: callable): ...
    
    # Properties
    @property
    def configuration(self) -> WKWebViewConfiguration: ...
    @property
    def navigationDelegate(self) -> WKNavigationDelegate: ...
    @property
    def UIDelegate(self) -> WKUIDelegate: ...
    @property
    def backForwardList(self) -> WKBackForwardList: ...
    @property
    def title(self) -> str: ...
    @property
    def URL(self) -> NSURL: ...
    @property
    def isLoading(self) -> bool: ...
    @property
    def estimatedProgress(self) -> float: ...
    @property
    def hasOnlySecureContent(self) -> bool: ...
    @property
    def certificateChain(self) -> list: ...
    @property
    def canGoBack(self) -> bool: ...
    @property
    def canGoForward(self) -> bool: ...
    @property
    def allowsBackForwardNavigationGestures(self) -> bool: ...
    @property
    def customUserAgent(self) -> str: ...
    @property
    def allowsMagnification(self) -> bool: ...
    @property
    def magnification(self) -> float: ...
    
    # Find in page
    def findString_withConfiguration_completionHandler_(self, string: str, configuration: WKFindConfiguration, completionHandler: callable): ...
    
    # PDF and Snapshots
    def createPDFWithConfiguration_completionHandler_(self, configuration: WKPDFConfiguration, completionHandler: callable): ...
    def takeSnapshotWithConfiguration_completionHandler_(self, configuration: WKSnapshotConfiguration, completionHandler: callable): ...
    
    # Media Control
    def pauseAllMediaPlayback_(self, completionHandler: callable): ...
    def suspendAllMediaPlayback_(self, completionHandler: callable): ...
    def resumeAllMediaPlayback_(self, completionHandler: callable): ...
    def requestMediaPlaybackState_(self, completionHandler: callable): ...
    def setMicrophoneCaptureState_completionHandler_(self, state: WKMediaCaptureState, completionHandler: callable): ...
    def setCameraCaptureState_completionHandler_(self, state: WKMediaCaptureState, completionHandler: callable): ...
    
    # Security
    @property
    def serverTrust(self) -> SecTrust: ...
    
    # Media
    @property
    def mediaType(self) -> str: ...
    @property
    def pageZoom(self) -> float: ...
    @property
    def microphoneCaptureState(self) -> WKMediaCaptureState: ...
    @property
    def cameraCaptureState(self) -> WKMediaCaptureState: ...

Configuration

WKWebViewConfiguration

Configuration object that defines the behavior and capabilities of a WKWebView instance.

class WKWebViewConfiguration:
    def init(self) -> WKWebViewConfiguration: ...
    
    # Content controllers
    @property
    def userContentController(self) -> WKUserContentController: ...
    
    # Preferences
    @property
    def preferences(self) -> WKPreferences: ...
    @property
    def defaultWebpagePreferences(self) -> WKWebpagePreferences: ...
    
    # Data storage
    @property
    def websiteDataStore(self) -> WKWebsiteDataStore: ...
    
    # Process pool
    @property
    def processPool(self) -> WKProcessPool: ...
    
    # Media configuration
    @property
    def mediaTypesRequiringUserAction(self) -> WKAudiovisualMediaTypes: ...
    @property
    def allowsInlineMediaPlayback(self) -> bool: ...
    @property
    def allowsAirPlayForMediaPlayback(self) -> bool: ...
    @property
    def allowsPictureInPictureMediaPlayback(self) -> bool: ...
    
    # JavaScript configuration
    @property
    def suppressesIncrementalRendering(self) -> bool: ...
    @property
    def applicationNameForUserAgent(self) -> str: ...
    
    # Selection
    @property
    def selectionGranularity(self) -> WKSelectionGranularity: ...
    
    # Data detection
    @property
    def dataDetectorTypes(self) -> WKDataDetectorTypes: ...
    
    # URL scheme handlers
    def setURLSchemeHandler_forURLScheme_(self, urlSchemeHandler: WKURLSchemeHandler, urlScheme: str): ...
    def urlSchemeHandlerForURLScheme_(self, urlScheme: str) -> WKURLSchemeHandler: ...

WKPreferences

Preferences object for configuring web view behavior.

class WKPreferences:
    def init(self) -> WKPreferences: ...
    
    @property
    def minimumFontSize(self) -> float: ...
    @property
    def javaScriptEnabled(self) -> bool: ...
    @property
    def javaScriptCanOpenWindowsAutomatically(self) -> bool: ...
    @property
    def isFraudulentWebsiteWarningEnabled(self) -> bool: ...
    @property
    def tabFocusesLinks(self) -> bool: ...
    @property
    def textInteractionEnabled(self) -> bool: ...

WKWebpagePreferences

Per-navigation preferences for web content.

class WKWebpagePreferences:
    def init(self) -> WKWebpagePreferences: ...
    
    @property
    def allowsContentJavaScript(self) -> bool: ...
    @property
    def preferredContentMode(self) -> WKContentMode: ...

Process Management

WKProcessPool

Shared process pool for web content processes.

class WKProcessPool:
    def init(self) -> WKProcessPool: ...

Security and Privacy

WKSecurityOrigin

Represents the security origin of web content.

class WKSecurityOrigin:
    @property
    def protocol(self) -> str: ...
    @property
    def host(self) -> str: ...
    @property
    def port(self) -> int: ...

WKFrameInfo

Information about a web page frame.

class WKFrameInfo:
    @property
    def isMainFrame(self) -> bool: ...
    @property
    def request(self) -> NSURLRequest: ...
    @property
    def securityOrigin(self) -> WKSecurityOrigin: ...
    @property
    def webView(self) -> WKWebView: ...

Window Management

WKWindowFeatures

Window features for popup windows.

class WKWindowFeatures:
    @property
    def menuBarVisibility(self) -> bool: ...
    @property
    def statusBarVisibility(self) -> bool: ...
    @property
    def toolbarsVisibility(self) -> bool: ...
    @property
    def allowsResizing(self) -> bool: ...
    @property
    def x(self) -> int: ...
    @property
    def y(self) -> int: ...
    @property
    def width(self) -> int: ...
    @property
    def height(self) -> int: ...

Content Worlds

WKContentWorld

Isolated JavaScript execution environment.

class WKContentWorld:
    @classmethod 
    def pageWorld(cls) -> WKContentWorld: ...
    @classmethod
    def defaultClientWorld(cls) -> WKContentWorld: ...
    @classmethod
    def worldWithName_(cls, name: str) -> WKContentWorld: ...
    
    @property
    def name(self) -> str: ...

Downloads

WKDownload

Represents a download operation initiated from a web view.

class WKDownload:
    @property
    def originalRequest(self) -> NSURLRequest: ...
    @property
    def delegate(self) -> WKDownloadDelegate: ...
    @property
    def progress(self) -> NSProgress: ...
    
    def cancel_(self, completionHandler: callable): ...

Find in Page

WKFindConfiguration

Configuration for text search operations.

class WKFindConfiguration:
    def init(self) -> WKFindConfiguration: ...
    
    @property
    def backwards(self) -> bool: ...
    @property
    def caseSensitive(self) -> bool: ...
    @property
    def wraps(self) -> bool: ...

WKFindResult

Result of a text search operation.

class WKFindResult:
    @property
    def matchFound(self) -> bool: ...

PDF and Snapshot Generation

WKPDFConfiguration

Configuration for PDF generation.

class WKPDFConfiguration:
    def init(self) -> WKPDFConfiguration: ...
    
    @property
    def rect(self) -> CGRect: ...

WKSnapshotConfiguration

Configuration for taking screenshots of web content.

class WKSnapshotConfiguration:
    def init(self) -> WKSnapshotConfiguration: ...
    
    @property
    def rect(self) -> CGRect: ...
    @property
    def snapshotWidth(self) -> float: ...
    @property
    def afterScreenUpdates(self) -> bool: ...

Permissions and Context

WKContextMenuElementInfo

Information about an element in a context menu.

class WKContextMenuElementInfo:
    @property
    def linkURL(self) -> NSURL: ...

WKOpenPanelParameters

Parameters for file selection panels.

class WKOpenPanelParameters:
    @property
    def allowsMultipleSelection(self) -> bool: ...
    @property
    def allowsDirectories(self) -> bool: ...

Delegate Protocols

While these are protocol definitions in Objective-C, they represent the methods you need to implement in your delegate classes:

WKNavigationDelegate

# Navigation delegate methods (implement in your delegate class)
def webView_decidePolicyForNavigationAction_decisionHandler_(self, webView: WKWebView, navigationAction: WKNavigationAction, decisionHandler: callable): ...
def webView_decidePolicyForNavigationResponse_decisionHandler_(self, webView: WKWebView, navigationResponse: WKNavigationResponse, decisionHandler: callable): ...
def webView_didStartProvisionalNavigation_(self, webView: WKWebView, navigation: WKNavigation): ...
def webView_didReceiveServerRedirectForProvisionalNavigation_(self, webView: WKWebView, navigation: WKNavigation): ...
def webView_didFailProvisionalNavigation_withError_(self, webView: WKWebView, navigation: WKNavigation, error: NSError): ...
def webView_didCommitNavigation_(self, webView: WKWebView, navigation: WKNavigation): ...
def webView_didFinishNavigation_(self, webView: WKWebView, navigation: WKNavigation): ...
def webView_didFailNavigation_withError_(self, webView: WKWebView, navigation: WKNavigation, error: NSError): ...
def webView_didReceiveAuthenticationChallenge_completionHandler_(self, webView: WKWebView, challenge: NSURLAuthenticationChallenge, completionHandler: callable): ...
def webViewWebContentProcessDidTerminate_(self, webView: WKWebView): ...

WKUIDelegate

# UI delegate methods (implement in your delegate class)
def webView_createWebViewWithConfiguration_forNavigationAction_windowFeatures_(self, webView: WKWebView, configuration: WKWebViewConfiguration, navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView: ...
def webViewDidClose_(self, webView: WKWebView): ...
def webView_runJavaScriptAlertPanelWithMessage_initiatedByFrame_completionHandler_(self, webView: WKWebView, message: str, frame: WKFrameInfo, completionHandler: callable): ...
def webView_runJavaScriptConfirmPanelWithMessage_initiatedByFrame_completionHandler_(self, webView: WKWebView, message: str, frame: WKFrameInfo, completionHandler: callable): ...
def webView_runJavaScriptTextInputPanelWithPrompt_defaultText_initiatedByFrame_completionHandler_(self, webView: WKWebView, prompt: str, defaultText: str, frame: WKFrameInfo, completionHandler: callable): ...
def webView_contextMenuConfigurationForElement_completionHandler_(self, webView: WKWebView, elementInfo: WKContextMenuElementInfo, completionHandler: callable): ...
def webView_contextMenuWillPresentForElement_(self, webView: WKWebView, elementInfo: WKContextMenuElementInfo): ...
def webView_contextMenuForElement_willCommitWithAnimator_(self, webView: WKWebView, elementInfo: WKContextMenuElementInfo, animator: callable): ...
def webView_contextMenuDidEndForElement_(self, webView: WKWebView, elementInfo: WKContextMenuElementInfo): ...

WKDownloadDelegate

# Download delegate methods (implement in your delegate class)
def download_decideDestinationUsingResponse_suggestedFilename_completionHandler_(self, download: WKDownload, response: NSURLResponse, suggestedFilename: str, completionHandler: callable): ...
def download_willPerformHTTPRedirection_newRequest_decisionHandler_(self, download: WKDownload, response: NSHTTPURLResponse, request: NSURLRequest, decisionHandler: callable): ...
def download_didReceiveAuthenticationChallenge_completionHandler_(self, download: WKDownload, challenge: NSURLAuthenticationChallenge, completionHandler: callable): ...
def download_didWriteData_totalBytesWritten_totalBytesExpectedToWrite_(self, download: WKDownload, bytesWritten: int, totalBytesWritten: int, totalBytesExpectedToWrite: int): ...
def downloadDidFinish_(self, download: WKDownload): ...
def download_didFailWithError_resumeData_(self, download: WKDownload, error: NSError, resumeData: NSData): ...

Usage Examples

Creating a Basic Web View

import WebKit
from Foundation import NSURL, NSRect
from AppKit import NSApplication, NSWindow

# Create configuration
config = WebKit.WKWebViewConfiguration.alloc().init()

# Create web view
frame = NSRect((0, 0), (800, 600))
web_view = WebKit.WKWebView.alloc().initWithFrame_configuration_(frame, config)

# Load URL
url = NSURL.URLWithString_("https://www.apple.com")
request = Foundation.NSURLRequest.requestWithURL_(url)
web_view.loadRequest_(request)

Executing JavaScript

def handle_js_result(result, error):
    if error:
        print(f"JavaScript error: {error}")
    else:
        print(f"Result: {result}")

# Execute JavaScript
web_view.evaluateJavaScript_completionHandler_(
    "document.title", 
    handle_js_result
)

Implementing Navigation Delegate

class MyNavigationDelegate:
    def webView_didFinishNavigation_(self, web_view, navigation):
        print(f"Finished loading: {web_view.title()}")
    
    def webView_decidePolicyForNavigationAction_decisionHandler_(self, web_view, navigation_action, decision_handler):
        # Allow all navigation
        decision_handler(WebKit.WKNavigationActionPolicyAllow)

delegate = MyNavigationDelegate()
web_view.setNavigationDelegate_(delegate)

Install with Tessl CLI

npx tessl i tessl/pypi-pyobjc-framework-webkit

docs

constants.md

content-management.md

dom-manipulation.md

index.md

javascript-integration.md

legacy-webkit.md

modern-webkit.md

navigation.md

tile.json