How to force HTMLViewer to use Preview plugin

  1. 3 weeks ago

    Payam A

    Aug 29 Pre-Release Testers, Xojo Pro

    Hi

    My app crashes if Adobe Acrobat Reader DC is installed on Mac, anytime when a htmlviewer is loading a PDF file. This is due to the two adobe internet pdfviewer plugins which are saved in the Internet plugins folder of the Mac. If I delete those plugins, my app works fine.

    How can I force the HTMLViewer not to use the Adobe plugins for the HTMLViewer on Mac?

    Thanks.

  2. Alain C

    Aug 29 Pre-Release Testers, Xojo Pro Switzerland

    Indeed, Apple has removed support for NPAPI plugins (which are used by Adobe) with the latest macOS update. The plugins remain installed and crash if it is used as well as your app.
    I do not know if it is possible to force the use of 'Preview' in an HTMLViewer, but you can check with a javascript if Adobe plugins are installed to avoid loading a PDF.

    Load this page in the HTMLViewer and check the 'StatusChanged' for InStr(newStatus,"navigator.plugins:Adobe Acrobat")>0

    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script language="JavaScript">
        for (var i = 0; i<navigator.plugins.length; i++) 
                {   
                      var n = navigator.plugins[i].name;                              
    		    status="navigator.plugins:"+n;
                }
    </script>
    </head>
    </html>
  3. Christian S

    Aug 30 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

    Just a few days I blogged about it: Adobe PDFViewer crashes in FileMaker

    So maybe in Xojo, you can also just throw it to the trash.

  4. Christian S

    Aug 30 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

    or did you check WebPreferencesMBS in MBS Xojo Plugins and set arePlugInsEnabled to false?

  5. Payam A

    Aug 30 Pre-Release Testers, Xojo Pro

    Hi @Alain C
    In which event handler do I have to load that HTML code? And what are the instructions that follow if the INSTR is not 0?

  6. Emile S

    Aug 30 Europe (France, Strasbourg)

    @Payam A event handler

    I suppose StatusChanged Event…

    @Payam A if the INSTR is not 0

    Then all is OK (I suppose too).

  7. Alain C

    Aug 30 Pre-Release Testers, Xojo Pro Switzerland

    You can do this test when opening the HTMLViewer (or window) and save the result (Adobe installed YES/NO) in a global variable.
    The code listed above lists all plugins installed via the 'StatusChanged' event of the HTMLViewer. You can also directly modify the javascript to indicate only the status for Adobe.
    In the following example the value of 'newStatus' contains either "Adobe.plugins:Not found" if the plugins are not detected, or "Adobe.plugins: Installed" if they are installed.

    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script language="JavaScript">
        var r = "Not found";
        for (var i = 0; i<navigator.plugins.length; i++) 
                {   
                    var n = navigator.plugins[i].filename;    
    		if (n.includes("AdobePDFViewer")) {
      		 r = "Installed";
    		}                          
                }
    status="Adobe.plugins:"+r;
    </script>
    </head>
    </html>

    Depending on the result you can open PDFs in HTMLViewer or indicate the procedure to remove Adobe plugins ...

  8. Payam A

    Aug 31 Pre-Release Testers, Xojo Pro
    Edited 3 weeks ago

    I did something like this:

    If Volume(0).Child("Library").Child("Internet Plug-Ins").Child("AdobePDFViewer.plugin").Exists _
            Or Volume(0).Child("Library").Child("Internet Plug-Ins").Child("AdobePDFViewerNPAPI.plugin").Exists Then
    adobeDelete
    End If

    adobeDelete is an Applescript which is this:

    set libraryFolder to path to library folder
    tell application "Finder"
    delete (every item of folder "Internet Plug-Ins" of libraryFolder whose name starts with "AdobePDFViewer")
    end tell

  9. Beatrix W

    Aug 31 Pre-Release Testers, Third Party Store Europe (Germany)

    Instead of Volume(0).Child("Library") use SpecialFolder.Library.

    If need to check for every child if the folder isn't nil and exists.

    Don't use an AppleScript except if you really have to because of the wonderful permissions in Mojave.

  10. Payam A

    Aug 31 Pre-Release Testers, Xojo Pro

    @Beatrix W The only way I found is to tell Finder to delete those files, because it does not go without prompting for password. That's why I used AppleScript. Now if, as you say about Mojave, the user does not give his permission, then it won't work. In that case I execute a shell command: "tccutil reset AppleEvents" on Mojave and "tccutil reset AppleEvents (bundle name of app)" on Catalina. This causes that the user will be asked again for permission when he starts my app.

  11. Sam R

    Sep 1 Pre-Release Testers, Xojo Pro, Third Party Store Hengchun, Pingtung, Taiwan
    Edited 3 weeks ago

    @Beatrix W Instead of Volume(0).Child("Library") use SpecialFolder.Library.

    Agree with Beatrix here, Catalina changes some system paths, so hard coded ones are likely to fail.

    There are other ways to delete files with permission and not using Apple Script; some Googling should help you find them.

    You should also sign on to this feature request; as it's asking Xojo to update the HTMLViewer to the newer replacement. Feedback Case #52330

  12. Jürg O

    Sep 1 Pre-Release Testers, Xojo Pro

    I can‘t test right now, but regarding permission and no AppleScript: would that work, too?
    @Payam A : please don‘t tccutil reset AppleEvents for all applications... I wouldn‘t like that if an app does that without asking.

  13. Payam A

    Sep 1 Pre-Release Testers, Xojo Pro

    @Jürg O ok I will remove that for Mojave.

  14. 2 weeks ago

    Greg O

    Sep 2 Xojo Inc

    @Payam A In that case I execute a shell command: "tccutil reset AppleEvents" on Mojave and "tccutil reset AppleEvents (bundle name of app)" on Catalina.

    From what I can see, this command requires the user to be an administrator and since it’s in the security & privacy category, will probably require a password to actually work. Have you checked the exit code on a non-dev machine?

  15. Payam A

    Sep 2 Pre-Release Testers, Xojo Pro

    Hi
    I don't know what you mean by exit code. I tried the tccutil on two computers and it didn't require any password, and on the Privacy tab, the Automation list was empty after I executed that command on Mojave, and on Catalina, since I specified the bundle name, it only deleted my app from the Automation list. Of course, if you are no administrator, then you always need to enter the password for anything of this sort, even as you need to do that when you simply want to install something.

or Sign Up to reply!