JavaScript Document is not defined, WebStorm IDE - javascript

I started up learning some basic HTML, CSS and JS and reached the point where I should be able to connect them. But when I'm trying to access the document object it just says that the document is not defined
I've tried changing the IDE, done some research on the internet and I found that it might be NodeJS, since it's more server based and not browser based, but even so how can I fix this ?

You need to open the html document directly in the browser and not run it via Webstorm, cause Webstrom thinks you are writing node and in node document is not defined.
Here's a link to the JetBrains Docs for information on how to debug vanilla js code: Docs

Related

Trying to run hello world JavaScript program on visual studio but keep getting 'document' is undefined

I've watched videos and when people run this it works just fine. I also tried console.log and I get-- 'console' undefined. I have node.js installed
document is not a built-in part of JavaScript. It is part of the Web API provided by browsers which you get when you load your JS by using a <script> element in an HTML document in a web browser. You aren't doing that, and document doesn't have a log method anyway.
You're running your JS using Windows Script Host, which isn't that. WSH does not have a document.
You probably want either:
the WriteLine method
to not use WSH (Browsers and Node.js being more common ways to run JS)
You aren't running in a browser, there is no document (plus, it'd be console.log there too). You are running in Windows Script Host, you can use WScript.Echo instead. But I'd rather recommend you to run your code in a browser or node.js anyway, WSH isn't a very useful environment for learning modern JavaScript.
You wrote you have node.js installed, so the issue could be that you simply used the wrong command: it should be node and not start!

How to inject JS into an application using Chromium Embedded Framework

I am attempting to inject a piece of JavaScript into a Mac application using Chromium Embedded Framework internally. I have tried using the command line options mentioned in the CEF documentation (load-extension), but I have not much success at getting any JavaScript running.
Is --load-extension supposed to load any browser extension when used with a CEF build? Or are there other things that need to be present for this to work? Are there limitations to what can be loaded here? I have yet to find a good example of using --load-extension in the wild.

Is there any way to inject code into a website via vscode

I found this question in stackoverflow, which is a bit similar but did not help me.
I would like to find some extension/plugin for vscode that would inject a JS and CSS code into a given URL.
For example, after setting a url in vscode, I create a js and when saving the file this script is injected into google chrome in the url mapped or in the tab that is open in chrome.
There is an extension to chrome that does just that: User JavaScript and CSS
This is non-trivial but definitely possible.
I sadly cannot provide you with all the necessary information as I am not sufficiently familiar with the way VSCode extensions function.
First of all, there is this project which you should take a look at. It's source code will have useful information.
Alternatively, and my personal recommendation, you should go with abusing the remote debugger which chrome provides. This project is a good example of how it can be used. It connects to the chrome remote debugger and exposes a REPL.
There is readily available documentation on how to use the remote debugger to execute arbitrary javascript.
The next part will be to make an actual extension which takes the above, ties it together and listens to a "on file save" event or something of the sort.

Is it possible to attach a debugger to k6 scripts?

I'm hoping to adopt k6 for load testing, but I'm having trouble developing scripts for it. My primary use case is to check at each request to see if I'm receiving the correct headers and content and would like to inspect the response with a debugger.
I tried to run the script on its own by attaching the node inspect debugger (https://nodejs.org/api/debugger.html) but the file doesn't get executed because the import and export module keywords are unrecognized by this current version of node (8.7.0)
I'm also unable to find any documentation on how to debug these scripts.
There is no debugger support (currently known) for k6 scripting. It's manual debugging at this time.
k6 runs javascript (ECMA6) and has an API documented at http://k6.io
Sidenote: k6 is not node and will not work with node tooling.
I recently opened an issue about this - the need for a "debug" mode where detailed information about requests is printed to stdout.
https://github.com/loadimpact/k6/issues/331
To be clear, this issue is not about creating a "real" debugger, like gdb or similar, where you can step through script code, but rather a special mode of operation where lots of HTTP request information is being output to stdout in real time, to facilitate understanding exactly what is happening between client and server when your script code is executed.
I will probably try to implement something like this as soon as Emily (the maintainer) merges in some major CLI changes she is working on right now.

Compile Error in JavaScript: "libraryVar is not defined"

I am new to JavaScript (coming from c++) and asking myself whether it is possible to compile and debug JavaScript code. I tried to use VisualStudio2012 and SublimeText2 with Node.js, but in both cases, I got a compile error when I tryed to use a library (3djs).
In SublimeText2 the error message is "ReferenceError: d3 is not defined".
I got that error trying to compile this d3js example: http://bl.ocks.org/mbostock/3828981
Strangely the example worked perfectly when I opened it in some browsers..
Can anyone tell me what I am doing wrong or whether it is even possible to compile or debug JavaScript code?
(Sorry, this seems to be a very beginner question but I did not find the answer searching for some hours...)
Best regards!
node.js also doesn't compile the JavaScript (not in the C++ sense; JavaScript interpreters often Just-in-Time compilation). The main difference between node.js and a browser is that node.js doesn't try to hide errors from you.
So the first question is whether you correctly included the library in your project. For this, we need to see the source code that you use to load / import it.
If you're sure that the library has loaded correctly, then you might be triggering a bug in the JavaScript interpreter. Try to install the latest version or the lastest stable version or the version before that.
[EDIT] In HTML, you use a <script> element to include scripts in the context of the page. When using node.js, then you have to use require():
var d3 = require('./d3.js')
That said, D3.js is a client framework. It expects the standard browser environment like a DOM. It will not work inside of node.js. node.js expects modules (= stuff that you can import using require) to have a certain format.
So the simple answer is: You can't "compile" and debug JavaScript code in your IDE. You always need to create a HTML page and open that in a browser. All modern browsers have consoles, plus tools to debug and examine JavaScript, CSS, HTML and the DOM.

Categories