Skip to content
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 I emulate Chrome DevTools console with the JS REPL buffer? #260

Open
tmurph opened this issue Feb 19, 2021 · 2 comments
Open

Can I emulate Chrome DevTools console with the JS REPL buffer? #260

tmurph opened this issue Feb 19, 2021 · 2 comments

Comments

@tmurph
Copy link
Contributor

tmurph commented Feb 19, 2021

For context, I'm new to Node and I'm learning by making a simple repl-style app, using Node's repl library. It's just a repl with one predefined variable. Here's the entire app.js:

// app.js
const repl = require('repl');

const r = repl.start('repl> ');
r.context.hello = 'Hello World!';

When I start the app (with --inspect) and connect through Chrome DevTools, the devtools console knows about the repl context variable. I can evaluate hello and see "Hello World!" come back.

When I indium-launch the app, the JS REPL buffer doesn't know about the repl context variable. When I evaluate hello I get a reference error.

I can roughly follow indium's execution path, so I can see why this is happening (evaluation happens in the node server's global context, not in the app's repl context). I just can't figure out if there's a way to tweak the JS REPL setup so that it better emulates Chrome's console behavior.

Has anybody got this working?

@tmurph tmurph changed the title Can I better emulate Chrome DevTools console through the JS REPL buffer? Can I emulate Chrome DevTools console through the JS REPL buffer? Feb 19, 2021
@tmurph tmurph changed the title Can I emulate Chrome DevTools console through the JS REPL buffer? Can I emulate Chrome DevTools console with the JS REPL buffer? Feb 19, 2021
@NicolasPetton
Copy link
Owner

I never tried to do anything like that. I'm wondering how this actually works, have you tried inspecting the Chrome devtools to see how the console handles the context?

CDP's Runtime.evaluate can take an optional contextId parameter, but I'm wondering how would Indium know about the context id.

@NicolasPetton
Copy link
Owner

I guess a Runtime.executionContextCreated event must be fired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants