Display web content in a window from Hammerspoon
This module uses Apple's WebKit WKWebView class to provide web content display with JavaScript injection support. The objective is to provide a functional interface to the WKWebView and WKUserContentController classes.
This module is not intended to replace a full web browser and does have some limitations to keep in mind:
hs.webview:reload(true)
and by crafting the url for hs.webview:url({...})
as a table -- see the appropriate help entries for more information.Any suggestions or updates to the code to address any of these or other limitations as they may become apparent are welcome at the Hammerspoon github site: https://www.github.com/Hammerspoon/hammerspoon
Signature | hs.webview:asHSDrawing() -> hs.drawing object |
---|---|
Type | Deprecated |
Description | Because use of this method can easily lead to a crash, useful methods from |
Source | extensions/webview/webview.lua line 346 |
Signature | hs.webview:asHSWindow() -> hs.window object |
---|---|
Type | Deprecated |
Description | Returns an hs.window object for the webview so that you can use hs.window methods on it. |
Source | extensions/webview/webview.lua line 269 |
Signature | hs.webview:setLevel(theLevel) -> drawingObject |
---|---|
Type | Deprecated |
Description | Deprecated; you should use hs.webview:level instead. |
Notes |
|
Source | extensions/webview/webview.lua line 282 |
Signature | hs.webview.certificateOIDs[] |
---|---|
Type | Constant |
Description | A table of common OID values found in SSL certificates. SSL certificates provided to the callback function for hs.webview:sslCallback or in the results of hs.webview:certificateChain use OID strings as the keys which describe the properties of the certificate and this table can be used to get a more common name for the keys you are most likely to see. |
Source | extensions/webview/libwebview.m line 2570 |
Signature | hs.webview.windowMasks[] |
---|---|
Type | Constant |
Description | A table containing valid masks for the webview window. |
Notes |
|
Source | extensions/webview/libwebview.m line 2528 |
Signature | hs.webview:titleVisibility([state]) -> webviewObject | string |
---|---|
Type | Function |
Description | Get or set whether or not the title text appears in the webview window. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 2179 |
Signature | hs.webview.new(rect, [preferencesTable], [userContentController]) -> webviewObject |
---|---|
Type | Constructor |
Description | Create a webviewObject and optionally modify its preferences. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 1798 |
Signature | hs.webview.newBrowser(rect, [preferencesTable], [userContentController]) -> webviewObject |
---|---|
Type | Constructor |
Description | Create a webviewObject with some presets common to an interactive web browser. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/webview.lua line 80 |
Signature | hs.webview:allowGestures([value]) -> webviewObject | current value |
---|---|
Type | Method |
Description | Get or set whether or not the webview will respond to gestures from a trackpad or magic mouse. Default is false. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/webview.lua line 166 |
Signature | hs.webview:allowMagnificationGestures([value]) -> webviewObject | current value |
---|---|
Type | Method |
Description | Get or set whether or not the webview will respond to magnification gestures from a trackpad or magic mouse. Default is false. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 1273 |
Signature | hs.webview:allowNewWindows([value]) -> webviewObject | current value |
---|---|
Type | Method |
Description | Get or set whether or not the webview allows new windows to be opened from it by any method. Defaults to true. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 1297 |
Signature | hs.webview:allowTextEntry([value]) -> webviewObject | current value |
---|---|
Type | Method |
Description | Get or set whether or not the webview can accept keyboard for web form entry. Defaults to false. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 1992 |
Signature | hs.webview:alpha([alpha]) -> webviewObject | currentValue |
---|---|
Type | Method |
Description | Get or set the alpha level of the window containing the hs.webview object. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 2320 |
Signature | hs.webview:attachedToolbar([toolbar]) -> webviewObject | currentValue |
---|---|
Type | Method |
Description | Get or attach/detach a toolbar to/from the webview. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/webview.lua line 107 |
Signature | hs.webview:behavior([behavior]) -> webviewObject | currentValue |
---|---|
Type | Method |
Description | Get or set the window behavior settings for the webview object. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 2445 |
Signature | hs.webview:behaviorAsLabels(behaviorTable) -> webviewObject | currentValue |
---|---|
Type | Method |
Description | Get or set the window behavior settings for the webview object using labels defined in |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/webview.lua line 299 |
Signature | hs.webview:bringToFront([aboveEverything]) -> webviewObject |
---|---|
Type | Method |
Description | Places the drawing object on top of normal windows |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 2284 |
Signature | hs.webview:certificateChain() -> table | nil |
---|---|
Type | Method |
Description | Returns the certificate chain for the most recently committed navigation of the webview. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 1006 |
Signature | hs.webview:children() -> array |
---|---|
Type | Method |
Description | Returns an array of webview objects which have been opened as children of this webview. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 854 |
Signature | hs.webview:closeOnEscape([flag]) -> webviewObject | current value |
---|---|
Type | Method |
Description | If the webview is closable, this will get or set whether or not the Escape key is allowed to close the webview window. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 2071 |
Signature | hs.webview:darkMode([state]) -> bool |
---|---|
Type | Method |
Description | Set or display whether or not the |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 2040 |
Signature | hs.webview:delete([propagate], [fadeOutTime]) -> none |
---|---|
Type | Method |
Description | Destroys the webview object, optionally fading it out first (if currently visible). |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/webview.lua line 189 |
Signature | hs.webview:deleteOnClose([value]) -> webviewObject | current value |
---|---|
Type | Method |
Description | Get or set whether or not the webview should delete itself when its window is closed. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 2014 |
Signature | hs.webview:estimatedProgress() -> number |
---|---|
Type | Method |
Description | Returns the estimated percentage of expected content that has been loaded. Will equal 1.0 when all content has been loaded. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 1135 |
Signature | hs.webview:evaluateJavaScript(script, [callback]) -> webviewObject |
---|---|
Type | Method |
Description | Execute JavaScript within the context of the current webview and optionally receive its result or error in a callback function. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 1676 |
Signature | hs.webview:examineInvalidCertificates([flag]) -> webviewObject | current value |
---|---|
Type | Method |
Description | Get or set whether or not invalid SSL server certificates that are approved by the ssl callback function are accepted as valid for browsing with the webview. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 1325 |
Signature | hs.webview:frame([rect]) -> webviewObject | currentValue |
---|---|
Type | Method |
Description | Get or set the frame of the webview window. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/webview.lua line 216 |
Signature | hs.webview:goBack() -> webviewObject |
---|---|
Type | Method |
Description | Move to the previous page in the webview's history, if possible. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 1195 |
Signature | hs.webview:goForward() -> webviewObject |
---|---|
Type | Method |
Description | Move to the next page in the webview's history, if possible. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 1175 |
Signature | hs.webview:hide([fadeOutTime]) -> webviewObject |
---|---|
Type | Method |
Description | Hides the webview object |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 1966 |
Signature | hs.webview:historyList() -> historyTable |
---|---|
Type | Method |
Description | Returns the URL history for the current webview as an array. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 1653 |
Signature | hs.webview:hswindow() -> hs.window object |
---|---|
Type | Method |
Description | Returns an hs.window object for the webview so that you can use hs.window methods on it. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 2098 |
Signature | hs.webview:html(html,[baseURL]) -> webviewObject, navigationIdentifier |
---|---|
Type | Method |
Description | Render the given HTML in the webview with an optional base URL for relative links. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 1421 |
Signature | hs.webview:isOnlySecureContent() -> bool |
---|---|
Type | Method |
Description | Returns a boolean value indicating if all content current displayed in the webview was loaded over securely encrypted connections. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 1155 |
Signature | hs.webview:isVisible() -> boolean |
---|---|
Type | Method |
Description | Checks to see if a webview window is visible or not. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 2126 |
Signature | hs.webview:level([theLevel]) -> drawingObject | currentValue |
---|---|
Type | Method |
Description | Get or set the window level |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 2250 |
Signature | hs.webview:loading() -> boolean |
---|---|
Type | Method |
Description | Returns a boolean value indicating whether or not the webview is still loading content. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 1089 |
Signature | hs.webview:magnification([value]) -> webviewObject | current value |
---|---|
Type | Method |
Description | Get or set the webviews current magnification level. Default is 1.0. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 1387 |
Signature | hs.webview:orderAbove([webview2]) -> webviewObject |
---|---|
Type | Method |
Description | Moves webview object above webview2, or all webview objects in the same presentation level, if webview2 is not given. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 2388 |
Signature | hs.webview:orderBelow([webview2]) -> webviewObject |
---|---|
Type | Method |
Description | Moves webview object below webview2, or all webview objects in the same presentation level, if webview2 is not given. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 2404 |
Signature | hs.webview:parent() -> webviewObject | nil |
---|---|
Type | Method |
Description | Get the parent webview object for the calling webview object, or nil if the webview has no parent. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 877 |
Signature | hs.webview:policyCallback(fn) -> webviewObject |
---|---|
Type | Method |
Description | Sets a callback to approve or deny web navigation activity. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 1503 |
Signature | hs.webview:privateBrowsing() -> boolean |
---|---|
Type | Method |
Description | Returns whether or not the webview browser is set up for private browsing (i.e. uses a non-persistent datastore) |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 819 |
Signature | hs.webview:reload([validate]) -> webviewObject, navigationIdentifier |
---|---|
Type | Method |
Description | Reload the page in the webview, optionally performing end-to-end revalidation using cache-validating conditionals if possible. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 1215 |
Signature | hs.webview:sendToBack() -> webviewObject |
---|---|
Type | Method |
Description | Places the webview object behind normal windows, between the desktop wallpaper and desktop icons |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 2302 |
Signature | hs.webview:shadow([value]) -> webviewObject | current value |
---|---|
Type | Method |
Description | Get or set whether or not the webview window has shadows. Default to false. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 2344 |
Signature | hs.webview:show([fadeInTime]) -> webviewObject |
---|---|
Type | Method |
Description | Displays the webview object |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 1940 |
Signature | hs.webview:size([size]) -> webviewObject | currentValue |
---|---|
Type | Method |
Description | Get or set the size of a webview window |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 1765 |
Signature | hs.webview:sslCallback(fn) -> webviewObject |
---|---|
Type | Method |
Description | Sets a callback to examine an invalid SSL certificate and determine if an exception should be granted. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 1600 |
Signature | hs.webview:stopLoading() -> webviewObject |
---|---|
Type | Method |
Description | Stop loading additional content for the webview. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 1109 |
Signature | hs.webview:title() -> title |
---|---|
Type | Method |
Description | Get the title of the page displayed in the webview. |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 1048 |
Signature | hs.webview:topLeft([point]) -> webviewObject | currentValue |
---|---|
Type | Method |
Description | Get or set the top-left coordinate of the webview window |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 1733 |
Signature | hs.webview:transparent([value]) -> webviewObject | current value |
---|---|
Type | Method |
Description | Get or set whether or not the webview background is transparent. Default is false. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 1245 |
Signature | hs.webview:url([URL]) -> webviewObject, navigationIdentifier | url |
---|---|
Type | Method |
Description | Get or set the URL to render for the webview. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 900 |
Signature | hs.webview:urlParts() -> table |
---|---|
Type | Method |
Description | Returns a table of keys containing the individual components of the URL for the webview. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/webview.lua line 252 |
Signature | hs.webview:userAgent([agent]) -> webviewObject | current value |
---|---|
Type | Method |
Description | Get or set the webview's user agent string |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 962 |
Signature | hs.webview:windowCallback(fn) -> webviewObject |
---|---|
Type | Method |
Description | Set or clear a callback for updates to the webview window |
Parameters |
|
Returns |
|
Source | extensions/webview/libwebview.m line 2486 |
Signature | hs.webview:windowStyle(mask) -> webviewObject | currentMask |
---|---|
Type | Method |
Description | Get or set the window display style |
Parameters |
|
Returns |
|
Source | extensions/webview/webview.lua line 123 |
Signature | hs.webview:windowTitle([title]) -> webviewObject |
---|---|
Type | Method |
Description | Sets the title for the webview window. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/webview/libwebview.m line 2147 |