# Sandbox, local pages and DesktopHTMLViewer

**URL:** <https://forum.xojo.com/t/sandbox-local-pages-and-desktophtmlviewer/73361>\
**Category:** macOS\
**Created:** [November 24, 2022, 12:17am UTC](https://forum.xojo.com/t/sandbox-local-pages-and-desktophtmlviewer/73361 "2022-11-24T00:17:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrice\_C](https://forum.xojo.com/user_avatar/forum.xojo.com/patrice_c/32/14346_2.png) [@Patrice\_C](https://forum.xojo.com/u/Patrice_C)\
**Post date:** [November 24, 2022, 12:17am UTC](https://forum.xojo.com/t/sandbox-local-pages-and-desktophtmlviewer/73361/1 "2022-11-24T00:17:08Z")

</div>

Anyone have an updated code working with last version of XOJO and DesktopHTMLViewer.

I cannot display the content from a local website when an app is sandboxed

This code seems to fix it for old versions of Xojo  
[https://ohanaware.com/blog/202150/WKWebKit,-Xojo-HTMLViewer-and-App-Sandbox.html](https://ohanaware.com/blog/202150/WKWebKit,-Xojo-HTMLViewer-and-App-Sandbox.html)

---

<div class="post-metadata">

**Author:** ![Sam\_Rowlands](https://forum.xojo.com/user_avatar/forum.xojo.com/sam_rowlands/32/265_2.png) [@Sam\_Rowlands](https://forum.xojo.com/u/Sam_Rowlands)\
**Post date:** [November 24, 2022, 8:11am UTC](https://forum.xojo.com/t/sandbox-local-pages-and-desktophtmlviewer/73361/2 "2022-11-24T08:11:32Z")

</div>

Pretty much everything I want to say would get me kicked off this forum and branded as a Troll, so I’ll show myself out, before it’s too late.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [November 24, 2022, 6:18pm UTC](https://forum.xojo.com/t/sandbox-local-pages-and-desktophtmlviewer/73361/3 "2022-11-24T18:18:18Z")

</div>

What kind of local website are you talking about ?

I use html files in all my apps to display help, and that includes apps sandboxed to go to the MAS.

Could you post your code ?

I just verified with DesktopHTMLViewer that it works with html files on my hard disk. The app is sandboxed as for the MAS.

Here is my code in a button:

```auto
Var f As FolderItem

f = FolderItem.ShowOpenFileDialog("text/html")
If f <> Nil Then
  HTMLViewer1.LoadPage(f)
Else
  MessageBox("Open failed.")
End If

```

---

<div class="post-metadata">

**Author:** ![Patrice\_C](https://forum.xojo.com/user_avatar/forum.xojo.com/patrice_c/32/14346_2.png) [@Patrice\_C](https://forum.xojo.com/u/Patrice_C)\
**Post date:** [November 26, 2022, 3:58pm UTC](https://forum.xojo.com/t/sandbox-local-pages-and-desktophtmlviewer/73361/4 "2022-11-26T15:58:34Z")

</div>

The code works when you load a page but if you save the file path and read it from a prefs, the content is not loaded. I’m tried all solutions like adding file:/// . Blank page.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [November 26, 2022, 4:24pm UTC](https://forum.xojo.com/t/sandbox-local-pages-and-desktophtmlviewer/73361/5 "2022-11-26T16:24:55Z")

</div>

If you always load from Resources, for instance, you can simply save the name of the file instead of the url.

If the path changes, perhaps you can do something like:

```auto
var f as folderitem
f = new folderitem(path, folderitem.native)
HTMLViewer1.LoadPage(f)

```

---

<div class="post-metadata">

**Author:** ![Ivan\_Tellez](https://forum.xojo.com/letter_avatar_proxy/v4/letter/i/a9a28c/32.png) [@Ivan\_Tellez](https://forum.xojo.com/u/Ivan_Tellez)\
**Post date:** [November 26, 2022, 6:14pm UTC](https://forum.xojo.com/t/sandbox-local-pages-and-desktophtmlviewer/73361/6 "2022-11-26T18:14:51Z")

</div>

> [@Patrice\_C](#):
>
> This code seems to fix it for old versions of Xojo

If the new release is not working, and they broke the workaround, see if you can aply for the 90-day money back guarantee. it is not fair to waste money in something that is not working. See if you can use the old HTMLViewer

---

<div class="post-metadata">

**Author:** ![Emily-Elizabeth\_Howard](https://forum.xojo.com/user_avatar/forum.xojo.com/emily-elizabeth_howard/32/14415_2.png) [@Emily-Elizabeth\_Howard](https://forum.xojo.com/u/Emily-Elizabeth_Howard)\
**Post date:** [November 26, 2022, 7:13pm UTC](https://forum.xojo.com/t/sandbox-local-pages-and-desktophtmlviewer/73361/7 "2022-11-26T19:13:11Z")

</div>

This is the code I use for the DesktopHTMLViewer. Just tested in 2022r3.2 and it worked.

```auto
Private Sub GrantAccessToFolder(inFolder as FolderItem)
  #if (TargetMacOS) AND (XojoVersion >= 2020.01) then
    // copied from https://forum.xojo.com/t/new-problem-with-htmlviewer-loadpage-since-version-2020-r1/56514/7
    // --- Originally created in July 2020. <--- Leave this info here so it's easier to track which version of the code.
    // Published Sep 1st 2020.
    // written by Sam Rowlands of Ohanaware.com
    // Apple documentation for this API: https://developer.apple.com/documentation/webkit/wkwebview/1414973-loadfileurl?language=objc
    
    Declare Function NSClassFromString Lib "Foundation" (inClassName As CFStringRef) As Integer
    Declare Function NSURLfileURLWithPathIsDirectory Lib "Foundation" Selector "fileURLWithPath:isDirectory:" (NSURLClass As Integer, path As CFStringRef, directory As Boolean) As Integer
    Declare Function WKWebViewloadFileURL Lib "WebKit" Selector "loadFileURL:allowingReadAccessToURL:" (HTMLViewer As Ptr, URL As Integer, readAccessURL As Integer) As Integer
    
    // --- Create a NSURL object from a Xojo Folderitem.
    DIM folderURL As Integer = NSURLfileURLWithPathIsDirectory(NSClassFromString("NSURL"), inFolder.NativePath, inFolder.IsFolder)
    
    // --- This bit is not technically correct. The first parameter after the instance should actually be the page that you're trying to load.
    // But as we're not loading a page per say... For the purpose of just setting access rights, we ignore the return
    // value as we don't need to display progress.
    Call WKWebViewloadFileURL(me.Handle, folderURL, folderURL)
  #EndIf
End Sub

```

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [November 26, 2022, 7:16pm UTC](https://forum.xojo.com/t/sandbox-local-pages-and-desktophtmlviewer/73361/8 "2022-11-26T19:16:53Z")

</div>

If you use MBS Xojo Plugins, you can go from a [DesktopHTMLViewer](https://www.monkeybreadsoftware.net/class-desktophtmlviewer.shtml) to a **[WKWebViewMBS](https://www.monkeybreadsoftware.net/class-wkwebviewmbs.shtml)**.

And this allows you to use LoadFileURL function:  
[LoadFileURL](https://www.monkeybreadsoftware.net/webkit2-wkwebviewmbs-method.shtml#14)(File as FolderItem, readAccessItem as FolderItem)
