• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Contributor ,
Jun 26, 2018 Jun 26, 2018

Copy link to clipboard

Copied

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]

Views

5.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 29, 2018 Jun 29, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 02, 2018 Jul 02, 2018

Copy link to clipboard

Copied

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 ·...

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jul 11, 2018 Jul 11, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 31, 2018 Jul 31, 2018

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 01, 2018 Aug 01, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 02, 2018 Aug 02, 2018

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines