6 Replies Latest reply on Aug 2, 2018 10:18 PM by williamr97361347

    [Q] CSInterface.evalScript() reports "EvalScript error."

    Naoki-Hada Level 1

      Hi all,

       

      I'm not sure where is the problem and still in troubleshooting.

      I wonder if anyone has workaround or any idea where I should check.

       

      ExtendScript itself is working as expected. But when it is called from CEP's CSInterface.evalScript(), it causes "EvalScript error."

       

      ExtendScript code is modified code from following.

      Change value sample size

       

      Changing Eyedropper's tools property value from CEP plugin.

      In the project there's similar code used, but only these part has issue.

       

      The above link's code's JSON has syntax issue. ExtendScript is OK. But JSONLint reported error. After fix, it still have issue.

       

      I rewrote to ActionDescriptor without JSON data, it still have same issue (JSX is OK. CEP has issue.)

       

      I appreciate any tips and advice.

       

      Thank you,

      Naoki

       

      [Moved to Extensions/Add-ons Development forum by Mod]

        • 1. Re: [Q] CSInterface.evalScript() reports "EvalScript error."
          Ten A Adobe Community Professional

          I try to wrap all code in IIFE and call from my code editor extension. It's work fine in CC2018.

          1 person found this helpful
          • 2. Re: [Q] CSInterface.evalScript() reports "EvalScript error."
            Naoki-Hada Level 1

            Hi Ten A

             

            Thank you very much for tips.

             

            This posting was only Photoshop issue and posted on Photoshop Scripting forum.

             

            The current framework (CEP + ExtendScript) was working fine for supporting multiple apps until added Photoshop's particular functionalities (RedEye and Eyedropper tool support).

             

            The CEP framework is similar to following sample code.

            CEP-Resources/CEP_7.x/Samples/CEP_HTML_Invisible_Extension-7.0 at master · Adobe-CEP/CEP-Resources · GitHub

             

            At beginging of CEP's JavaScript, it is loading JSX as following.

             

            csInterface.evalScript('$.evalFile("' + fullpath_fileName + '")');
            
            

             

            At execution place was just using evalScript.

             

                csInterface.evalScript('jsx_func_in_jsx_file(' + passing_param + ')', function(response) {
                    // handing response
                });
            

             

            Other part of JSX functions are still working fine, but above new Photoshop function are not working and causing "EvalScript error".

            The JSX function are working fine with ExtendScript.

             

            So my question for this forum would be is there any way to get more detail info from CsInterface.evalScript() on "EvalScript error" case?

            Of is it really blackbox?

             

            Thank you,

            Naoki

            • 3. Re: [Q] CSInterface.evalScript() reports "EvalScript error."
              Trevorׅ Adobe Community Professional

              I do this with my JSX.js A Game Changer in Adobe HTML Extensions Development? | Creative-Scripts.com

              See around line 438, the basic idea is to wrap the script with a try {} catch(e){} returning the e info you want.

              You can see how this is used in my CSTK search for it there.

              2 people found this helpful
              • 4. Re: [Q] CSInterface.evalScript() reports "EvalScript error."
                sberic Level 3

                Naoki-Hada  wrote

                 

                So my question for this forum would be is there any way to get more detail info from CsInterface.evalScript() on "EvalScript error" case?

                Of is it really blackbox?

                Yes, it really is a blackbox.

                 

                The code you show above might actually not be harmless. Are you perchance sending Windows-formatted file paths? Do they use the "\" character instead of "/" (e.g. "C:\Users\joe\Documents\")? If so, those slashes become escape characters in the string you pass to evalScript.

                 

                You will very likely want to do what is suggested here and use the string replace method to format your content for evalScript. We do this with a handy helper function:

                 

                /**
                 * Prepares a string to cross the HTML/App boundary, escaping
                 *  characters as necessary. Specifically:
                 *      Replaces:
                 *          \ with \\
                 *          ' with \'
                 *          " with \"
                 * @param str The JSX string to prepare.
                 */
                function EscapeStringForJSX(str)
                {
                    // Replaces:
                    //  \ with \\
                    //  ' with \'
                    //  " with \"
                    // See: https://stackoverflow.com/a/3967927/5285364
                    return str.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/"/g, '\\"');
                }
                

                 

                In your case, it would be used like this:

                 

                csInterface.evalScript(`jsx_func_in_jsx_file( ${ EscapeStringForJSX(passing_param) } )`, function(response) {  
                        // handing response  
                    });
                

                 

                You'll note that I've also replaced your usage of quotes with ticks (`) to leverage Template Literal string syntax (should be supported in CEP 6.1+).

                 

                In short, you need to be really careful when preparing a string to send to ExtendScript via evalScript from CEP.

                 

                Hope this helps!

                1 person found this helpful
                • 5. Re: [Q] CSInterface.evalScript() reports "EvalScript error."
                  Naoki-Hada Level 1

                  HI Ten A, Trevorׅ sberic

                   

                  Thank you very much for your help and tips.

                   

                  The my issue was solved some time ago.

                  It is shame to report it was my mistake that I was testing against wrong target.

                  Some unexpected file got mixed in both dev env and testing machine from different source.

                   

                  I wished evalScript() report better message.

                  But still it is convenient and we relay on.

                   

                  Thank you very much again,

                  Naoki

                  • 6. Re: [Q] CSInterface.evalScript() reports "EvalScript error."
                    williamr97361347 Level 1

                    I am just beginning with Photoshop CEP extension development, and I also ran into the problem of evalScript() not providing any useful error messages or debug information.  The solution I decided on was to try to run the same code in the ExtendScript Toolkit as a standalone script.  For instance, if a particular evalScript call is causing problems, then you can output the exact parameters that you are calling it with in the JS / CEP panel, and then separately run the JSX code using those parameters in ExtendScript.  This way, you get more detailed error messages when the host-side code runs into something that it doesn't understand. 

                     

                    Of course, for particularly complex or dynamic extensions, this may be impractical, but it at least gives you a way to debug some form of your host JSX file.

                    1 person found this helpful