I am using reagent and am connected to the browser using weasel (tenzing template using boot). In my browser (chrome) console I am able to call clear() and it works.
However when I type (js/clear) in my cider repl, it throws an error -
ReferenceError: clear is not defined
I am however able to run (js/alert "Hello") without any problems. Any ideas what is wrong ?
When you're typing clear() into the console you're not using the Console API, but the Command Line API.
It's not possible to call this function from javascript:
This API complements the Console API, the Command Line API is only
available from within the console itself.
Note that: Some are available in both. Such as console.dir or console.clear which you can call with (.clear js/console).
Try this:
(.clear js/console)
(.log js/console "asdasd")
Worked in my Figwheel REPL. You should try Figwheel, btw: https://github.com/bhauman/lein-figwheel
In case you ask "why" but not "how", this question should clear the situation: clear javascript console in Google Chrome
Related
In my ClojureScript code I am requiring a JavaScript module called seedrandom which is in the node_modules folder, like this:
(ns something.core
(:require ["seedrandom" :as rnd]))
(js/console.log (.quick (rnd "x")))
According to the seedrandom documentation it is intended for both nodejs and the browser, and I've previously included and used it successfully in ClojureScript code via a <script> tag, confirming it works in the browser.
Running this cljs file in lumo on the command line works well and outputs a deterministically random number.
When I try to use this same cljs file in my Reagent frontend project I see the following error:
Compiling build :app to "public/js/app.js" from ["src" "env/dev/cljs"]...
events.js:183
throw er; // Unhandled 'error' event
^
Error: module not found: "crypto" from file /home/chrism/dev/something/node_modules/seedrandom/seedrandom.js
at onresolve (/home/chrism/dev/something/node_modules/#cljs-oss/module-deps/index.js:181:30)
...
Inside seedrandom.js we see the following:
// When in node.js, try using crypto package for autoseeding.
try {
nodecrypto = require('crypto');
} catch (ex) {}
Clearly this code is intended to ignore the built-in nodejs crypto module when running in the browser. The problem, as far as I can tell, is that the ClojureScript compiler does not know that - it sees that require('crypto') and tries to pull it into the compilation phase, but can't find it because it's a nodejs built-in.
Is there some way I can tell the compiler to ignore that particular require? Or can I shim the 'crypto' module somehow? What is the cleanest way to solve this?
Note: I have previously experienced this same issue with JavaScript modules which check for the fs node module. Hope we can find a general solution to use again in future. Thanks!
Relevant versions: [org.clojure/clojurescript "1.10.520"] and [reagent "0.8.1"].
This answer is related, asking a similar question from the perspective of Google Closure, which ClojureScript uses, but I'm looking for an answer I can use specifically with cljs.
I know that AngularJS by default catches all application exceptions and then logs them to the console. That makes the 'Pause on uncaught exceptions' button in Chrome (which I use a lot) useless.
Many times I encounter small javascript errors in my code (like accessing members on undefined variables) and I'm really used to pausing on the exception and inspecting the situation.
The only solution I have by now is either to put a breakpoint on the code which is triggering the error (impractical) or to use the 'Pause on all exceptions' button, but I have to continue on all errors generated by default by jQuery, Angular and other frameworks, and that's also very nasty.
I also tried overwriting the $exceptionHandler service, and put a breakpoint in it, but I don't have access from the call stack in the function that generated the error.
So, is it possible to use the 'Pause on uncaught exceptions' with AngularJS apps?
According to the Angular docs,
https://docs.angularjs.org/api/ng/service/$exceptionHandler
This example will override the normal action of $exceptionHandler, to
make angular exceptions fail hard when they happen, instead of just
logging to the console.
angular.module('exceptionOverride', []).factory('$exceptionHandler', function() {
return function(exception, cause) {
exception.message += ' (caused by "' + cause + '")';
throw exception;
};
});
This will cause them to be handled by the browser dev tools, which will allow pause on caught exceptions, usage of source maps for nice stack traces, etc.
Presumably you don't want this to happen in production, and also don't want to have to add/remove this code continuously during development. We solve this secondary problem by having a 'dev' module which adds to and overrides our production code during development. For example:
In dev.html:
<html ng-app="devApp">
...
In dev.js:
angular.module('devApp', ['mainApp'])
.factory('$exceptionHandler', ...)
The "Skip stepping through sources" is no longer available in Chrome, but - there is a new option - you can right click any script in sources/sources and choose 'Blackbox script'. Then you can turn on 'Pause on Caught Exceptions' without worrying about jQuery and other errors. Personally I use it always on jquery.js and angular.js.
You can enable Skip stepping through sources with particular names in DevTools and set it to something like this:
(jquery|angular|diigolet)
I built a console app to find all the *.ts files in my project and then compile them using tsc.exe.
Everything was working fine, but as I converted my JavaScript files to TypeScript, I eventually ran into the following error:
ytsc.js(21053, 17) Microsoft JScipt runtime error: 'window' is undefined
Each time this happened when I was trying to extend window:
window['prop'] = "something";
I tested the code until I found the answer, which had little to do with my code...
The fault was my build tool.
I had declared the -e (execute) command line option when calling tsc.exe:
I did this because I thought I might add some automated testing code in the modules.
The cause for the error:
Most of my code is in functions.
However, there were a few places that I wanted to extend 'window' (for example if a built in function is missing from an old browser, I was shimming those calls). The code to shim the window object was running as the file loaded:
if (window.fun == null) {
window.fun = function(){...};
}
Anyway, because of the -e option, the tsc.exe was attempting to run the code (outside of a browser environment). This caused the above error.
In my ClojureScript programs running in FireFox 5.0 on Ubuntu 10.04.1 LTS, I get a single cryptic line when an exception is thrown.
'Error: No protocol method ISeqable.-seq defined for type object: [object Object]' when calling method: [nsIDOMEventListener::handleEvent]
The "-seq" bit seems strange to me and I have searched the generated javascript files for it and not found it.
I hope I am not missing something entirely obvious, but how do I get a stack trace of the exception thrown? How are you debugging your scripts?
Unfortunately stack traces from errors rely on browser support. Most (all?) browsers will allow you to access a canned version of the stack trace (usually the top 10 elements, iirc) as a string by dereferencing the 'stack' field, so you could do something like this:
(try ...throws...
(catch js/Error e
(.log js/console (.-stack e))))
However, string stack traces aren't much fun, you can't click them to take you to the source. Better is printing the exception directory to the javascript console (if it's available) to print stack traces with clickable links. E.g.
(try ...throws...
(catch js/Error e
(.log js/console e)))
At least in chrome, this only works if the javascript console was open when the error was thrown. This is great for debugging, but less useful when the error was unexpected.
The javascript console objects provided by most browsers have lots of useful functions that you can use from clojurescript. If you want to get helpful line numbers though, you probably want to write a couple of macros to inject the code to print to the console, otherwise all your line numbers will point to your print function.
Looks like you are passing a Javascript object to a Clojurescript function which expects a Clojure sequence. Try (my-function (js->clj my-thing)) edit: or, I'm guessing you're using (.strobj) where you don't need to
I'm trying to run a test in Google Chrome 9.0.597.98 beta using Selenium Grid. I'm firing the test off from C# using the default *googlechrome target that ships with Selenium Grid. When I try to open a site, I'm greeted with a "Cannot call method 'indexOf' of undefined" error.
I've found a post from someone who suggests that the solution is to drop security on Chrome a bit by passing in some parameters. This post suggest using something like this:
DefaultSelenium selenium = new DefaultSelenium(location, port, browser, targetPath);
BrowserConfigurationOptions bco = new BrowserConfigurationOptions();
selenium.start(bco.setCommandLineFlags("--disable-web-security"));
For some reason I don't see the BrowserConfigurationOptions anywhere. Is this something that ships with the Selenium dll? Is it something that's not available in the .NET version, but is in others? What options do I have to setting this "--disable-web-security" option and is there a better way of doing this?
Try this
[TestInitialize]
public void PreTest()
{
selenium = new DefaultSelenium("localhost",4444,"googlechrome","http://www.ryanhayes.net")
}
[TestMethod]
public void TestRyanHayesDotNet()
{
selenium.Open("/")
}
removing the / after the ryanhayes.net fixes the problem
Thanks a lot for this, I was looking this information and I got it here!
Now I'm able to run my test in googlechrome, earlier I was getting the same problem.
Following code is working for me:
BrowserConfigurationOptions webSec = new BrowserConfigurationOptions();
selenium.start(webSec.setCommandLineFlags("--disable-web-security"));
You're correct in assuming .Net doesn't have BrowserConfigurationOptions object, but fortunately you don't need it (it's only a thin wrapper). DefaultSelenium has two overrides for the Start() method. One of them takes no parameters and starts the browser normally, but the other takes a string specifying browser options. try selenium.Start("--disable-web-security")