We recommend providing a unique, human-readable name for each inspectable JSContext to make it easier for you and your customers to determine what the JSContext represents. Unlike WKWebView, which automatically gets a name based on the page currently loaded in the view, every JSContext with inspectable enabled will be listed as JSContext in Safari’s Develop menu. Provide readable names for inspectable JSContexts It makes it harder for customers to use this functionality of your app. Without the ability for a release version of your app to adopt inspectability, your customers may have no way to debug the scripts they have written. JSContext can also enable scripting in an app whereby the customer provides the scripts to augment the app. Unfortunately, not all issues can or will get debugged by folks with access to a developer-provisioned copy of your app. Web content is often dynamic, delivered by a server-not in the app-and easily changed over time. It can be beneficial both for the app developer, as well as web authors, to be able to inspect content in these views, as the size of the view may not match that of Safari’s, or the app developer may be injecting script into the view to provide integration with their app. The browser shows ordinary web content that would be inspectable when loaded in Safari. Learn more about enabling Web Inspector… When should I consider making content inspectable?Ī common situation in which you may want the content of WKWebView to be inspectable is in an in-app web browser. You do not need to enable Web Inspector for simulators it is always enabled. For iOS and iPadOS, you must also have enabled Web Inspector in the Settings app under Safari > Advanced > Web Inspector. Once you’ve enabled inspection for your app, you can inspect it from Safari’s Develop menu in the submenu for either your current computer or an attached device. Disabling inspection while Web Inspector actively inspects the content will automatically close Web Inspector, and no further information about the content will be available. The inspectable property can be changed at any point during the lifetime of your WKWebView or JSContext. JSGlobalContextSetInspectable( jsContextRef, true) JsContext ?.isInspectable = true Objective-C JSContext *jsContext = Ĭ JSGlobalContextRef jsContextRef = JSGlobalContextCreate( NULL) WKWebView *webView = initWithFrame:CGRectZero configuration:webConfiguration] įor JSContext, matching API is available, with the addition of C API for developers using JSGlobalContextRef: Swift let jsContext = JSContext() WebView.isInspectable = true Objective-C WKWebViewConfiguration *webConfiguration = So, for example, to make a WKWebView inspectable, you would: Swift let webConfiguration = WKWebViewConfiguration() This decision is made for each individual WKWebView and JSContext to prevent unintentionally making it enabled for a view or context you don’t intend to be inspectable. It defaults to false, and you can set it to true to opt-in to content being inspectable. How do I enable inspection?Īcross all platforms supporting WKWebView or JSContext, a new property is available called isInspectable ( inspectable in Objective-C). Now, this same functionality is available through an API on WKWebView and JSContext. However, released versions of apps had no way to inspect dynamic web content or scripts, leaving developers and users to have to resort to more complicated workflows to get information that would otherwise be made available by Web Inspector. Previously, Web Inspector supported inspecting developer-provisioned apps built directly from Xcode for local development, meaning developers could debug this content so long as the app is installed for development. Web content and JavaScript is used for various purposes in apps, from providing UI from a webpage to enabling apps to be scriptable. iOS and iPadOS allow inspection of the same content as macOS, with the addition of Home Screen web apps. In Safari on macOS, you can use Web Inspector to inspect web pages, extensions, and service workers. Web Inspector is a powerful tool that allows you to debug the layout of web pages, step through JavaScript, read messages logged to the console, and more.
0 Comments
Leave a Reply. |