-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can it support Inspector protocol? #63
Comments
Hey, interesting idea! The v8 inspector protocol is pretty extensive! I wonder if you could describe what kinds of things you want to do with it? (E.g., print values, change values, pause execution, profile memory, ...) Also, what kind of interface were you thinking of (E.g., just expose a JSON sendInspectorMessage and onInspectorMessage, or something more user-friendly?) It might be noteworthy that as of PyMiniRacer $ python
>>> from py_mini_racer import MiniRacer
>>> ctx = MiniRacer()
>>> async def log(s):
... print(s)
...
>>> async def run_my_code():
... async with ctx.wrap_py_function(log) as log_js:
... ctx.eval('this')['log'] = log_js
... ctx.eval('for (let i = 0; i < 10; i++) { log(i); }')
...
>>> import asyncio
>>> asyncio.run(run_my_code())
0
1
2
3
4
5
... |
I'm very sorry that I'm replying to your message just now. What I hope is that I can debug the js code with the help of Chrome's DevTools, and I can pause the program where needed, similar to Pycharm's debugging mode. I describe it like this, I don't know if it is clear. This feature is great for developers, and I hope you can adopt this suggestion. |
@bpcreech I have looked at your example and have the problem that the wrapped function is not called immediately but only when the async contextmanager exits: $ python
>>> from py_mini_racer import MiniRacer
>>> ctx = MiniRacer()
>>> async def log(s):
... print(s)
...
>>> async def run_my_code():
... async with ctx.wrap_py_function(log) as log_js:
... ctx.eval('this')['log'] = log_js
... print('before loop')
... ctx.eval('for (let i = 0; i < 10; i++) { log(i); }')
... print('after loop')
... print('after async with')
...
>>> import asyncio
>>> asyncio.run(run_my_code())
before loop
after loop
0
1
2
...
9
after async with The expectation would be that |
Ah, hmm, I think that's either a bug or expectation gap in the code. Because the JS code doesn't If we wanted more deterministic logging we'd need to do something like: import asyncio
from py_mini_racer import MiniRacer
ctx = MiniRacer()
async def log(s):
print(s)
async def run_my_code():
async with ctx.wrap_py_function(log) as log_js:
ctx.eval('this')['log'] = log_js
print('before loop')
await ctx.eval('Promise.all(Array(10).keys().map(i => log(i)))')
print('after loop')
print('after async with')
asyncio.run(run_my_code()) |
Not sure if |
The sequence isn't relevant in this example since the values are ignored. The purpose here is simply to ensure the function is completed. You are right that this is not a drop-in replacement for console.log. it is, however, a functioning way to get logs! The trouble with a sync wrap_py_function is that it would very quickly deadlock when the wrapped function attempted to call back into v8 for anything including even unpacking an object or array. |
The reason I came here was, because I was trying to intercept |
Neat use case! You are sort of building a headless web browser. :) So we want to serialize operations here while avoiding the world of multithreaded recursion... IIUC we want our Python outer loop (which is running BeautifulSoup) to ensure any calls to |
I want to debug when python executes js code. I checked some documents of V8, but I am not familiar with C++ and cannot implement this function myself. So, I would like to ask if this feature can be added in subsequent updates.
The text was updated successfully, but these errors were encountered: