Comments (12)
That console closes when the xulrunner or firefox closes. It's a good feature to have. If you want the console to stay around then don't exit the program. I ran the initial-tests.js and had to comment out the exit
command to keep the window open. After I read the results I closed the window and the process exited as expected.
from slimerjs.
There are notes about the console on windows in this article on MDN It says you can redirect the console output to a file by launching firefox without the -console
switch like this: firefox.exe > log.txt 2>&1
I tried that and it didn't work for me. I thought that if it did I might be able to find some obscure batch magic to redirect to the output to a console that wouldn't be closed when Gecko exits.
from slimerjs.
I found a solution. Not an optimal one because we cannot see messages at realtime. We saw them at the end at least.
Can it be an acceptable solution?
from slimerjs.
It's acceptable as long as you don't rely on people being able to see it before slimerjs closes. In other words, if the console is only paid any attention when running tests or debugging why an application won't start. Once an app is capable of displaying a window then the built in error console is a much better place to log things as it has good formatting and can be given access to the chrome. Being that the command line is only a message board for stdout I doubt that anyone would be interested in it aside from troubleshooting application start up. I mean, we're not recompiling custom versions of Gecko so...
I did look around for a way to redirect the output so windows, linux, and mac would all be able to see the dump
messages in realtime. It appears that redirecting to CON
is supposed to be a way of explicitly sending information to the console.
firefox.exe 1> CON 2>&1
The thing is, it seems that either what I was reading is wrong, or that firefox is just too smart to be put into the calling console on windows.
There were more complicated solutions involving visual basic that might work but, then there would be some compiling of the executable and other irritating work for something that just won't be all that useful. If you want to look into it, there is a massive and complex example of redirecting sterr in realtime on msdn You can do the same thing with stdout and have the handler functions for OutputDataReceived
and ErrorDataReceived
just Console.WriteLine(DataReceivedEventArgs.Data)
but, I didn't quite have the patience to test it with firefox. Like I said, it would need to be compiled into an executable in order to be easy for people to use.
from slimerjs.
I found some patience and curiosity. I've got a Visual Basic file that can redirect Firefox's stdout and stderr back to the console that opened it. If you compile it into a console application and just run the exe file, it will do the same thing that running Firefox with the -console
switch does. If you run the exe from a command prompt then Firefox's output will be redirected to it and everything will seem normal (realtime dump logging). I've got it compiled already and can send a pull request if you're interested. I could also eliminate all the other logic in the batch file by bringing it into this executable if you want.
Here is the VB code, note that I've got to trick Firefox by feeding it an argument to redirect it's output to a text file and then I can grab the output and send it to the console instead. . . weird huh? It would probably make a horrible looking batch file 1> tmp.txt 2>&1 CON<
. . . err. . . umm tee?
. . . we don't have tee, I could fake it with this though:
Imports System
Imports System.Diagnostics
Imports System.IO
Module Module1
Public Sub Main()
Try
FirefoxyConsoleRedirector()
Catch e As InvalidOperationException
Console.WriteLine("Exception:")
Console.WriteLine(e.ToString())
End Try
End Sub
Public Sub FirefoxyConsoleRedirector()
Dim ffloc As String = Nothing
Try
ffloc = Environment.GetEnvironmentVariable("programfiles(x86)")
Catch ex As Exception
Try
ffloc = Environment.GetEnvironmentVariable("programfiles")
Catch exc As Exception
Console.WriteLine("Could not retreive a programfiles" _
& "environment variable on your system!")
Exit Sub
End Try
End Try
ffloc = ffloc & "\Mozilla Firefox\firefox.exe"
If Not File.Exists(ffloc) Then
Console.WriteLine("Firefox not found at " & ffloc)
Exit Sub
End If
Dim firefoxen As New Process()
firefoxen.StartInfo.FileName = ffloc
firefoxen.StartInfo.Arguments = """>tmp.txt 1>&2"""
firefoxen.StartInfo.UseShellExecute = False
firefoxen.StartInfo.RedirectStandardError = True
firefoxen.StartInfo.RedirectStandardOutput = True
AddHandler firefoxen.OutputDataReceived, AddressOf ConsoleLogger
AddHandler firefoxen.ErrorDataReceived, AddressOf ConsoleLogger
firefoxen.Start()
firefoxen.BeginOutputReadLine()
firefoxen.BeginErrorReadLine()
firefoxen.WaitForExit()
firefoxen.Close()
End Sub
Private Sub ConsoleLogger(sendingProcess As Object, _
outLine As DataReceivedEventArgs)
Console.WriteLine(outLine.Data)
End Sub
End Module
from slimerjs.
#12 completely resolves this issue. The console output is now redirected to the console that launched the Gecko runtime in real time all the time. The user can then do whatever they would like with it.
from slimerjs.
There is a Windows version of tee that correctly outputs redirection to the console in real time.
from slimerjs.
Nice! Is it open source? Do you have a link to it?
from slimerjs.
https://code.google.com/p/wintee
It's released under the MPL. Copy wtee.exe to the folder where slimerjs lives and redirect the output to it:
yadda yadda slimerjs | wtee
Not the best solution, but it works OK for me.
from slimerjs.
It sounds like wintee has gone through a lot more testing and use by the developer than what I did with my code. For sure, if I had found it when I thought about helping slimerjs behave similarly on Windows and Linux I'd have just used it and not taken the time to build a silly project in VB. :D
That said, I can't say what @laurentj may or may not have done to improve what I scribbled out so for sure, this might be a better option than my repo but, it may not be quite as awesome as whatever Laurent has done in the 10 months since we argued over just how awesome Firefox and Windows consoles are. :D Looking at issue #105 leads me to believe he may not be using my code anymore at all? Looking at the bugzilla reports it looks like the weird Windows console behavior of late was something in Mozilla's code around v. 15 of FF.
I'm not saying my scribbles are perfect, they could be wrong, but they're pretty much doing what wintee is doing in that the code is set up to redirect stdin, stderr, and stdout to as many individual endpoints as you want in real time. There are a couple examples of how to use it at https://github.com/matthewkastor/redirector and for sure, if you know a tiny bit of VB you can do a lot more with my code than you can do with wintee.
For real though, it was kinda rude to say "correctly outputs redirection" because for sure my code correctly redirects to the console. I think getting messages to the command console on Firefox requires the dump
(https://developer.mozilla.org/en-US/docs/Web/API/Window.dump) command or something, and if I remember correctly the messages dumped need to be terminated by newlines or they won't show up. People always make the mistake of thinking console.log
will write to the command console but that writes to the browsers console object, unless Firefox changed it to write to the command console as well. Could be, I don't know, I haven't been messing around with this area of esoterica in months.
Whatever you do to get the job done, if it works better than what's currently in slimerjs you should definitely share it. Working with strangers on awesome projects like this is really a lot of fun. :D
from slimerjs.
window.dump() is a non-standard extension.
from slimerjs.
lolz, so how do you send messages to the command console from your app? Has laurent overridden console.log
so it dumps to the command console?
/**
* Turns console.log into window.dump
* @author <a href="[email protected]">Matthew Kastor</a>
*/
function slimer_dump () {
var args = Array.prototype.slice.call(arguments, 0);
var message = args.reduce(function (prev, curr) {
if (curr instanceof Function) {
curr = String(curr);
}
if (curr instanceof Object) {
curr = JSON.stringify(curr);
}
return String(prev) + ' ' + String(curr);
}, '');
message = message.slice(1);
// because really, what's standard about what you're doing with slimerjs?
dump(message + '\r\n');
}
console.log = slimer_dump;
// usage?
var z = function wee(){};
z.a = 'banana';
var a = {"something":5};
var b = [1,2,3,4];
console.log('foo', z, a, b, 'bar');
from slimerjs.
Related Issues (20)
- Documentation improvement: major difference between the behaviour of evaluateJavaScript in PhantomJS VS SlimerJS
- Is it possible to use with remote running firefox instance?
- when will FF 61 be supported? HOT 1
- segmentation fault errors
- how to access browser default popup?
- SlimerJS not compatible with Firefox 62 HOT 5
- SlimerJS not compatible with Firefox 63 HOT 11
- slimer 1.0.0 leaves a lot of garbage in /tmp HOT 1
- Can't render this site, https://piaofang.maoyan.com/dashboard
- Cannot delete window.callPhantom HOT 1
- Strange bash script behaviour on Heroku
- Script won't work if modules aren't ended with semicolons before async handler HOT 1
- SlimerJS crashes on Windows Server with Firefox 67 HOT 1
- I need each script to connect to a different proxy
- 'expires' attribute from page.cookies is incorrect
- Arch/Manjaro package manager can not download from download.slimerjs.org HOT 1
- Appropriate version of firefox for slimerjs on a raspberry pi? HOT 2
- No more development on Slimerjs HOT 1
- Thumbnail is not generating for video assets
- Crash Annotation GraphicsCriticalError for headless selenium on firefox browser HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slimerjs.