Python bindings for Apple's WebKit and JavaScriptCore frameworks on macOS, enabling web browser functionality and JavaScript execution in Python applications
—
This document covers navigation types, error codes, content policies, and other enumerated values used throughout the WebKit and JavaScriptCore frameworks. These constants are essential for handling navigation events, error conditions, and configuring framework behavior.
Navigation type constants for WKNavigationAction.
# WK Navigation Types
WKNavigationTypeLinkActivated = 0 # User activated a link
WKNavigationTypeFormSubmitted = 1 # User submitted a form
WKNavigationTypeBackForward = 2 # User used back/forward navigation
WKNavigationTypeReload = 3 # User reloaded the page
WKNavigationTypeFormResubmitted = 4 # User resubmitted a form
WKNavigationTypeOther = -1 # Other navigation typesPolicy constants for navigation and response handling.
# WK Navigation Action Policies
WKNavigationActionPolicyCancel = 0 # Cancel the navigation
WKNavigationActionPolicyAllow = 1 # Allow the navigation
WKNavigationActionPolicyDownload = 2 # Download the resource instead
# WK Navigation Response Policies
WKNavigationResponsePolicyCancel = 0 # Cancel loading the response
WKNavigationResponsePolicyAllow = 1 # Allow loading the response
WKNavigationResponsePolicyDownload = 2 # Download the responseNavigation type constants for legacy WebView components.
# Web Navigation Types (Legacy)
WebNavigationTypeLinkClicked = 0 # User clicked a link
WebNavigationTypeFormSubmitted = 1 # User submitted a form
WebNavigationTypeBackForward = 2 # Back/forward navigation
WebNavigationTypeReload = 3 # Page reload
WebNavigationTypeFormResubmitted = 4 # Form resubmission
WebNavigationTypeOther = 5 # Other navigationError codes for WebKit operations and failures.
# WK Error Codes
WKErrorUnknown = 1 # Unknown error
WKErrorWebContentProcessTerminated = 2 # Web content process crashed
WKErrorWebViewInvalidated = 3 # Web view was invalidated
WKErrorJavaScriptExceptionOccurred = 4 # JavaScript exception occurred
WKErrorJavaScriptResultTypeIsUnsupported = 5 # Unsupported JavaScript result type
WKErrorContentRuleListStoreCompileFailed = 6 # Content rule compilation failed
WKErrorContentRuleListStoreLookUpFailed = 7 # Content rule lookup failed
WKErrorContentRuleListStoreRemoveFailed = 8 # Content rule removal failed
WKErrorContentRuleListStoreVersionMismatch = 9 # Content rule version mismatch
WKErrorAttributedStringContentFailedToLoad = 10 # Attributed string content loading failed
WKErrorAttributedStringContentLoadTimedOut = 11 # Attributed string content load timeoutWKErrorDomain = "WKErrorDomain" # Error domain for WebKit errorsWhen to inject user scripts into web pages.
# WK User Script Injection Times
WKUserScriptInjectionTimeAtDocumentStart = 0 # Inject after document creation but before loading
WKUserScriptInjectionTimeAtDocumentEnd = 1 # Inject after document load completion# WK Website Data Types
WKWebsiteDataTypeCookies = "WKWebsiteDataTypeCookies"
WKWebsiteDataTypeDiskCache = "WKWebsiteDataTypeDiskCache"
WKWebsiteDataTypeMemoryCache = "WKWebsiteDataTypeMemoryCache"
WKWebsiteDataTypeOfflineWebApplicationCache = "WKWebsiteDataTypeOfflineWebApplicationCache"
WKWebsiteDataTypeSessionStorage = "WKWebsiteDataTypeSessionStorage"
WKWebsiteDataTypeLocalStorage = "WKWebsiteDataTypeLocalStorage"
WKWebsiteDataTypeWebSQLDatabases = "WKWebsiteDataTypeWebSQLDatabases"
WKWebsiteDataTypeIndexedDBDatabases = "WKWebsiteDataTypeIndexedDBDatabases"
WKWebsiteDataTypeServiceWorkerRegistrations = "WKWebsiteDataTypeServiceWorkerRegistrations"
WKWebsiteDataTypeFetchCache = "WKWebsiteDataTypeFetchCache"
WKWebsiteDataTypeFileSystem = "WKWebsiteDataTypeFileSystem"
WKWebsiteDataTypeSearchFieldRecentSearches = "WKWebsiteDataTypeSearchFieldRecentSearches"
WKWebsiteDataTypeMediaKeys = "WKWebsiteDataTypeMediaKeys"
WKWebsiteDataTypeHashSalt = "WKWebsiteDataTypeHashSalt"# WK Media Capture States
WKMediaCaptureStateNone = 0
WKMediaCaptureStateActive = 1
WKMediaCaptureStateMuted = 2
# WK Audiovisual Media Types
WKAudiovisualMediaTypeNone = 0
WKAudiovisualMediaTypeAudio = 1
WKAudiovisualMediaTypeVideo = 2
WKAudiovisualMediaTypeAll = -1
# WK Content Mode
WKContentModeRecommended = 0
WKContentModeMobile = 1
WKContentModeDesktop = 2
# WK Selection Granularity
WKSelectionGranularityDynamic = 0
WKSelectionGranularityCharacter = 1
# WK Data Detector Types
WKDataDetectorTypeNone = 0
WKDataDetectorTypePhoneNumber = 1
WKDataDetectorTypeLink = 2
WKDataDetectorTypeAddress = 4
WKDataDetectorTypeCalendarEvent = 8
WKDataDetectorTypeTrackingNumber = 16
WKDataDetectorTypeFlightNumber = 32
WKDataDetectorTypeLookupSuggestion = 64
WKDataDetectorTypeAll = -1
# WK Permission Decision
WKPermissionDecisionPrompt = 0
WKPermissionDecisionGrant = 1
WKPermissionDecisionDeny = 2# DOM Node Types
DOM_ELEMENT_NODE = 1
DOM_ATTRIBUTE_NODE = 2
DOM_TEXT_NODE = 3
DOM_CDATA_SECTION_NODE = 4
DOM_ENTITY_REFERENCE_NODE = 5
DOM_ENTITY_NODE = 6
DOM_PROCESSING_INSTRUCTION_NODE = 7
DOM_COMMENT_NODE = 8
DOM_DOCUMENT_NODE = 9
DOM_DOCUMENT_TYPE_NODE = 10
DOM_DOCUMENT_FRAGMENT_NODE = 11
DOM_NOTATION_NODE = 12# DOM CSS Value Types
DOM_CSS_INHERIT = 0
DOM_CSS_PRIMITIVE_VALUE = 1
DOM_CSS_VALUE_LIST = 2
DOM_CSS_CUSTOM = 3# DOM Event Phase Constants
DOM_CAPTURING_PHASE = 1
DOM_AT_TARGET = 2
DOM_BUBBLING_PHASE = 3
# DOM Key Location Constants
DOM_KEY_LOCATION_STANDARD = 0
DOM_KEY_LOCATION_LEFT = 1
DOM_KEY_LOCATION_RIGHT = 2
DOM_KEY_LOCATION_NUMPAD = 3# JavaScript Types (JSType enum)
kJSTypeUndefined = 0
kJSTypeNull = 1
kJSTypeBoolean = 2
kJSTypeNumber = 3
kJSTypeString = 4
kJSTypeObject = 5
kJSTypeSymbol = 6
kJSTypeBigInt = 7# JavaScript Property Attributes
kJSPropertyAttributeNone = 0
kJSPropertyAttributeReadOnly = 2
kJSPropertyAttributeDontEnum = 4
kJSPropertyAttributeDontDelete = 8# JavaScript Class Attributes
kJSClassAttributeNone = 0
kJSClassAttributeNoAutomaticPrototype = 2# TypedArray Types
kJSTypedArrayTypeInt8Array = 0
kJSTypedArrayTypeInt16Array = 1
kJSTypedArrayTypeInt32Array = 2
kJSTypedArrayTypeUint8Array = 3
kJSTypedArrayTypeUint8ClampedArray = 4
kJSTypedArrayTypeUint16Array = 5
kJSTypedArrayTypeUint32Array = 6
kJSTypedArrayTypeFloat32Array = 7
kJSTypedArrayTypeFloat64Array = 8
kJSTypedArrayTypeArrayBuffer = 9
kJSTypedArrayTypeNone = 10
kJSTypedArrayTypeBigInt64Array = 11
kJSTypedArrayTypeBigUint64Array = 12
kJSTypedArrayTypeDataView = 13# Property Descriptor Keys (for Object.defineProperty)
JSPropertyDescriptorConfigurableKey = "configurable"
JSPropertyDescriptorEnumerableKey = "enumerable"
JSPropertyDescriptorGetKey = "get"
JSPropertyDescriptorSetKey = "set"
JSPropertyDescriptorValueKey = "value"
JSPropertyDescriptorWritableKey = "writable"# WebKit Version Constants
WEBKIT_VERSION_1_0 = 256
WEBKIT_VERSION_1_1 = 272
WEBKIT_VERSION_1_2 = 288
WEBKIT_VERSION_1_3 = 304
WEBKIT_VERSION_2_0 = 512
WEBKIT_VERSION_3_0 = 768
WEBKIT_VERSION_3_1 = 784
WEBKIT_VERSION_4_0 = 1024
WEBKIT_VERSION_LATEST = 39321# WebView Progress Notifications
WebViewProgressStartedNotification = "WebViewProgressStartedNotification"
WebViewProgressEstimateChangedNotification = "WebViewProgressEstimateChangedNotification"
WebViewProgressFinishedNotification = "WebViewProgressFinishedNotification"
# WebView Editing Notifications
WebViewDidBeginEditingNotification = "WebViewDidBeginEditingNotification"
WebViewDidChangeNotification = "WebViewDidChangeNotification"
WebViewDidEndEditingNotification = "WebViewDidEndEditingNotification"
WebViewDidChangeTypingStyleNotification = "WebViewDidChangeTypingStyleNotification"
WebViewDidChangeSelectionNotification = "WebViewDidChangeSelectionNotification"# Element Dictionary Keys (for hit testing results)
WebElementDOMNodeKey = "WebElementDOMNode"
WebElementFrameKey = "WebElementFrame"
WebElementImageKey = "WebElementImage"
WebElementImageAltStringKey = "WebElementImageAltString"
WebElementImageRectKey = "WebElementImageRect"
WebElementImageURLKey = "WebElementImageURL"
WebElementIsSelectedKey = "WebElementIsSelected"
WebElementLinkURLKey = "WebElementLinkURL"
WebElementLinkTargetFrameKey = "WebElementLinkTargetFrame"
WebElementLinkTitleKey = "WebElementLinkTitle"
WebElementLinkLabelKey = "WebElementLinkLabel"
WebElementSpellingToolTipKey = "WebElementSpellingToolTip"
WebElementTitleKey = "WebElementTitle"
WebElementLinkIsLiveKey = "WebElementLinkIsLive"# Cache Models for WebPreferences
WebCacheModelDocumentViewer = 0 # Appropriate for document viewer
WebCacheModelDocumentBrowser = 1 # Appropriate for document browser
WebCacheModelPrimaryWebBrowser = 2 # Appropriate for primary web browserimport WebKit
class NavigationDelegate:
def webView_decidePolicyForNavigationAction_decisionHandler_(self, web_view, action, handler):
navigation_type = action.navigationType()
if navigation_type == WebKit.WKNavigationTypeLinkActivated:
print("User clicked a link")
handler(WebKit.WKNavigationActionPolicyAllow)
elif navigation_type == WebKit.WKNavigationTypeFormSubmitted:
print("User submitted a form")
handler(WebKit.WKNavigationActionPolicyAllow)
else:
handler(WebKit.WKNavigationActionPolicyAllow)import WebKit
class NavigationDelegate:
def webView_didFailNavigation_withError_(self, web_view, navigation, error):
error_code = error.code()
if error_code == WebKit.WKErrorWebContentProcessTerminated:
print("Web content process crashed - reloading")
web_view.reload()
elif error_code == WebKit.WKErrorJavaScriptExceptionOccurred:
print(f"JavaScript error: {error.localizedDescription()}")
else:
print(f"Navigation error: {error.localizedDescription()}")import JavaScriptCore
def handle_js_value(js_value, context):
value_type = JavaScriptCore.JSValueGetType(context, js_value)
if value_type == JavaScriptCore.kJSTypeString:
return "String value"
elif value_type == JavaScriptCore.kJSTypeNumber:
return "Number value"
elif value_type == JavaScriptCore.kJSTypeBoolean:
return "Boolean value"
elif value_type == JavaScriptCore.kJSTypeObject:
return "Object value"
elif value_type == JavaScriptCore.kJSTypeNull:
return "Null value"
elif value_type == JavaScriptCore.kJSTypeUndefined:
return "Undefined value"
else:
return "Unknown type"These constants provide the foundation for handling WebKit and JavaScriptCore framework events, errors, and configuration throughout your application development.
Install with Tessl CLI
npx tessl i tessl/pypi-pyobjc-framework-webkit