sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    Working around "location=", for debugging

    Scheduled Pinned Locked Moved Developers' Forum
    16 Posts 5 Posters 1.0k 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.
    • RichMorinR Offline
      RichMorin
      last edited by

      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
      • thomthomT Offline
        thomthom
        last edited by

        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
        • RichMorinR Offline
          RichMorin
          last edited by

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

          1 Reply Last reply Reply Quote 0
          • RichMorinR Offline
            RichMorin
            last edited by

            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
            • thomthomT Offline
              thomthom
              last edited by

              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
              • RichMorinR Offline
                RichMorin
                last edited by

                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

                  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
                  • thomthomT Offline
                    thomthom
                    last edited by

                    @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
                    • AdamBA Offline
                      AdamB
                      last edited by

                      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
                      • RichMorinR Offline
                        RichMorin
                        last edited by

                        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
                        • RichMorinR Offline
                          RichMorin
                          last edited by

                          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
                          • Dan RathbunD Offline
                            Dan Rathbun
                            last edited by

                            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
                            • thomthomT Offline
                              thomthom
                              last edited by

                              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
                              • RichMorinR Offline
                                RichMorin
                                last edited by

                                @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
                                • First post
                                  Last post
                                Buy SketchPlus
                                Buy SUbD
                                Buy WrapR
                                Buy eBook
                                Buy Modelur
                                Buy Vertex Tools
                                Buy SketchCuisine
                                Buy FormFonts

                                Advertisement