idea plugin jbCefJSQuery return undefined

已回答

I am developing idea plugin which embeds jcef browser, i use jbCefJSQuery to call plugin from browser, but browser get undefined response, why? btw i'm certain that plugin side received the callIde call

plugin code :

this.jbCefBrowser.getCefBrowser().executeJavaScript(
"window.callIde = function(requestStr) {" + jbCefJSQuery.inject("requestStr") + "};", this.jbCefBrowser.getCefBrowser().getURL(), 0);
                
jbCefJSQuery.addHandler((requestStr)->{return new JBCefJSQuery.Response("xxx");});

js code expect xxx response, but get undefined:

console.log(window.callIde("aaa"));



 

0

It's an example of an actual request from JS side that contains the callbacks for the response:

window.cefQuery({
  request: 'request',
  onSuccess: function(response) {
    console.log(response);
  },
  onFailure: function(error_code, error_message) {
    console.log(error_message);
  }
);

 JBCefJSQuery is some sort of a wrapper for this functionality. And its inject method basically constructs the text of such call. It does the substitution of  cefQueryname, request, onSuccess and onFailure values.
To consume the response on JS side another version of JBCefJSQuery#inject has to be used.

 public @NotNull String inject(@Nullable String queryResult) {
    return inject(queryResult, "function(response) {}", "function(error_code, error_message) {}");
  }
0

请先登录再写评论。