Platforms to show: All Mac Windows Linux Cross-Platform

Back to WKWebViewMBS class.

WKWebViewMBS.addUserScript(userScript as WKUserScriptMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Adds an user script.

WKWebViewMBS.Constructor

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Creates a new web view with size 100/100 and position 0/0
Example
dim x as new WebViewMBS

On success the handle property is not zero.

See also:

WKWebViewMBS.Constructor(Handle as Integer)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Creates an object based on the given WKWebView handle.
Example
dim t as new WKWebViewMBS(0, 0, 100, 100)
dim v as new WKWebViewMBS(t.handle)

MsgBox str(v.Bounds.Width)+" x "+str(v.Bounds.Height)

The handle is casted to a WKWebView and the plugin retains this handle.

See also:

WKWebViewMBS.Constructor(left as double, top as double, width as double, height as double)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Creates a new button with the given size and position.
Example
dim w as new WKWebViewMBS(0,0,800,600)

w.LoadHTMLString "Hello World",""

On success the handle property is not zero.

See also:

WKWebViewMBS.copy

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Copies current text selection.

WKWebViewMBS.cut

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Cuts current text selection.

WKWebViewMBS.deleteSelection

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Deletes current text selection.

WKWebViewMBS.EvaluateJavaScript(JavaScript as String, byref Error as NSErrorMBS) as Variant

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Evaluates JavaScript.
Example
Dim w As WKWebViewMBS = WKWebViewControlMBS1.WKWebView
Dim e As NSErrorMBS

// returns array of variants with doubles
Dim v As Variant = w.EvaluateJavaScript("o = [1,2,3];", e)
Dim vd() As Variant = v

// returns array of variants with strings
Dim vv As Variant = w.EvaluateJavaScript("o = [""a"",""b"",""d""];", e)
Dim vs() As Variant = vv

// returns dictionary
Dim v3 As Variant = w.EvaluateJavaScript("o = {a:1}", e)
Dim dd As Dictionary = v3

Break

Synchronous version which waits for JavaScript to return the value.
Error is set in case of errors.

Result is converted from JavaScript data types to Xojo datatypes, usually variants, dictionaries or array of variants.

WKWebViewMBS.goBack

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Navigates to the back item in the back-forward list.

WKWebViewMBS.goForward

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Navigates to the forward item in the back-forward list.

WKWebViewMBS.goToBackForwardListItem(Item as WKBackForwardListItemMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Navigates to an item from the back-forward list and sets it as the current item.

item: The item to which to navigate. Must be one of the items in the web view's back-forward list.

WKWebViewMBS.HTMLText as String

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.3 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Queries HTML text for the current main page.

This is live, so any changes made after loading will be included.

WKWebViewMBS.LoadData(Data as MemoryBlock, MIMEType as String, textEncodingName as String, baseURL as string = "")

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Sets the webpage contents and base URL.
Example
Dim browser As WKWebViewMBS // your instance

browser.LoadData "<p>Hello World</p>", "text/html", "UTF-8", ""

data: The data to use as the contents of the webpage.
MIMEType: The MIME type of the data.
characterEncodingName: The data's character encoding name.
baseURL: A URL used to resolve relative URLs within the document.

WKWebViewMBS.LoadFileURL(File as FolderItem, readAccessItem as FolderItem)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Navigates to a requested file.
Example
Dim w as WKWebViewMBS // your web viewer
Dim HTMLFile as folderItem = getfolderItem("test.html")

// pass folderitem parent to allow read to other files in same folder
w.LoadFileURL HTMLFile, HTMLFile.parent

Navigates to the requested file URL on the filesystem.
file: The file URL to which to navigate.
readAccessItem: The file or folder to allow read access to.
If readAccessItem references a single file, only that file may be loaded by WebKit.
If readAccessItem references a directory, files inside that file may be loaded by WebKit.

WKWebViewMBS.LoadHTML(htmlText as String, baseURL as string = "")

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Sets the webpage contents and base URL.
Example
Dim browser As WKWebViewMBS // your instance

browser.LoadHTML "<p>Hello World</p>"

htmlText: The string to use as the contents of the webpage.
baseURL: A URL used to resolve relative URLs within the document.

WKWebViewMBS.LoadURL(URL as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Navigates to a requested URL.
Example

Dim browser As WKWebViewMBS // your instance

browser.LoadURL "https://www.mbsplugins.de/xojo"

WKWebViewMBS.LoadURLRequest(Request as NSURLRequestMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Navigates to a requested URL.

WKWebViewMBS.MainResourceData(byref error as NSErrorMBS) as MemoryBlock

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.3 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Queries the source data from the webviewer.

Returns nil in case of error.
Also sets error parameter to NSErrorMBS for details on the error.

Some examples using this method:

WKWebViewMBS.paste

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Pastes clipboard into current position in document.

WKWebViewMBS.PDFData(byref error as NSErrorMBS) as MemoryBlock

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.3 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Create a PDF document representation from the web page currently displayed in the WKWebView.

Returns PDF data of new PDF Document.
If the data is written to a file the resulting file is a valid PDF document.

Available in macOS 11.0 or newer.
May also work if Safari 14 is installed on older macOS versions.

Some examples using this method:

WKWebViewMBS.PlainText as String

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.3 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Queries plain text for the current main page.

This is live, so any changes made after loading will be included.

WKWebViewMBS.printOperation(printInfo as NSPrintInfoMBS) as NSPrintOperationMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Creates a print operation for the current web viewer.
Example
dim browser as WKWebViewMBS // your web viewer
Dim pi As NSPrintInfoMBS = NSPrintInfoMBS.sharedPrintInfo
Dim po As NSPrintOperationMBS = browser.printOperation(pi)

po.showsPrintPanel = True
po.showsProgressPanel = True

po.runOperationModalForWindow(Self)

Works for WebKit 1.x and 2.x.

For WebKit 2.x may run into endless loop for some websites due to bugs in Apple's WebKit framework.

WKWebViewMBS.reload

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Reloads the current page.
Example
Public Sub Reload(browser as WKWebViewMBS, force as Boolean)
If force Then
browser.reloadFromOrigin
Else
browser.reload
End If
End Sub

WKWebViewMBS.reloadFromOrigin

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Reloads the current page, performing end-to-end revalidation using cache-validating conditionals if possible.
Example
Public Sub Reload(browser as WKWebViewMBS, force as Boolean)
If force Then
browser.reloadFromOrigin
Else
browser.reload
End If
End Sub

WKWebViewMBS.removeAllUserScripts

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Removes all associated user scripts.
Example
Dim browser As WKWebViewMBS // your instance

browser.removeAllUserScripts

WKWebViewMBS.selectAll

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Selects all.

WKWebViewMBS.setMagnification(magnification as double, pointX as double, pointY as double)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Scales the page content by a specified factor and centers the result on a specified point.
Example
Dim browser As WKWebViewMBS // your instance

// zoom to 200% on 100/100
browser.setMagnification(2, 100, 100)

magnification: The factor by which to scale the content.
x/y: The point (in view space) to center magnification on. As usual with Cocoa, bottom is y = 0.

For MacOS 64-bit only.

WKWebViewMBS.stopLoading

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Stops loading all resources on the current page.
Example
Dim browser As WKWebViewMBS // your instance

browser.stopLoading

WKWebViewMBS.takeSnapshot(byref error as NSErrorMBS) as NSImageMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Requests a snapshot.
Example
// get a webview reference
Dim web As WKWebViewMBS = HTMLViewer1.WKWebViewMBS

// take snapshot
Dim error As NSErrorMBS
Dim image As NSImageMBS = web.takeSnapshot(error)

If error <> Nil Then
MsgBox error.LocalizedDescription
return
End If

// save as PNG
Dim png As String = image.PNGRepresentation

// write to file
Dim f As FolderItem = SpecialFolder.Desktop.Child("test.png")
Dim b As BinaryStream = BinaryStream.Create(f, True)
b.Write png

This is synchronous version which waits for image to be finished.
In case of error the result is nil and error may be set.

WKWebViewMBS.userScripts as WKUserScriptMBS()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.0 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
The user scripts associated with the user content controller.

WKWebViewMBS.WebArchiveData(byref error as NSErrorMBS) as MemoryBlock

Type Topic Plugin Version macOS Windows Linux iOS Targets
method WebKit2 MBS Mac64bit Plugin 20.3 ✅ Yes ❌ No ❌ No ✅ Yes Desktop & iOS
Queries web archive data for the website.
Example
Dim w As WKWebViewMBS = HTMLViewer1.WKWebViewMBS

Dim error As NSErrorMBS
Dim data As MemoryBlock = w.WebArchiveData(error)

Break // inspect in debugger

May return nil in case of error and maybe report the NSError in case of an error.

The items on this page are in the following plugins: MBS Mac64bit Plugin.


The biggest plugin in space...