question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A call from CEF to js_api to a Python standard json library's dumps() returns a promise, but the resolved promise returns an object and not a string

See original GitHub issue

Specification

  • pywebview version: I don’t know where to find the version. There’s no readme in the webview folder. Folder was created on 5th of june 2019.

  • platform / version: Windows 7, 32-bit

Description

A call from CEF to js_api to a Python standard json library’s dump() returns a promise, but the resolved promise returns an object and not a string

Here is the Javascript:

   function json_stringify(object, loaded_handler){
       promise1 = window.pywebview.api.json_stringify(object)
       promise1.then((value) => {
           console.log("type " + typeof(value))
           loaded_handler(value)
       })
   }
   
   setTimeout(function(){
       json_stringify({}, console.log)
   }, 3000)

The Python:

class python_interpreter_api:
    def json_stringify(self, obj):
        return str(json.dumps(obj))
        
python_interpreter_api = python_interpreter_api()

Side question: is there a way to make the js_api run Python functions synchronously? So that the javascript is halted, python is run, then javascript continues?

Note: I even added str() to json.dumps (which should be redundant) but that doesn’t work either.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
darthglowballcommented, Jul 26, 2019

Hahaha @r0x0r you had me on the edge of walking away mad; me screaming: “let the bugs be set free!!11” or me posting a mathematical logical proof of the problem with svg flow chart diagrams in the hopes that it would become clear. ^-^

0reactions
r0x0rcommented, Aug 17, 2019

Fix is deployed to 3.0.2

Read more comments on GitHub >

github_iconTop Results From Across the Web

Promise resolved but returns part of data - rest 'undefined'
Finally got it. It was problem with the schema which I have not adjusted (one schema was used for uploading data to MongoDB,...
Read more >
Resolving the JavaScript Promise Error "TypeError: Cannot ...
This function is expected to return a Promise that should resolve to JSON data. The getGithubOrgs() function is then called with an argument ......
Read more >
Promise API - The Modern JavaScript Tutorial
Promise.all takes an iterable (usually, an array of promises) and returns a new promise. The new promise resolves when all listed promises ......
Read more >
JavaScript Promises: an introduction - web.dev
Promises simplify deferred and asynchronous computations. A promise represents an operation that hasn't completed yet.
Read more >
You Must Know Python JSON Dumps, But Maybe Not All ...
We know that we can use the json.dumps() method to easily convert a Python dictionary object into a JSON string. However, this method...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found