Disable deprecation in javascript console - javascript

I'm using a library from another person but it's probably pretty old and, even though it works just fine, I get a DEP066 deprecation error in my console when I run it.
I'm a COMPLETE noob when talking about javascript so I need your help. Is there a way to disable the deprecation warning/fix it if I use a newer function ?
EDIT:
Thank you so much! It works with the --no-deprecation option.

Try running the the script using the the --no-deprecation parameter which will "silence deprecation warnings":
node --no-deprecation script
Alternatively, --no-warnings will "silence all process warnings (including deprecations)."

Related

Unable to execute karate script() method

I am trying to migrate one of selenium test to karate, while doing this I am using script() method defined in documentation which is used in karate for evaluating the given string as JavaScript within the browser but I am getting this
driver.executeScript("sauce:job-result=passed");
Also Sharing my feature file which getting failed:
Also Even I tried calling below statement in my script but still getting the same error
* script("console.log('hello world')")
I am using testImplementation("com.intuit.karate:karate-core:1.2.0.RC1") version with gatling
First - try version 1.2.0.RC6 that has some fixes for the console.log() issue.
I also must say that sauce:job-result=passed does not look like valid JavaScript to me. Please take some time to read the docs: https://github.com/karatelabs/karate/tree/master/karate-core#karate-vs-the-browser
If still stuck, follow this process. That is the only way to replicate and for us to determine what fixes we need to make (if any): https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue
See this answer for ideas on how to troubleshoot things at your end: https://stackoverflow.com/a/71952132/143475

CKEditor throws error after adding Notification Plugin

I am attempting to add the notification plugin to CKEditor and I receive the following error when I go on any page implementing the CKEditor regardless if it attempts to use the Notification Plugin or not
Uncaught TypeError: CKEDITOR.tools.eventsBuffer is not a function
at Area (plugin.js?t=D2LI:448)
at Object.init (plugin.js?t=D2LI:17)
at Object.<anonymous> (ckeditor.js:221)
at n (ckeditor.js:202)
at Array.m (ckeditor.js:202)
at o (ckeditor.js:202)
at ckeditor.js:203
I am clearly including the plugin since I am getting these errors.
this is the line of code in the plugin that is causing the error.
this._uiBuffer = CKEDITOR.tools.eventsBuffer( 10, this._layout, this );
Any help is appreciated.
Please see: https://docs.ckeditor.com/#!/api/CKEDITOR.tools-method-eventsBuffer.
The error means that tools object doesn't have eventsBuffer method. There are two explanations which come to my mind:
This method is available since CKEditor 4.2.1. Please check your ckeditor/CHANGES.md file (your version is at the top) to find out which editor version you use. If your editor is anything below 4.2.1, please upgrade it to latest version. Please also note that if you want to use notifications you need to use at least CKEditor 4.5 - https://docs.ckeditor.com/#!/api/CKEDITOR.plugins.notification so upgrading to 4.2.1 won't help in this case.
This is a long shot but another possibility is that you have a third-party script which conflicts with CKEditor thus you get such result. If your editor is up to date, please try disabling other scripts, clearing browser's cache according to this link and checking the result one more time.
NOTE: To find out your version you can also click question mark icon on the toolbar (it is available if you have About plugin installed).

Getting more information from “SyntaxError: Parse error” message in PhantomJS/CasperJS

I have a long CasperJS script. When I run it I get:
phantomjs file.js
SyntaxError: Parse error
Is there a way to get some more information about the error.
At least a line number? or any hint at all?
Try run the file.js with node, so for your example:
node file.js
It's not possible to determine this in PhantomJS itself. The documentation on phantom.onError says:
This is the closest it gets to having a global error handler in PhantomJS
And this doesn't catch the syntax error. If you try to run it with the --debug=true option, you will see a lot of debug messages, but the final error has still the same amount of information.
Another thing that I tried was to use a second PhantomJS script which reads the original script and tries to eval it. The phantom.onError event is triggered in this case, but the trace argument is empty.
The good thing is that PhantomJS/CasperJS scripts are just JavaScript, so you can paste them to http://jslint.com/ or run a dedicated jslinter on them to see where the problem lies. There are some options that you have to mark on the site or otherwise you will get a lot of errors:
add phantom to the global variables box,
enable node.js mode and
tolerate "everything" (or those things that you actually want to tolerate)
I spent a whole 8hrs on this to find a trick for this problem. The trick is to run "phantomjs" and type 'require "path_to_js_file"'. I used 2.1.1 version of phantomjs. Likely 2.2 also works.
Then there will be a stack trace that shows which line is the offender. You won't see this in testem output.
In my case, if you define a property twice for an object, it will work for chrome, firefox etc, but not phantomjs. Lint might help but there are >5K lint errors for the project I work on and it is practically impossible to see what's wrong. Also the particular problem is likely hidden under the same bucket of "javascript strict mode violation". Nodejs didn't complain this either.

Send Javascript code to browser

Is there a way to send javascript commands to an open web running in a browser from the shell?
Let's say I have stackoverflow.com open with Chrome. Well, I'd like to send something like
alert('hi!');
from the shell, with something similar to the following:
$ send -t Chrome -w "stackoverflow.com" -c "alert('hi!')"
I was wondering this, because if I can write alert('hi!') on the javascript console of Chrome, I should be able to do the same with a call somewhere, right?
I've seen node.js but I think is not possible with that, please, let me know if I'm wrong.
I know the question could seem weird but I'm curious, thanks in advance :)
You can send JavaScript to Firefox through the jssh extension.
http://www.croczilla.com/bits_and_pieces/jssh/
This is what the Watir testing framework uses to automate Firefox.
I don't know of an equivalent for Chrome.
For IE seems like you can use good old VBScript: http://www.autohotkey.com/forum/topic7642.html
Worked for me just fine now with IE8. :)
Edit: to open this very question and alert JS value have this code as .vbs file and run it:
Dim oIE
Set oIE = CreateObject("InternetExplorer.Application")
oIE.Visible = 1
oIE.Navigate "http://stackoverflow.com/questions/4992552/send-javascript-code-to-browser/4992812"
Do While (oIE.Busy)
Wscript.Sleep 10
Loop
oIE.Navigate "javascript:alert(fkey);"
I think it is possible if you write and install some browser addon that would receive your signal, and do the job. Interesting question, ill be tracking it.
It is entirely up to the browser to provide this sort of functionality. In fact, the form of your problem isn't specific even to browsers:
I was wondering this, because if I can [provide some sort of input] to [a program] to make it [do something], I should be able to do the same with a call somewhere, right?
Some programs do indeed provide hooks for scripting, but if they don't, you're out of luck. There is certainly no guarantee that if you can do something via the GUI, then you can trigger the same action from a command line call.
Now the fact that most browsers provide some sort of plugin architecture, makes it much more likely that such a plugin exists that will listen for external input in this way, if this functionality is missing in the base product.
However, this is still going to be very specific to the particular model and even version of the browser you want to control - so if it's something you wanted to release into the wild, you'll need to be very specific with your requirements.
You can send arbitrary code to browser through the address bar! For example in AutoHotKey style,
send F6 //focus the address bar
send ctrl+v //given that your code is in clipboard
send enter
Now there is another question. Can we get the return value of the inject code? The answer is YES!
Assign your return value to document.title, and retrieve the window title from your application.
If the return value is too long (eg. a JSON format string), do the trick that
document.title='calculating...';
document.title=returnValue.subString(0,20);
sleep(10);
document.title=returnValue.subString(20,40);
sleep(10);
document.title=returnValue.subString(40,60);
...
document.title='finished';
Hope it works.

VERY confused - javascript not being executed - unless Console is turned on in Firebug?

I just started doing some Javascript work for a project, I do mostly backend work so I'm sorry for being new at this! Also, not using a Javascript framework because I want to learn about the fundamentals before making everything very easy for myself :)
So, here is my question/confusion: I wrote a little javascript that dynamically changed forms. This is how I called the code:
// loads the initial box
window.onload = initList(environment_box);
// loads artifacts on each change to environment select box
environment_box.onchange = changeList;
This worked like magic - in CHROME that is! I never noticed it wasn't working in Firefox (its just an internal tool, so I can assume decent browsers, but I figure hey, if its working in Chrome, it will work in Firefox!). So, I did some investigation, and it seems as though the code isnt getting executed in Firefox. I whipped out firebug and wanted to see what was going on.
The interesting thing was, when I enabled Console on firebug, my code got executed! I am very confused as to why, and I would much appreciate any help I could get. Thanks!
-Shawn
You are calling some method on console in your JavaScript is my best guess. Chrome has console defined be default, so it is not a problem.
On Firefox, however, there is no such global object (not without Firebug), so when you try to call a property on an undefined object like,
console.log(..);
it throws an exception which you are not catching, so the JavaScript execution halts.
You're probably calling a method of the console object which just doesn't exist by default in most web browsers. It may be always available on webkit based browsers (like Chrome) but with firefox/IE(/opera?) it requires an external add-on, either firebug or a javascript dependency.
Checkout things like firebugx which simply defines the most common methods of a console object as no-op functions.

Categories

Resources