• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Working around "location=", for debugging

Scheduled Pinned Locked Moved Developers' Forum
16 Posts 5 Posters 735 Views 5 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    RichMorin
    last edited by 29 Oct 2010, 23:09

    I figured out a way around the problem. I define an empty safe_loc function in my JS file, giving the browsers something safe to call. I then redefine it to (after the dialog is launched) from the plugin, making it work under SketchUp.

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 29 Oct 2010, 23:45

      checking the user agent string should let you automate it.

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • R Offline
        RichMorin
        last edited by 30 Oct 2010, 00:47

        No, the user agent strings are identical between the SU WebDialog and Safari.

        1 Reply Last reply Reply Quote 0
        • R Offline
          RichMorin
          last edited by 30 Oct 2010, 05:09

          My "way around the problem", described above, didn't quite work. Problem is, there's no reliable way to send code to the dialog until it has indicated (eg, via location=...) that it's alive. And, of course, the location=... code is what I'm trying to add.

          My current hack, which seems to be working (if ugly), is to write two copies of the HTML file (eg, main.html and DBG_main.html). If I use the latter in the browser, I can test for it, as:

          
          function set_loc(string) {
            var patt = /DBG_/;
            var url  = document.documentURI;
            if (!patt.test(url)) { location = string; }
          }
          
          
          1 Reply Last reply Reply Quote 0
          • T Offline
            thomthom
            last edited by 30 Oct 2010, 07:35

            How about sending a message to the webdialog once it's loaded and set a flag to indicate webdialog or not?

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • R Offline
              RichMorin
              last edited by 30 Oct 2010, 08:43

              As I understand it, there's no reliable way for the plugin code to know when the webdialog has been loaded, except to wait for a "location=..." message. And, if I try to send that message in the browser environment, I crash. So, I seem to have a "chicken and egg" problem. Am I missing something?

              1 Reply Last reply Reply Quote 0
              • J Offline
                Jim
                last edited by 30 Oct 2010, 12:07

                Can't speak about the Mac, but I was able to register the skp: protocol in Firefox on Windows.

                Hi

                1 Reply Last reply Reply Quote 0
                • T Offline
                  thomthom
                  last edited by 30 Oct 2010, 13:32

                  @richmorin said:

                  As I understand it, there's no reliable way for the plugin code to know when the webdialog has been loaded, except to wait for a "location=..." message. And, if I try to send that message in the browser environment, I crash. So, I seem to have a "chicken and egg" problem. Am I missing something?

                  
                  wd.show {
                    wd.execute_script('is_webdialog = true;')
                  }
                  
                  

                  ?

                  Thomas Thomassen — SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 Reply Last reply Reply Quote 0
                  • A Offline
                    AdamB
                    last edited by 30 Oct 2010, 17:28

                    FWIW On Mac, the string from a WebDialog is:

                    Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-us) AppleWebKit/533.18.1 (KHTML, like Gecko)

                    but from Safari its:

                    Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-us) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5

                    So you could detect this.

                    Sure this is been discussed before, but isn't the simplest thing to install a scheme handler that does nothing?

                    Developer of LightUp Click for website

                    1 Reply Last reply Reply Quote 0
                    • R Offline
                      RichMorin
                      last edited by 3 Nov 2010, 16:16

                      Good catch! I had looked at the appVersion strings, but failed to notice the extra goo at the end of the Safari version.

                      I'm not sure what you mean by "isn't the simplest thing to install a scheme handler that does nothing". Could you please give more details?

                      1 Reply Last reply Reply Quote 0
                      • R Offline
                        RichMorin
                        last edited by 3 Nov 2010, 16:52

                        Here is the comment block I put in my code. I think it summarizes what I know about this issue. Comments welcome...

                        
                        # It's a bit tricky to determine whether this
                        # method is running under SU or a web browser.
                        # The first way I found, which is solid but
                        # clunky, is to write a second copy of the HTML
                        # file using a name such as DBG_main.html,
                        # allowing this test to work;
                        #
                        #   document.documentURI.match(/DBG_/) ||
                        #     (location = string);
                        #
                        # Adam Billyard (AdamB on SketchUcation) pointed
                        # out that Safari puts some extra goo at the end
                        # of the appVersion string.  So, here's a less
                        # clunky (but possibly brittle) alternative;
                        #
                        #   navigator.appVersion.match(/533\.18\.5$/) ||
                        #     (location = string);
                        #
                        # Thomas Thomassen (thomthom on SketchUcation),
                        # pointed out that JavaScript code may be reliably
                        # sent from a block attached to the show() or
                        # show_modal() call, as;
                        #
                        #   wd.show_modal do
                        #     wd.execute_script('env_is_webdialog = true;')
                        #   end
                        #
                        # This allows the technique below to be used;
                        #
                        #   env_is_webdialog && (location = string);
                        
                        
                        1 Reply Last reply Reply Quote 0
                        • D Offline
                          Dan Rathbun
                          last edited by 4 Nov 2010, 14:00

                          I was under the impression that the code block of show() and show_modal() did not work on the Mac.
                          Has this been fixed on SU 8.x ??

                          I'm not here much anymore.

                          1 Reply Last reply Reply Quote 0
                          • T Offline
                            thomthom
                            last edited by 4 Nov 2010, 14:04

                            hmm.... you might be right about that... when you mention it I do imagine there was some issues...

                            Thomas Thomassen — SketchUp Monkey & Coding addict
                            List of my plugins and link to the CookieWare fund

                            1 Reply Last reply Reply Quote 0
                            • R Offline
                              RichMorin
                              last edited by 5 Nov 2010, 19:38

                              @dan rathbun said:

                              I was under the impression that the code block of show() and show_modal() did not work on the Mac.
                              Has this been fixed on SU 8.x ??

                              Dunno, in general, but a quick experiment worked for me. Then again, I was only setting a single variable.

                              -r

                              1 Reply Last reply Reply Quote 0
                              • 1 / 1
                              1 / 1
                              • First post
                                12/16
                                Last post
                              Buy SketchPlus
                              Buy SUbD
                              Buy WrapR
                              Buy eBook
                              Buy Modelur
                              Buy Vertex Tools
                              Buy SketchCuisine
                              Buy FormFonts

                              Advertisement