Think outside the sandbox — UIWebView's hidden properties

Think outside the sandbox

Thoughts on Objective-C, Cocoa and other programming topics

UIWebView’s hidden properties

The UIWebView component comes in handy for loading HTML content or displaying documents such as PDF, Excel, Word, PowerPoint, Keynote, Numbers and Pages.

The implementation of UIWebView is based on WebKit, which is a multi-platform open source web browser engine. However, UIWebView doesn’t provide an obvious way for configuring the functionality of the rendering engine. For example, in case of memory pressure on iOS, WebKit will use the temporary folder to cache images. For security reasons, one might want to disable this behavior, but Apple doesn’t provide a documented method on how to do so. Fortunately, when the UIWebView component is initialized, all WebKit properties are loaded using NSUserDefaults. By replacing the method -[NSUserDefaults objectForKey:] with our own implementation, we can get a complete list of settings that can be used to customize the behavior of WebKit.

The WebKit properties and their default value are enumerated below. The sample project that was used to read these properties is hosted on GitHub.

  • WebKitKerningAndLigaturesEnabledByDefault = 1
  • WebKitLocalStorageDatabasePathPreferenceKey = %SANDBOX%/Library/Caches
  • WebKitStoreWebDataForBackup = (null)
  • WebKitSingleTapModeEnabled = (null)
  • WebKitDatabasesEnabledPreferenceKey = 1
  • WebKitStorageTrackerEnabledPreferenceKey = 0
  • WebKitLocalCache = (null)
  • WebKitDiskImageCacheSavedCacheDirectory =
  • WebKitUseSiteSpecificSpoofing = 0
  • WebKitCursiveFont = Snell Roundhand
  • WebKitDefaultFixedFontSize = 13
  • WebKitDefaultFontSize = 16
  • WebKitDefaultTextEncodingName = ISO-8859-1
  • WebKitUsesEncodingDetector = 0
  • WebKitFantasyFont = Papyrus
  • WebKitFixedFont = Courier
  • WebKitScreenFontSubstitutionEnabled = 0
  • WebKitForceFTPDirectoryListings = (null)
  • WebKitFTPDirectoryTemplatePath = (null)
  • WebKitJavaEnabled = (null)
  • WebKitJavaScriptEnabled = 1
  • WebKitWebSecurityEnabled = 1
  • WebKitAllowUniversalAccessFromFileURLs = 1
  • WebKitAllowFileAccessFromFileURLs = 1
  • WebKitJavaScriptCanOpenWindowsAutomatically = 0
  • WebKitMinimumFontSize = 0
  • WebKitMinimumLogicalFontSize = 9
  • WebKitPictographFont = AppleColorEmoji
  • WebKitPluginsEnabled = 1
  • WebKitLocalStorageEnabledPreferenceKey = 1
  • WebKitPrivateBrowsingEnabled = 0
  • WebKitSansSerifFont = Helvetica
  • WebKitSerifFont = Times
  • WebKitStandardFont = Times
  • WebKitDisplayImagesKey = 1
  • WebKitLoadSiteIconsKey = 0
  • WebKitShrinksStandaloneImagesToFit = 1
  • WebKitEditableLinkBehavior = 0
  • WebKitTextDirectionSubmenuInclusionBehaviorPreferenceKey = (null)
  • WebKitDOMPasteAllowedPreferenceKey = (null)
  • WebKitUsesPageCachePreferenceKey = 1
  • WebKitPageCacheSupportsPluginsPreferenceKey = 1
  • WebKitBackForwardCacheExpirationIntervalKey = 1800
  • DisableWebKitDeveloperExtras = (null)
  • WebKitDeveloperExtras = (null)
  • WebKitDeveloperExtrasEnabledPreferenceKey = 0
  • WebKitJavaScriptExperimentsEnabledPreferenceKey = 0
  • WebKitAuthorAndUserStylesEnabledPreferenceKey = 1
  • WebKitApplicationChromeModeEnabledPreferenceKey = 0
  • WebKitStandalonePreferenceKey = (null)
  • WebKitMaximumImageSize = 20971520
  • WebKitTelephoneParsingEnabledPreferenceKey = 0
  • WebKitAlwaysUseBaselineOfPrimaryFontPreferenceKey = (null)
  • WebKitAllowMultiElementImplicitFormSubmissionPreferenceKey = 0
  • WebKitLayoutIntervalPreferenceKey = -1
  • WebKitMaxParseDurationPreferenceKey = -1
  • WebKitAlwaysUseAcceleratedOverflowScroll = (null)
  • WebKitAllowCompositingLayerVisualDegradation = 0
  • WebKitWebArchiveDebugModeEnabledPreferenceKey = 0
  • WebKitLocalFileContentSniffingEnabledPreferenceKey = 0
  • WebKitOfflineWebApplicationCacheEnabled = 1
  • WebKitJavaScriptCanAccessClipboard = 0
  • WebKitXSSAuditorEnabled = 1
  • WebKitDNSPrefetchingEnabled = 0
  • WebKitAcceleratedCompositingEnabled = 1
  • WebKitAcceleratedDrawingEnabled = 0
  • WebKitCanvasUsesAcceleratedDrawing = 0
  • WebKitShowDebugBorders = 0
  • WebKitShowRepaintCounter = 0
  • WebKitAccelerated2dCanvasEnabled = 0
  • WebKitFrameFlatteningEnabled = 1
  • WebKitSpatialNavigationEnabled = 0
  • WebKitPaginateDuringLayoutEnabled = (null)
  • WebKitCSSRegionsEnabled = 1
  • WebKitCSSCompositingEnabled = 1
  • WebKitWebAudioEnabled = 1
  • WebKitSeamlessIFramesEnabled = (null)
  • WebKitCSSGridLayoutEnabled = 0
  • WebKitAsynchronousSpellCheckingEnabled = 0
  • WebKitHyperlinkAuditingEnabled = 1
  • WebKitUsePreHTML5ParserQuirks = 0
  • WebKitQTKitEnabled = 1
  • WebKitMediaPlaybackRequiresUserGesture = 1
  • WebKitMediaPlaybackAllowsInline = 0
  • WebKitMediaPlaybackAllowsAirPlay = 1
  • WebKitAudioSessionCategoryOverride = 0
  • WebKitNetworkDataUsageTrackingEnabledPreferenceKey = 0
  • WebKitNetworkInterfaceNamePreferenceKey =
  • WebKitSuppressesIncrementalRendering = (null)
  • WebKitRegionBasedColumnsEnabled = (null)
  • WebKitBackspaceKeyNavigationEnabled = (null)
  • WebKitWantsBalancedSetDefersLoadingBehavior = 0
  • WebKitMockScrollbarsEnabled = (null)
  • WebKitShouldDisplaySubtitles = (null)
  • WebKitShouldDisplayCaptions = (null)
  • WebKitShouldDisplayTextDescriptions = (null)
  • WebKitShouldRespectImageOrientation = 1
  • WebKitRequestAnimationFrameEnabled = 1
  • WebKitDiagnosticLoggingEnabled = 0
  • WebKitLowPowerVideoAudioBufferSizeEnabled = 0
  • WebKitStorageBlockingPolicy = 0
  • WebKitPlugInSnapshottingEnabled = 0
  • WebKitHiddenPageCSSAnimationSuspensionEnabled = 0
  • WebKitIncrementalRenderingSuppressionTimeoutInSeconds = (null)
  • WebKitApplicationCacheDefaultOriginQuota = 26214400
  • WebKitZoomsTextOnly = 1
  • WebKitMinimumZoomFontSizePreferenceKey = 15
  • WebKitDiskImageCacheEnabled = 1
  • WebKitDiskImageCacheMinimumImageSize = 102400
  • WebKitDiskImageCacheMaximumCacheSize = 104857600
  • WebKitInterpolationQualityPreferenceKey = 2
  • WebKitEnablePasswordEchoPreferenceKey = 1
  • WebKitPasswordEchoDurationPreferenceKey = 2
  • WebKitOmitPDFSupport = (null)