What I want
I want to be able to run a whole script in node during debugging with node-inspector and Web Inspector. - I don't want to step through the individual JavaScript calls.
What I did
(My PowerShell Instructions)
PS C:\Users\JK> node-inspector
info - socket.io started
visit http://0.0.0.0:8080/debug?port=5858 to start debugging
...
==[In another PowerShell instance:]==
PS %> node —debug-brk myscript.js
debugger listening on port 5858
Why I want that
I'm writing a node script. In this script I console.log a lot of objects in order to be able to explore them during the debugging process. But the simple static textual console output isn't really nice - You can't fold and expand your object's properties or get the source code of a function:
(For Example)
{ [Function: Xy]
a: [Function],
b: 8.2,
c: [Function],
d: [Circular],
e: '2011-11-11' }
So I decided to use Web Inspector with node-inspector in order to get a good object browse experience (because of Web Inspector's nice output formatting).
Why I Don't Step Through
(Structure of My Script)
var fs = require('fs');
fs.readFile('myfile', function (err, data) {
if (err) {
throw err;
}
//My Script...
console.log(something);
});
The console.log() calls are executed in a callback function of
require('fs').readFile(). I won't get there just with "normal"
steps.
It's simply boring the click the Step buttons again and again.
My Questions
Is there a possibility to run a script without stepping through using the following Web Inspector user interface? (I don't want to use node —debug myscript.js instead of node —debug-brk myscript.js because then Inspector throws Error: connect ECONNREFUSED
Is node running with --debug port 5858? because the script runs too fast)
(Web Inspector Interface)
Or is there at least any other way to do what I described above (in the Why I want that section).
Thanks. -
(I hope it's clear what I wanted to ask. - Please write a comment if it isn't.)
You have a couple options.
Using --debug-brk:
Start your script, let it stop on the first line.
In the Script pane, click the line number inside the callback (line
4 in this
example).
Click "Continue" (the "|> icon above the right-hand panel).
Using --debug:
Add the line debugger; to your callback. This will stop the
debugger at that point. Click "|>" when you're done.
Related
I'm new to cypress and love the way it is architected. However, I seem to have run into a problem early on for a very simple thing that I'm trying to do.
My workflow is:
1) Visit the site
2) Enter username and password
3) On the next screen, type a number and press submit,
4) On the next screen, select a value from a dropdown and press enter.
5) I get to the landing page of my website.
Cypress works totally fine till step 4). It seems to stall at step 5. The test runner suddenly stalls and without warning or error, shows
"Whoops, there is no test to run."
From here, when I click the "View All Tests" button, it takes me to the runner tool. There I see the indication that something is still running in the background. I tried waiting for more than 10 minutes but nothing happens until I click on the "Stop" action.
How do I debug this? Can I see what is happening via any log etc?
There could even be something wrong with my website as well, but without any log information, I'm unable to proceed further. Any help is appreciated.
To provide more context, I don't think this is a timeout based issue as if that were the case, cypress did report to me about this and stopped. I then increased the timeout.
My spec file
describe('My first test', function() {
it('Visits home page', function() {
cy.visit('https://mywebsite.com:5800', {timeout: 400000}, {pageLoadTimeout: 400000}, {defaultCommandTimeout: 400000})
cy.get('#USERNAME').type('myusername')
cy.get('#PASSWORD').type('mypassword')
cy.get('#loginbutton').click()
cy.get('#SOMELEMENT_WHERE_I_TYPE_A_UNIQUE_NUMBER').type('8056')
cy.get('#loginbutton').click()
cy.get('#loginbutton').click()
})
})
Thanks.
If you run DEBUG=cypress:* cypress open from the terminal when initially opening Cypress, there will be more debug log information printed there while you run your tests.
Also, it's always a good idea to search the issues for the project to see if anyone else has had this happen.
For some reason, the Cypress automation gets into a state where it thinks that you have no spec file. All Cypress does to determine this is to see if there is a location.hash defined on the main window -> where it usually says https://localhost:2020/__/#tests/integration/my_spec.js.
Likely this is due to security mechanisms in the app that prevent your application from being run within an iframe (which is how Cypress runs all applications under test). Maybe in your application code it is something like:
if (top !== self) {
top.location.href = self.location.href;
}
You can simply disable these checks while testing or in Cypress you can add to your test file (or a support file to have it work on every test file):
Cypress.on('window:before:load', (win) => {
Object.defineProperty(win, 'self', {
get: () => {
return window.top
}
})
})
I had the same issue. Usually this is related to the page moving out of the parent and can be solved by invoking the attribute and changing it to the current page.
cy.get('.approved-content .no-auto-submit').invoke('attr', 'target', '_self');
Is there any way to access Angular2 specific component specific data in console, for debugging purpose?
Like Angular1 has capability to access its components value in console.
update 4.0.0
StackBlitz example
update RC.1
Plunker example In the browser console on the top-left (filter symbol) select plunkerPreviewTarget (or launch the demo app in its own window) then enter for example
Select a component in the DOM node and execute in the console
ng.probe($0);
or for IE - thanks to Kris Hollenbeck (see comments)
ng.probe(document.getElementById('myComponentId')).componentInstance
Alternative
Hint: enabling debug tools overrides ng.probe()
Enable debug tools like:
import {enableDebugTools} from '#angular/platform-browser';
bootstrap(App, []).then(appRef => enableDebugTools(appRef))
Use above Plunker example and in the console execute for example:
ng.profiler.appRef
ng.profiler.appRef._rootComponents[0].instance
ng.profiler.appRef._rootComponents[0].hostView.internalView
ng.profiler.appRef._rootComponents[0].hostView.internalView.viewChildren[0].viewChildren
I haven't found a way yet to investigate the Bar directive.
A better debug experience is provided by Augury which builds on this API
https://augury.angular.io/
https://www.youtube.com/watch?v=b1YV9vJKXEA
original (beta)
Here is a summary how to do that https://github.com/angular/angular/blob/master/TOOLS_JS.md (dead link and I haven't found a replacement).
Enabling debug tools
By default the debug tools are disabled. You can enable debug tools as follows:
import {enableDebugTools} from 'angular2/platform/browser';
bootstrap(Application).then((appRef) => {
enableDebugTools(appRef);
});
Using debug tools
In the browser open the developer console (Ctrl + Shift + j in Chrome). The top level object is called ng and contains more specific tools inside it.
Example:
ng.profiler.timeChangeDetection();
See also
Angular 2: How enable debugging in angular2 from browser console
First select the element using chrome 'inspect element' and run below method in chrome 'developer console'.
ng.probe($0).componentInstance
You could also use a css selector as shown below.
ng.probe($$('.image-picker')[0]).componentInstance
If you do it often, to make it little easier, have a global shortcut created as below. Now select any DOM element inside the component using 'inspect element' and invoke 'e()' from console
window['e'] = () => eval('ng.probe($0).componentInstance');
Using global scope variable.(any browser)
In ngOnInit() of component file
ngOnInit() {
window['test'] = this;
}
Now we can access instance of that component including services(imported on that component).
If you want to prevent accessing test for let's say production, you can conditionally give access to test like:
constructor(private _configService: ConfigService) {
}
ngOnInit() {
if(_configService.prod) {
window['test'] = this;
}
}
Here _configService means the instance of service used by all components and services.
So variable would be set like:
export class ConfigService {
prod = false;
}
I'm surprised that no one has mentioned Augury here, it's a Chrome plugin that gives you convenient access to all the information in your components, and also makes it easier to see that information in the console directly:
https://augury.rangle.io/
Angular 9+:
Select component root element in developer tools (Inspector), then type in console:
ng.getComponent($0);
I know this sounds crazy... but I really hope to have something like this...
Click on a button in a page, like:
localhost:8080/index
And there is a button in it. When I click that button, it runs a local application. In this case I hope it can get some extra information from the button, like:
<button id="script1.sh">Run</button>
<script>
$("button").click(function(){
var scriptName = $(this).attr("id");
OpenTermninalWithScript(scriptName);
});
</script>
I am using Macintosh / Google Chrome.
as you are on localhost:8080/index I assure you can open it from the backend part (frontend API is not yet evolved to have security permission which allow that in a safe manner)
To do so, your frontend script would create an ajax call to the backend at a specific url you choose asking the backend to proceed. You could start a child process in a terminal (you could do anything you want that is already possible via command line interface (CLI) or just use the default open to simplify
here is a nodejs / express example but it's possible with java, php python and manymore
var spawn = require('child_process').spawn;
var app = require('express')();
app.get('/path/to/trigger/comand', function(req, res){
spawn('open', ['http://google.com']);
res.end('ok');
});
// [...]
open take a ressource to open, you may put here any kind of ressource your OS will open with it's default behaviour
Never mind. The reason this did not work: I forgot to meteor reset so debugger did not get a chance to stop. Duh!
More info: I am using the method in the answer by Mason Chang to the related question, not the kill -s USR1 [proc_id] (where I could see the scripts, but not able to stop in the startup() function.). Also, I am using meteorite.
I am trying to debug the Meteor.startup(function ()) code on Meteor server side (i.e., under /server) with node-inspector, I have read this question, and following the answer to change run.js, but somehow, my own script for the startup function does not show up in the scripts section of Chrome.
How do I see my code here and set break points and stop at those points? BTW, the Meteor_debug() does not output anything to stdout, stderr, or node-inspector browser console. I also tried console.log() with no avail. How to enable logging on Meteor server side?
If it matters, I am on auth branch.
The code here is very simple (/server/bootstrap.js):
Meteor.startup(function () {
if (Logs.find().count() === 0) {
var data = [/*...some data...*/];
var timestamp = (new Date()).getTime();
Meteor._debug("timestamp: "+timestamp+", data.len: " + data.length);
debugger;
for (var i = 0; i < data.length; i++) {
data[i].timestamp = timestamp++;
var entry_id = Logs.insert(data[i]);
Meteor._debug("entry_id: "+ entry_id);
}
}
});
Now that I know how to do this, I will answer my own question so that we can keep this information (in details) here: (This is based on Mason Chang's answer to this question.)
Stop meteor execution.
Edit /usr/lib/meteor/app/meteor/run.js (or the corresponding run.js installed by meteorite in HOME//.meteorite/meteors/meteor/meteor/[LONG_HEX_CODE]/app/meteor):
change the line
[path.join(bundle_path, 'main.js'), '--keepalive']
to
['--debug-brk', path.join(bundle_path, 'main.js'), '--keepalive']
//--debug-brk makes the new thread break at the first line;
Add debugger statements as breakpoints in your server code;
Run node-inspector & in a server terminal. (google "node-inspector" to install it.)
Run meteor; (this will not have the debugger attached as there's no server thread yet, if you have no client window open.)
Refresh client browser window; (to initiate a server thread that will break at the first line, and be attached to node-inspector.)
Open a browser window at [SERVER:8080], your server code stops at first line (main.js in your [PROJECT_DIR]/.meteor/local/build);
Hit the RUN button on the debugger browser window; depending on where your debugger statements are, you may have to do some triggering actions in client browser window to run to the debugger breakpoints. (Note that if you wait too long to hit the RUN button, your client window may time out, and you have to refresh again.)
Now you can do the usual debugging stuff in server debugger window: step through, watch variables, execute in console, look at the stack, etc.
Edit: For logging on server side, you can use either Meteor._debug() and console.log(), they will show up in the terminal where you run meteor. On client side, these logging statements will output to the console of your browser's dev. tools.
On MacOSX, you can use with Chrome :
NODE_OPTIONS="--debug-brk" meteor
and in another terminal
node-inspector --debug-port=5858 --web-port=12345
Then connect Chrome to 127.0.0.1:12345/debug?port=5858
Otherwise with Webstorm, just create a Node.js Remote Debug configuration and run it :
Name : Meteor
Host : 127.0.0.1
Port 5858
Note that once the server has started, you need to press run in order for Meteor to load, and then pause in order to debug from the server console.
what is the best way to write and debug Server Side Action Script on Flash Media Server?
I use Flash Builder for syntax highlighting, but that's all.
I want to debug, make breakpoints and step-trough server application code.
Any ideas?
EDIT1: I know about administration console for viewing trace messages, but that is not real debugging for me.
Although I don't know of an easy way to step through code, there are some cool things you can do.
Since objects in SSAS are dynamic, you can write a custom logging method that dumps variables recursively. I've found this very useful. If you print the method name and dump arguments with each call, this is as good as stepping through code.
Since SSAS is interpreted, you can write a custom admin console that processes eval statements. This is useful when doing live code, or debugging code in a certain state.
Here is a link to the Adobe developers guide:
http://www.adobe.com/livedocs/flashmediaserver/3.0/hpdocs/help.html?content=Book_Part_34_ss_asd_1.html
This includes the developers guide, language reference, some tutorials, etc... Everything you need to get started.
A hello world in server side ActionScript 3 looks like this:
application.onConnect = function( client ) {
client.serverHelloMsg = function( helloStr ) {
return "Hello, " + helloStr + "!";
}
application.acceptConnection( client );
}
AMS (/FMS):
Client.prototype.foo = function (){
return this;
}
Client:
netConn.call('foo', new Responder(_debug, _debug));
And breakpoint over:
function _debug(... rest):void{
}
Is as good as it gets:
we use the client to debug the server
we have to restart the server every time the main.asc file changes
we have to use rsync to upload the file to the remove machine if you can't get a local dev environment (which i couldn't - after a day of futile attempts and this post being 4 years old)
Seriously, it's load of fun, try it!