Replies: 2 comments 4 replies
-
|
Further solutions & discussions: https://stackoverflow.com/questions/24027589/how-to-convert-raw-javascript-object-to-a-dictionary |
Beta Was this translation helpful? Give feedback.
-
|
Since I'm of the author of d07c006 here some context. An additional cons about chompjs: it is maintained by one person and parse external data using C. The tests might be enough or it, the code enough simple, but I'm afraid of a buffer overflow. curl, lxml are also written in C, but there are far more contributors and eyes on the code. I wrote js_variable_to_python for the google image engine one or two years ago, but actually the engine never used it. As far I understand, parse_js_object_naive does not parse escape sequence. It will break as soon a title or content contains double quotes. The function from yt-dlp has a I'm currently adding the tests from chompjs to check the function js_variable_to_python to investigate. I'm not saying we should continue to use this function, my stance is to keep this function has long only one engine need it and it does not break too often which might happen, yes as you are saying. So, it is good thing to look for alternatives. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
So last week we switched from chompjs to pure python code in d07c006. I do think it's an improvement to get rid of a dependency, especially when it is only used by a single engine.
However, it already broke, so brave.news and brave.videos weren't working, which I fixed in #2784. After having a look at the function
js_variable_to_python, I noticed it is also 5x slower than chompjs, taking around 10ms on a normal brave page, which is not bad but can definitely add up and become noticeable, especially on weaker hardware. I'm also concerned that it can come with a bigger maintenance cost than using chompjs.Here are some other solutions:
chompjs
Pros:
js_variable_to_pythonCons:
Function from yt-dlp
Pros:
Cons:
js_variable_to_pythonMy naive implementation
I rewrote
js_variable_to_pythonto be even more bare-bones, just as an example. This works exactly the same for parsing brave responses.Pros:
js_variable_to_pythonCons:
js_variable_to_pythonTesting
Beta Was this translation helpful? Give feedback.
All reactions